-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from rpcpool/espi/das-bubblegum-tree
[Feat] Ops cli with tree backfiller
- Loading branch information
Showing
17 changed files
with
1,280 additions
and
13 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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
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 CONCURRENTLY 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(()) | ||
} | ||
} |
Oops, something went wrong.