Skip to content

Commit 1383287

Browse files
committed
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.
1 parent d38fc5c commit 1383287

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/db/file.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
196196
match s3_res {
197197
// we've successfully uploaded the content, so steal it;
198198
// we don't want to put it in the DB
199-
Ok(_) => break None,
199+
Ok(_) => {
200+
crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(1);
201+
break None;
202+
},
200203
// Since s3 was configured, we want to panic on failure to upload.
201204
Err(e) => {
202205
log::error!("failed to upload to {}: {:?}", bucket_path, e);
@@ -240,6 +243,7 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
240243
WHERE path = $1",
241244
&[&path, &mime, &content]));
242245
}
246+
crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(1);
243247
}
244248
}
245249

src/web/metrics.rs

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ lazy_static! {
3535
"Number of builds that did not complete due to not being a library"
3636
)
3737
.unwrap();
38+
pub static ref UPLOADED_FILES_TOTAL: IntCounter = register_int_counter!(
39+
"docsrs_uploaded_files_total",
40+
"Number of files uploaded to S3 or stored in the database"
41+
)
42+
.unwrap();
3843
}
3944

4045
pub fn metrics_handler(req: &mut Request) -> IronResult<Response> {

src/web/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ pub fn start_web_server(sock_addr: Option<&str>) {
438438
metrics::SUCCESSFUL_BUILDS.inc_by(0);
439439
metrics::FAILED_BUILDS.inc_by(0);
440440
metrics::NON_LIBRARY_BUILDS.inc_by(0);
441+
metrics::UPLOADED_FILES_TOTAL.inc_by(0);
441442

442443
let cratesfyi = CratesfyiHandler::new();
443444
Iron::new(cratesfyi).http(sock_addr.unwrap_or("0.0.0.0:3000")).unwrap();

0 commit comments

Comments
 (0)