Skip to content

Commit

Permalink
fix queue size metrics with priorities
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Nov 5, 2023
1 parent 5a86c4a commit 38e69ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,14 @@ impl ServiceMetrics {

let queue_pending_count = queue.pending_count_by_priority()?;

for (priority, count) in queue_pending_count.iter() {
// we reset the metric so we won't keep old gauge values around
// when a certain priority is no longer used in the queue.
self.queued_crates_count_by_priority.reset();

// for commonly used priorities we want the value to be zero, and not missing,
// when there are no items in the queue with that priority.
for priority in 0..=20 {
let count = queue_pending_count.get(&priority).unwrap_or(&0);
self.queued_crates_count_by_priority
.with_label_values(&[&priority.to_string()])
.set(*count as i64);
Expand Down
6 changes: 6 additions & 0 deletions src/web/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,16 @@ pub fn start_web_server(addr: Option<SocketAddr>, context: &dyn Context) -> Resu
// initialize the storage and the repo-updater in sync context
// so it can stay sync for now and doesn't fail when they would
// be initialized while starting the server below.
tracing::info!("initializing storage");
context.storage()?;

tracing::info!("initializing repository stats updater");
context.repository_stats_updater()?;

tracing::info!("building axum app");
let app = build_axum_app(context, template_data)?.into_make_service();

tracing::info!("starting axum server");
context.runtime()?.block_on(async {
axum::Server::bind(&axum_addr)
.serve(app)
Expand Down

0 comments on commit 38e69ff

Please sign in to comment.