From ebcb0556cca0b1890dcd520f765827e45e18901e Mon Sep 17 00:00:00 2001 From: ktatarnikov Date: Mon, 13 Jan 2025 14:59:40 +0100 Subject: [PATCH] [104] code review changes --- rhio/src/blobs/actor.rs | 26 ++++++++++++-------------- rhio/src/health.rs | 8 ++++++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/rhio/src/blobs/actor.rs b/rhio/src/blobs/actor.rs index 36fcf4a6..383e453b 100644 --- a/rhio/src/blobs/actor.rs +++ b/rhio/src/blobs/actor.rs @@ -131,24 +131,12 @@ impl BlobsActor { DownloadBlobEvent::Abort(err) => { error!(parent: &span, %err, "failed downloading blob"); - metrics::counter!( - BLOBS_DOWNLOAD_TOTAL, - LABEL_MSG_TYPE => LABEL_BLOB_MSG_TYPE_ERROR, - LABEL_LOCAL_BUCKET => blob.local_bucket_name.to_owned(), - LABEL_REMOTE_BUCKET => blob.remote_bucket_name.to_owned() - ) - .increment(1); + BlobsActor::increment_blob_downloads(LABEL_BLOB_MSG_TYPE_ERROR, &blob); } DownloadBlobEvent::Done => { debug!(parent: &span, "finished downloading blob"); - metrics::counter!( - BLOBS_DOWNLOAD_TOTAL, - LABEL_MSG_TYPE => LABEL_BLOB_MSG_TYPE_DONE, - LABEL_LOCAL_BUCKET => blob.local_bucket_name.to_owned(), - LABEL_REMOTE_BUCKET => blob.remote_bucket_name.to_owned() - ) - .increment(1); + BlobsActor::increment_blob_downloads(LABEL_BLOB_MSG_TYPE_DONE, &blob); } } } @@ -156,6 +144,16 @@ impl BlobsActor { Ok(()) } + fn increment_blob_downloads(msg_type: &str, blob: &SignedBlobInfo) { + metrics::counter!( + BLOBS_DOWNLOAD_TOTAL, + LABEL_MSG_TYPE => msg_type.to_owned(), + LABEL_LOCAL_BUCKET => blob.local_bucket_name.to_owned(), + LABEL_REMOTE_BUCKET => blob.remote_bucket_name.to_owned() + ) + .increment(1); + } + async fn shutdown(&mut self) -> Result<()> { Ok(()) } diff --git a/rhio/src/health.rs b/rhio/src/health.rs index 16d67619..8a47bc4e 100644 --- a/rhio/src/health.rs +++ b/rhio/src/health.rs @@ -20,16 +20,20 @@ pub async fn run_http_server(bind_port: u16) -> Result<()> { IpAddr::V4(Ipv4Addr::UNSPECIFIED), bind_port, )) - .await?; + .await + .context("TCP Listener binding")?; debug!( "HTTP health and metrics endpoint listening on {}", listener.local_addr()? ); + let app = Router::new().route(HTTP_HEALTH_ROUTE, get(health)).route( HTTP_METRICS_ROUTE, get(move || ready(recorder_handle.render())), ); - axum::serve(listener, app).await?; + axum::serve(listener, app) + .await + .context("HTTP metrics and health serving")?; Ok(()) }