From 1383287bb26e975ac846500e8f6d3fef118dc982 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 31 Oct 2019 16:36:59 +0100 Subject: [PATCH] add a metric on the number of uploaded files This commit adds a new Prometheus metric to track how much files we uploaed to S3 or added to the database. This will be useful to track the usefulness of parallel S3 upload once we land it. --- src/db/file.rs | 6 +++++- src/web/metrics.rs | 5 +++++ src/web/mod.rs | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/db/file.rs b/src/db/file.rs index 8e32c3970..98f57f026 100644 --- a/src/db/file.rs +++ b/src/db/file.rs @@ -196,7 +196,10 @@ pub fn add_path_into_database>(conn: &Connection, match s3_res { // we've successfully uploaded the content, so steal it; // we don't want to put it in the DB - Ok(_) => break None, + Ok(_) => { + crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(1); + break None; + }, // Since s3 was configured, we want to panic on failure to upload. Err(e) => { log::error!("failed to upload to {}: {:?}", bucket_path, e); @@ -240,6 +243,7 @@ pub fn add_path_into_database>(conn: &Connection, WHERE path = $1", &[&path, &mime, &content])); } + crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(1); } } diff --git a/src/web/metrics.rs b/src/web/metrics.rs index 6204bb6ed..0adcfa2a1 100644 --- a/src/web/metrics.rs +++ b/src/web/metrics.rs @@ -35,6 +35,11 @@ lazy_static! { "Number of builds that did not complete due to not being a library" ) .unwrap(); + pub static ref UPLOADED_FILES_TOTAL: IntCounter = register_int_counter!( + "docsrs_uploaded_files_total", + "Number of files uploaded to S3 or stored in the database" + ) + .unwrap(); } pub fn metrics_handler(req: &mut Request) -> IronResult { diff --git a/src/web/mod.rs b/src/web/mod.rs index fabdf65a6..c8986101c 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -438,6 +438,7 @@ pub fn start_web_server(sock_addr: Option<&str>) { metrics::SUCCESSFUL_BUILDS.inc_by(0); metrics::FAILED_BUILDS.inc_by(0); metrics::NON_LIBRARY_BUILDS.inc_by(0); + metrics::UPLOADED_FILES_TOTAL.inc_by(0); let cratesfyi = CratesfyiHandler::new(); Iron::new(cratesfyi).http(sock_addr.unwrap_or("0.0.0.0:3000")).unwrap();