Skip to content

Commit 7000e2b

Browse files
committed
Add metrics to the job queue
This adds: - a histogram of the time it takes to process a job for each queue, with the status of the job (success, failure, etc.) - a histogram which records the time it takes to do a "tick", fetch jobs - a counter of the number of jobs currently in-flight for each queue - a counter which tracks the reasons why the worker got worken up
1 parent f2221d3 commit 7000e2b

File tree

4 files changed

+198
-19
lines changed

4 files changed

+198
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tasks/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ tower.workspace = true
2929
tracing.workspace = true
3030
tracing-opentelemetry.workspace = true
3131
opentelemetry.workspace = true
32+
opentelemetry-semantic-conventions.workspace = true
3233
ulid.workspace = true
3334
url.workspace = true
3435
serde.workspace = true

crates/tasks/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
// SPDX-License-Identifier: AGPL-3.0-only
55
// Please see LICENSE in the repository root for full details.
66

7-
#![allow(dead_code)]
8-
9-
use std::sync::Arc;
7+
use std::sync::{Arc, LazyLock};
108

119
use mas_email::Mailer;
1210
use mas_matrix::HomeserverConnection;
1311
use mas_router::UrlBuilder;
1412
use mas_storage::{BoxClock, BoxRepository, RepositoryError, SystemClock};
1513
use mas_storage_pg::PgRepository;
1614
use new_queue::QueueRunnerError;
15+
use opentelemetry::metrics::Meter;
1716
use rand::SeedableRng;
1817
use sqlx::{Pool, Postgres};
1918
use tokio_util::{sync::CancellationToken, task::TaskTracker};
@@ -25,6 +24,15 @@ mod new_queue;
2524
mod recovery;
2625
mod user;
2726

27+
static METER: LazyLock<Meter> = LazyLock::new(|| {
28+
let scope = opentelemetry::InstrumentationScope::builder(env!("CARGO_PKG_NAME"))
29+
.with_version(env!("CARGO_PKG_VERSION"))
30+
.with_schema_url(opentelemetry_semantic_conventions::SCHEMA_URL)
31+
.build();
32+
33+
opentelemetry::global::meter_with_scope(scope)
34+
});
35+
2836
#[derive(Clone)]
2937
struct State {
3038
pool: Pool<Postgres>,

0 commit comments

Comments
 (0)