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 8, 2023
1 parent 8c337d6 commit 04f06e4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::{cdn, db::Pool, target::TargetAtom, BuildQueue, Config};
use anyhow::Error;
use dashmap::DashMap;
use prometheus::proto::MetricFamily;
use std::time::{Duration, Instant};
use std::{
collections::HashSet,
time::{Duration, Instant},
};

load_metric_type!(IntGauge as single);
load_metric_type!(IntCounter as single);
Expand Down Expand Up @@ -307,7 +310,20 @@ 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.
// So we create a set of all priorities we want to be explicitly zeroed, combined
// with the actual priorities in the queue.
let all_priorities: HashSet<i32> =
queue_pending_count.keys().copied().chain(0..=20).collect();

for priority in all_priorities {
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

0 comments on commit 04f06e4

Please sign in to comment.