-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ops): add ops crate for bundling misc tools. add a tree backfill…
…er based on cl_audits_v2.
Showing
17 changed files
with
1,266 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "das-core" | ||
version.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
publish.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { workspace = true } | ||
anyhow = { workspace = true } | ||
sqlx = { workspace = true } | ||
cadence = { workspace = true } | ||
cadence-macros = { workspace = true } | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use sqlx::{ | ||
postgres::{PgConnectOptions, PgPoolOptions}, | ||
PgPool, | ||
}; | ||
|
||
#[derive(Debug, Parser, Clone)] | ||
pub struct PoolArgs { | ||
/// The database URL. | ||
#[arg(long, env)] | ||
pub database_url: String, | ||
/// The maximum number of connections to the database. | ||
#[arg(long, env, default_value = "125")] | ||
pub database_max_connections: u32, | ||
/// The minimum number of connections to the database. | ||
#[arg(long, env, default_value = "5")] | ||
pub database_min_connections: u32, | ||
} | ||
|
||
///// Establishes a connection to the database using the provided configuration. | ||
///// | ||
///// # Arguments | ||
///// | ||
///// * `config` - A `PoolArgs` struct containing the database URL and the minimum and maximum number of connections. | ||
///// | ||
///// # Returns | ||
///// | ||
///// * `Result<DatabaseConnection, DbErr>` - On success, returns a `DatabaseConnection`. On failure, returns a `DbErr`. | ||
pub async fn connect_db(config: PoolArgs) -> Result<PgPool, sqlx::Error> { | ||
let options: PgConnectOptions = config.database_url.parse()?; | ||
|
||
PgPoolOptions::new() | ||
.min_connections(config.database_min_connections) | ||
.max_connections(config.database_max_connections) | ||
.connect_with(options) | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod db; | ||
mod metrics; | ||
|
||
pub use db::*; | ||
pub use metrics::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use anyhow::Result; | ||
use cadence::{BufferedUdpMetricSink, QueuingMetricSink, StatsdClient}; | ||
use cadence_macros::set_global_default; | ||
use clap::Parser; | ||
use std::net::UdpSocket; | ||
|
||
#[derive(Clone, Parser, Debug)] | ||
pub struct MetricsArgs { | ||
#[arg(long, env, default_value = "127.0.0.1")] | ||
pub metrics_host: String, | ||
#[arg(long, env, default_value = "8125")] | ||
pub metrics_port: u16, | ||
#[arg(long, env, default_value = "das.backfiller")] | ||
pub metrics_prefix: String, | ||
} | ||
|
||
pub fn setup_metrics(config: MetricsArgs) -> Result<()> { | ||
let host = (config.metrics_host, config.metrics_port); | ||
|
||
let socket = UdpSocket::bind("0.0.0.0:0")?; | ||
socket.set_nonblocking(true)?; | ||
|
||
let udp_sink = BufferedUdpMetricSink::from(host, socket)?; | ||
let queuing_sink = QueuingMetricSink::from(udp_sink); | ||
|
||
let client = StatsdClient::from_sink(&config.metrics_prefix, queuing_sink); | ||
|
||
set_global_default(client); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
migration/src/m20240124_173104_add_tree_seq_index_to_cl_audits_v2.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use super::model::table::ClAuditsV2; | ||
use sea_orm::{ConnectionTrait, DatabaseBackend, Statement}; | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
let conn = manager.get_connection(); | ||
|
||
conn.execute(Statement::from_string( | ||
DatabaseBackend::Postgres, | ||
"CREATE INDEX IF NOT EXISTS tree_seq_idx ON cl_audits_v2 (tree, seq);".to_string(), | ||
)) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.drop_index( | ||
Index::drop() | ||
.name("tree_seq_idx") | ||
.table(ClAuditsV2::Table) | ||
.to_owned(), | ||
) | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
[package] | ||
name = "das-ops" | ||
version.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
publish.workspace = true | ||
|
||
[[bin]] | ||
name = "das-ops" | ||
|
||
[dependencies] | ||
|
||
clap = { workspace = true, features = ["derive", "cargo", "env"] } | ||
das-core = { workspace = true } | ||
backon = "0.4.1" | ||
log = { workspace = true } | ||
env_logger = { workspace = true } | ||
anyhow = { workspace = true } | ||
redis = { workspace = true } | ||
futures = { workspace = true } | ||
futures-util = { workspace = true } | ||
base64 = { workspace = true } | ||
indicatif = "0.17.5" | ||
thiserror = { workspace = true } | ||
serde_json = { workspace = true } | ||
cadence = { workspace = true } | ||
cadence-macros = { workspace = true } | ||
anchor-client = { workspace = true } | ||
tokio = { workspace = true } | ||
sqlx = { workspace = true } | ||
sea-orm = { workspace = true } | ||
sea-query = { workspace = true } | ||
chrono = { workspace = true } | ||
tokio-postgres = { workspace = true } | ||
serde = { workspace = true } | ||
bs58 = { workspace = true } | ||
reqwest = { workspace = true } | ||
plerkle_messenger = { workspace = true } | ||
plerkle_serialization = { workspace = true } | ||
flatbuffers = { workspace = true } | ||
lazy_static = { workspace = true } | ||
regex = { workspace = true } | ||
digital_asset_types = { workspace = true } | ||
mpl-bubblegum = { workspace = true } | ||
spl-account-compression = { workspace = true } | ||
spl-concurrent-merkle-tree = { workspace = true } | ||
uuid = { workspace = true } | ||
figment = { workspace = true } | ||
solana-sdk = { workspace = true } | ||
solana-client = { workspace = true } | ||
solana-transaction-status = { workspace = true } | ||
solana-account-decoder = { workspace = true } | ||
rust-crypto = { workspace = true } | ||
url = { workspace = true } | ||
anchor-lang = { workspace = true } | ||
borsh = { workspace = true } |
Oops, something went wrong.