From 756c97b0a4b60ae76447a79992dfb95608fe27d4 Mon Sep 17 00:00:00 2001 From: Pietro Albini Date: Thu, 4 Jun 2020 12:49:38 +0200 Subject: [PATCH] metrics: fix docsrs_prioritized_crates_count The metric was including failed crates, and didn't consider that the priority is stored with the wrong sign in the database (a positive priority means a negative priority, for whatever reason). --- src/web/metrics.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/web/metrics.rs b/src/web/metrics.rs index ac4e17a44..65bd19c68 100644 --- a/src/web/metrics.rs +++ b/src/web/metrics.rs @@ -124,9 +124,12 @@ pub fn metrics_handler(req: &mut Request) -> IronResult { .get(0), ); PRIORITIZED_CRATES_COUNT.set( - ctry!(conn.query("SELECT COUNT(*) FROM queue WHERE priority >= 0;", &[])) - .get(0) - .get(0), + ctry!(conn.query( + "SELECT COUNT(*) FROM queue WHERE attempt < 5 AND priority <= 0;", + &[] + )) + .get(0) + .get(0), ); FAILED_CRATES_COUNT.set( ctry!(conn.query("SELECT COUNT(*) FROM queue WHERE attempt >= 5;", &[])) @@ -196,7 +199,7 @@ impl iron::Handler for RequestRecorder { #[cfg(test)] mod tests { - use crate::test::wrapper; + use crate::test::{assert_success, wrapper}; use std::{ collections::HashMap, sync::{ @@ -358,4 +361,12 @@ mod tests { Ok(()) }) } + + #[test] + fn metrics() { + wrapper(|env| { + let web = env.frontend(); + assert_success("/about/metrics", web) + }) + } }