Skip to content

Commit be2f260

Browse files
authored
feat(cat-gateway): Invalid RBAC registration metric counter (#3175)
* wip * wip
1 parent 9f262c6 commit be2f260

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

catalyst-gateway/bin/src/db/index/block/rbac509/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::{
2222
queries::{FallibleQueryTasks, PreparedQuery, SizedBatch},
2323
session::CassandraSession,
2424
},
25+
metrics,
2526
settings::cassandra_db::EnvVars,
2627
};
2728

@@ -145,6 +146,7 @@ impl Rbac509InsertQuery {
145146
}
146147
},
147148
Err(report) => {
149+
metrics::rbac::inc_invalid_rbac_reg_count();
148150
self.invalid.push(insert_rbac509_invalid::Params::new(
149151
catalyst_id,
150152
txn_hash,

catalyst-gateway/bin/src/metrics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) mod chain_indexer;
88
pub(crate) mod endpoint;
99
pub(crate) mod health;
1010
pub(crate) mod memory;
11+
pub(crate) mod rbac;
1112

1213
/// Initialize Prometheus metrics.
1314
///
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! Metrics related to RBAC Registration Chain analytics.
2+
3+
use crate::settings::Settings;
4+
5+
/// Increments the `INVALID_RBAC_REGISTRATION_COUNT` metric.
6+
pub(crate) fn inc_invalid_rbac_reg_count() {
7+
let api_host_names = Settings::api_host_names().join(",");
8+
let service_id = Settings::service_id();
9+
let network = Settings::cardano_network().to_string();
10+
11+
reporter::INVALID_RBAC_REGISTRATION_COUNT
12+
.with_label_values(&[&api_host_names, service_id, &network])
13+
.inc();
14+
}
15+
16+
/// All the related RBAC Registration Chain metrics to the Prometheus
17+
/// service are inside this module.
18+
pub(crate) mod reporter {
19+
use std::sync::LazyLock;
20+
21+
use prometheus::{register_int_counter_vec, IntCounterVec};
22+
23+
/// Labels for the metrics.
24+
const METRIC_LABELS: [&str; 3] = ["api_host_names", "service_id", "network"];
25+
26+
/// This counter increases every when we found invalid RBAC registration during
27+
/// indexing.
28+
pub(crate) static INVALID_RBAC_REGISTRATION_COUNT: LazyLock<IntCounterVec> =
29+
LazyLock::new(|| {
30+
register_int_counter_vec!(
31+
"invalid_rbac_registration_count",
32+
"Number of Invalid RBAC registrations found during indexing",
33+
&METRIC_LABELS
34+
)
35+
.unwrap()
36+
});
37+
}

0 commit comments

Comments
 (0)