-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
db_store will now record metrics on db connection pool size and num_i…
…dle (#412) * db_store will now record metrics on db connection pool size and num_idle * Remove unnecessary Box and change app_name to &str * Fix missed paramter change
- Loading branch information
Showing
13 changed files
with
108 additions
and
11 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
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,47 @@ | ||
use std::time::Duration; | ||
|
||
use crate::{Error, Result}; | ||
|
||
const DURATION: Duration = Duration::from_secs(300); | ||
|
||
pub async fn start( | ||
app_name: &str, | ||
pool: sqlx::Pool<sqlx::Postgres>, | ||
shutdown: triggered::Listener, | ||
) -> Result<futures::future::BoxFuture<'static, Result>> { | ||
let pool_size_name = format!("{app_name}_db_pool_size"); | ||
let pool_idle_name = format!("{app_name}_db_pool_idle"); | ||
let join_handle = | ||
tokio::spawn(async move { run(pool_size_name, pool_idle_name, pool, shutdown).await }); | ||
|
||
Ok(Box::pin(async move { | ||
match join_handle.await { | ||
Ok(()) => Ok(()), | ||
Err(err) => Err(Error::from(err)), | ||
} | ||
})) | ||
} | ||
|
||
async fn run( | ||
size_name: String, | ||
idle_name: String, | ||
pool: sqlx::Pool<sqlx::Postgres>, | ||
shutdown: triggered::Listener, | ||
) { | ||
let mut trigger = tokio::time::interval(DURATION); | ||
|
||
loop { | ||
let shutdown = shutdown.clone(); | ||
|
||
tokio::select! { | ||
_ = shutdown => { | ||
tracing::info!("db_store: MetricTracker shutting down"); | ||
break; | ||
} | ||
_ = trigger.tick() => { | ||
metrics::gauge!(size_name.clone(), pool.size() as f64); | ||
metrics::gauge!(idle_name.clone(), pool.num_idle() as f64); | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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