Alternative ATProto PDS implementation
1//! Metric name constants.
2
3use std::time::Duration;
4
5use anyhow::Context as _;
6use metrics::{describe_counter, describe_gauge};
7use metrics_exporter_prometheus::PrometheusBuilder;
8
9use crate::config;
10
11/// Authorization failed. Counter.
12pub(crate) const AUTH_FAILED: &str = "bluepds.auth.failed";
13/// Firehose history. Gauge.
14pub(crate) const FIREHOSE_HISTORY: &str = "bluepds.firehose.history";
15/// Firehose listeners. Gauge.
16pub(crate) const FIREHOSE_LISTENERS: &str = "bluepds.firehose.listeners";
17/// Firehose messages. Counter.
18pub(crate) const FIREHOSE_MESSAGES: &str = "bluepds.firehose.messages";
19/// Firehose sequence. Counter.
20pub(crate) const FIREHOSE_SEQUENCE: &str = "bluepds.firehose.sequence";
21/// Repository commits. Counter.
22pub(crate) const REPO_COMMITS: &str = "bluepds.repo.commits";
23/// Repository operation create. Counter.
24pub(crate) const REPO_OP_CREATE: &str = "bluepds.repo.op.create";
25/// Repository operation update. Counter.
26pub(crate) const REPO_OP_UPDATE: &str = "bluepds.repo.op.update";
27/// Repository operation delete. Counter.
28pub(crate) const REPO_OP_DELETE: &str = "bluepds.repo.op.delete";
29
30/// Must be ran exactly once on startup. This will declare all of the instruments for `metrics`.
31pub(crate) fn setup(config: Option<&config::MetricConfig>) -> anyhow::Result<()> {
32 describe_counter!(AUTH_FAILED, "The number of failed authentication attempts.");
33
34 describe_gauge!(FIREHOSE_HISTORY, "The size of the firehose history buffer.");
35 describe_gauge!(
36 FIREHOSE_LISTENERS,
37 "The number of active consumers on the firehose."
38 );
39 describe_counter!(
40 FIREHOSE_MESSAGES,
41 "All messages that have been broadcast on the firehose."
42 );
43 describe_counter!(
44 FIREHOSE_SEQUENCE,
45 "The current sequence number on the firehose."
46 );
47
48 describe_counter!(
49 REPO_COMMITS,
50 "The count of commits created for all repositories."
51 );
52 describe_counter!(REPO_OP_CREATE, "The count of created records.");
53 describe_counter!(REPO_OP_UPDATE, "The count of updated records.");
54 describe_counter!(REPO_OP_DELETE, "The count of deleted records.");
55
56 if let Some(config) = config {
57 match *config {
58 config::MetricConfig::PrometheusPush(ref prometheus_config) => {
59 PrometheusBuilder::new()
60 .with_push_gateway(
61 prometheus_config.url.clone(),
62 Duration::from_secs(10),
63 None,
64 None,
65 )
66 .context("failed to set up push gateway")?
67 .install()
68 .context("failed to install metrics exporter")?;
69 }
70 }
71 }
72
73 Ok(())
74}