Skip to content

Commit

Permalink
fix(prometheus): improve queue_count when tags have no more jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Nov 4, 2024
1 parent 693b7a4 commit 09156b6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions backend/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ lazy_static::lazy_static! {
"Number of jobs in the queue",
&["tag"]
).unwrap();

static ref QUEUE_COUNT_TAGS: Arc<RwLock<Vec<String>>> = Arc::new(RwLock::new(Vec::new()));

}

pub async fn initial_load(
Expand Down Expand Up @@ -1089,12 +1092,23 @@ pub async fn expose_queue_metrics(db: &Pool<Postgres>) {
if metrics_enabled || save_metrics {
let queue_counts = windmill_common::queue::get_queue_counts(db).await;

if metrics_enabled {
for q in QUEUE_COUNT_TAGS.read().await.iter() {
if queue_counts.get(q).is_none() {
(*QUEUE_COUNT).with_label_values(&[q]).set(0);
}
}
}

let mut tags_to_watch = vec![];
for q in queue_counts {
let count = q.1;
let tag = q.0;

if metrics_enabled {
let metric = (*QUEUE_COUNT).with_label_values(&[&tag]);
metric.set(count as i64);
tags_to_watch.push(tag.to_string());
}

// save queue_count and delay metrics per tag
Expand All @@ -1119,6 +1133,10 @@ pub async fn expose_queue_metrics(db: &Pool<Postgres>) {
}
}
}
if metrics_enabled {
let mut w = QUEUE_COUNT_TAGS.write().await;
*w = tags_to_watch;
}
}

// clean queue metrics older than 14 days
Expand Down

0 comments on commit 09156b6

Please sign in to comment.