pub const QUERIES_TOTAL: &str = "selene.queries.total";
pub const QUERY_DURATION_SECONDS: &str = "selene.query.duration_seconds";
pub const COMMITS_TOTAL: &str = "selene.commits.total";
pub const COMMIT_DURATION_SECONDS: &str = "selene.commit.duration_seconds";
pub const WAL_APPENDS_TOTAL: &str = "selene.wal.appends.total";
pub const SNAPSHOTS_TOTAL: &str = "selene.snapshots.total";
pub const SNAPSHOT_DURATION_SECONDS: &str = "selene.snapshot.duration_seconds";
pub const RECOVERIES_TOTAL: &str = "selene.recoveries.total";
pub const RECOVERY_DURATION_SECONDS: &str = "selene.recovery.duration_seconds";
pub const CANCELLATIONS_TOTAL: &str = "selene.cancellations.total";
pub const ALGORITHM_RUNS_TOTAL: &str = "selene.algorithm.runs.total";
pub const CALL_PLAN_CACHE_HITS_TOTAL: &str = "selene.gql.call_plan_cache.hits.total";
pub const GRAPH_NODES: &str = "selene.graph.nodes";
pub const GRAPH_EDGES: &str = "selene.graph.edges";
pub const STATEMENT_KIND_LABEL: &str = "statement.kind";
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Label {
pub key: &'static str,
pub value: &'static str,
}
impl Label {
#[must_use]
pub const fn new(key: &'static str, value: &'static str) -> Self {
Self { key, value }
}
}
pub fn counter_inc(name: &'static str) {
counter_add(name, 1);
}
pub fn counter_inc_with_label(name: &'static str, label: Label) {
counter_add_with_label(name, 1, label);
}
#[cfg(feature = "metrics")]
pub fn counter_add(name: &'static str, value: u64) {
metrics::counter!(name).increment(value);
}
#[cfg(not(feature = "metrics"))]
pub fn counter_add(_name: &'static str, _value: u64) {}
#[cfg(feature = "metrics")]
pub fn counter_add_with_label(name: &'static str, value: u64, label: Label) {
metrics::counter!(name, label.key => label.value).increment(value);
}
#[cfg(not(feature = "metrics"))]
pub fn counter_add_with_label(_name: &'static str, _value: u64, _label: Label) {}
#[cfg(feature = "metrics")]
pub fn histogram_record(name: &'static str, seconds: f64) {
metrics::histogram!(name).record(seconds);
}
#[cfg(not(feature = "metrics"))]
pub fn histogram_record(_name: &'static str, _seconds: f64) {}
#[cfg(feature = "metrics")]
pub fn histogram_record_with_label(name: &'static str, seconds: f64, label: Label) {
metrics::histogram!(name, label.key => label.value).record(seconds);
}
#[cfg(not(feature = "metrics"))]
pub fn histogram_record_with_label(_name: &'static str, _seconds: f64, _label: Label) {}
#[cfg(feature = "metrics")]
pub fn gauge_set(name: &'static str, value: f64) {
metrics::gauge!(name).set(value);
}
#[cfg(not(feature = "metrics"))]
pub fn gauge_set(_name: &'static str, _value: f64) {}