Skip to content

Add a metric on the number of uploaded files #457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/db/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ pub fn add_path_into_database<P: AsRef<Path>>(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);
Expand Down Expand Up @@ -240,6 +243,7 @@ pub fn add_path_into_database<P: AsRef<Path>>(conn: &Connection,
WHERE path = $1",
&[&path, &mime, &content]));
}
crate::web::metrics::UPLOADED_FILES_TOTAL.inc_by(1);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/web/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response> {
Expand Down
1 change: 1 addition & 0 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down