Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Change created_at to scheduled_at for metrics (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner authored Jan 19, 2024
1 parent a4b9943 commit e2b5dcb
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions hook-janitor/src/webhooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ struct FailedRow {

#[derive(sqlx::FromRow, Debug)]
struct QueueDepth {
oldest_created_at_untried: DateTime<Utc>,
oldest_scheduled_at_untried: DateTime<Utc>,
count_untried: i64,
oldest_created_at_retries: DateTime<Utc>,
oldest_scheduled_at_retries: DateTime<Utc>,
count_retries: i64,
}

Expand Down Expand Up @@ -187,9 +187,9 @@ impl WebhookCleaner {

let base_query = r#"
SELECT
COALESCE(MIN(CASE WHEN attempt = 0 THEN created_at END), now()) AS oldest_created_at_untried,
COALESCE(MIN(CASE WHEN attempt = 0 THEN scheduled_at END), now()) AS oldest_scheduled_at_untried,
COALESCE(SUM(CASE WHEN attempt = 0 THEN 1 ELSE 0 END), 0) AS count_untried,
COALESCE(MIN(CASE WHEN attempt > 0 THEN created_at END), now()) AS oldest_created_at_retries,
COALESCE(MIN(CASE WHEN attempt > 0 THEN scheduled_at END), now()) AS oldest_scheduled_at_retries,
COALESCE(SUM(CASE WHEN attempt > 0 THEN 1 ELSE 0 END), 0) AS count_retries
FROM job_queue
WHERE status = 'available';
Expand Down Expand Up @@ -374,15 +374,16 @@ impl WebhookCleaner {
// of rows in memory. It seems unlikely we'll need to paginate, but that can be added in the
// future if necessary.

let untried_status = [("status", "untried")];
let retries_status = [("status", "retries")];

let queue_depth = self.get_queue_depth().await?;
metrics::gauge!("queue_depth_oldest_created_at_untried")
.set(queue_depth.oldest_created_at_untried.timestamp() as f64);
metrics::gauge!("queue_depth", &[("status", "untried")])
.set(queue_depth.count_untried as f64);
metrics::gauge!("queue_depth_oldest_created_at_retries")
.set(queue_depth.oldest_created_at_retries.timestamp() as f64);
metrics::gauge!("queue_depth", &[("status", "retries")])
.set(queue_depth.count_retries as f64);
metrics::gauge!("queue_depth_oldest_scheduled", &untried_status)
.set(queue_depth.oldest_scheduled_at_untried.timestamp() as f64);
metrics::gauge!("queue_depth", &untried_status).set(queue_depth.count_untried as f64);
metrics::gauge!("queue_depth_oldest_scheduled", &retries_status)
.set(queue_depth.oldest_scheduled_at_retries.timestamp() as f64);
metrics::gauge!("queue_depth", &retries_status).set(queue_depth.count_retries as f64);

let mut tx = self.start_serializable_txn().await?;

Expand Down

0 comments on commit e2b5dcb

Please sign in to comment.