cat_gateway/metrics/caches/
rbac.rs1use super::cache_metric_inc;
4use crate::{db::index::session::CassandraSession, settings::Settings};
5
6const PERSISTENT: bool = true;
8const VOLATILE: bool = false;
10
11pub(crate) fn update() {
13 let api_host_names = Settings::api_host_names().join(",");
14 let service_id = Settings::service_id();
15 let network = Settings::cardano_network().to_string();
16
17 CassandraSession::get(PERSISTENT).inspect(|session| {
18 let caches = session.caches();
19
20 reporter::PERSISTENT_PUBLIC_KEYS_CACHE_SIZE
21 .with_label_values(&[&api_host_names, service_id, &network])
22 .set(i64::try_from(caches.rbac_public_key().weighted_size()).unwrap_or(-1));
23
24 reporter::PERSISTENT_STAKE_ADDRESSES_CACHE_SIZE
25 .with_label_values(&[&api_host_names, service_id, &network])
26 .set(i64::try_from(caches.rbac_stake_address().weighted_size()).unwrap_or(-1));
27
28 reporter::PERSISTENT_TRANSACTION_IDS_CACHE_SIZE
29 .with_label_values(&[&api_host_names, service_id, &network])
30 .set(i64::try_from(caches.rbac_transaction_id().weighted_size()).unwrap_or(-1));
31
32 reporter::PERSISTENT_CHAINS_CACHE_SIZE
33 .with_label_values(&[&api_host_names, service_id, &network])
34 .set(i64::try_from(caches.rbac_persistent_chains().weighted_size()).unwrap_or(-1));
35
36 reporter::PERSISTENT_PUBLIC_KEYS_CACHE_ENTRY_COUNT
37 .with_label_values(&[&api_host_names, service_id, &network])
38 .set(i64::try_from(caches.rbac_public_key().entry_count()).unwrap_or(-1));
39
40 reporter::PERSISTENT_STAKE_ADDRESSES_CACHE_ENTRY_COUNT
41 .with_label_values(&[&api_host_names, service_id, &network])
42 .set(i64::try_from(caches.rbac_stake_address().entry_count()).unwrap_or(-1));
43
44 reporter::PERSISTENT_TRANSACTION_IDS_CACHE_ENTRY_COUNT
45 .with_label_values(&[&api_host_names, service_id, &network])
46 .set(i64::try_from(caches.rbac_transaction_id().entry_count()).unwrap_or(-1));
47
48 reporter::PERSISTENT_CHAINS_CACHE_ENTRY_COUNT
49 .with_label_values(&[&api_host_names, service_id, &network])
50 .set(i64::try_from(caches.rbac_persistent_chains().entry_count()).unwrap_or(-1));
51 });
52
53 CassandraSession::get(VOLATILE).inspect(|session| {
54 let caches = session.caches();
55
56 reporter::VOLATILE_PUBLIC_KEYS_CACHE_SIZE
57 .with_label_values(&[&api_host_names, service_id, &network])
58 .set(i64::try_from(caches.rbac_public_key().weighted_size()).unwrap_or(-1));
59
60 reporter::VOLATILE_STAKE_ADDRESSES_CACHE_SIZE
61 .with_label_values(&[&api_host_names, service_id, &network])
62 .set(i64::try_from(caches.rbac_stake_address().weighted_size()).unwrap_or(-1));
63
64 reporter::VOLATILE_TRANSACTION_IDS_CACHE_SIZE
65 .with_label_values(&[&api_host_names, service_id, &network])
66 .set(i64::try_from(caches.rbac_transaction_id().weighted_size()).unwrap_or(-1));
67
68 reporter::VOLATILE_PUBLIC_KEYS_CACHE_ENTRY_COUNT
69 .with_label_values(&[&api_host_names, service_id, &network])
70 .set(i64::try_from(caches.rbac_public_key().entry_count()).unwrap_or(-1));
71
72 reporter::VOLATILE_STAKE_ADDRESSES_CACHE_ENTRY_COUNT
73 .with_label_values(&[&api_host_names, service_id, &network])
74 .set(i64::try_from(caches.rbac_stake_address().entry_count()).unwrap_or(-1));
75
76 reporter::VOLATILE_TRANSACTION_IDS_CACHE_ENTRY_COUNT
77 .with_label_values(&[&api_host_names, service_id, &network])
78 .set(i64::try_from(caches.rbac_transaction_id().entry_count()).unwrap_or(-1));
79 });
80}
81
82pub(crate) fn rbac_volatile_stake_address_cache_hits_inc() {
84 cache_metric_inc!(VOLATILE_STAKE_ADDRESSES_CACHE_HIT);
85}
86
87pub(crate) fn rbac_volatile_stake_address_cache_miss_inc() {
89 cache_metric_inc!(VOLATILE_STAKE_ADDRESSES_CACHE_MISS);
90}
91
92pub(crate) fn rbac_persistent_stake_address_cache_hits_inc() {
94 cache_metric_inc!(PERSISTENT_STAKE_ADDRESSES_CACHE_HIT);
95}
96
97pub(crate) fn rbac_persistent_stake_address_cache_miss_inc() {
99 cache_metric_inc!(PERSISTENT_STAKE_ADDRESSES_CACHE_MISS);
100}
101
102pub(crate) fn rbac_persistent_public_key_cache_hits_inc() {
104 cache_metric_inc!(PERSISTENT_PUBLIC_KEYS_CACHE_HIT);
105}
106
107pub(crate) fn rbac_persistent_public_key_cache_miss_inc() {
109 cache_metric_inc!(PERSISTENT_PUBLIC_KEYS_CACHE_MISS);
110}
111
112pub(crate) fn rbac_volatile_public_key_cache_hits_inc() {
114 cache_metric_inc!(VOLATILE_PUBLIC_KEYS_CACHE_HIT);
115}
116
117pub(crate) fn rbac_volatile_public_key_cache_miss_inc() {
119 cache_metric_inc!(VOLATILE_PUBLIC_KEYS_CACHE_MISS);
120}
121
122pub(crate) fn rbac_persistent_transaction_id_cache_hits_inc() {
124 cache_metric_inc!(PERSISTENT_TRANSACTION_IDS_CACHE_HIT);
125}
126
127pub(crate) fn rbac_persistent_transaction_id_cache_miss_inc() {
129 cache_metric_inc!(PERSISTENT_TRANSACTION_IDS_CACHE_MISS);
130}
131
132pub(crate) fn rbac_volatile_transaction_id_cache_hits_inc() {
134 cache_metric_inc!(VOLATILE_TRANSACTION_IDS_CACHE_HIT);
135}
136
137pub(crate) fn rbac_volatile_transaction_id_cache_miss_inc() {
139 cache_metric_inc!(VOLATILE_TRANSACTION_IDS_CACHE_MISS);
140}
141
142pub(crate) fn rbac_persistent_chains_cache_hits_inc() {
144 cache_metric_inc!(PERSISTENT_CHAINS_CACHE_HIT);
145}
146
147pub(crate) fn rbac_persistent_chains_cache_miss_inc() {
149 cache_metric_inc!(PERSISTENT_CHAINS_CACHE_MISS);
150}
151
152pub(crate) fn inc_index_sync() {
154 cache_metric_inc!(INDEXING_SYNCHRONIZATION_COUNT);
155}
156
157pub(crate) fn inc_invalid_rbac_reg_count() {
159 cache_metric_inc!(INVALID_RBAC_REGISTRATION_COUNT);
160}
161
162pub(crate) mod reporter {
165 #![allow(clippy::unwrap_used)]
166
167 use std::sync::LazyLock;
168
169 use prometheus::{
170 register_int_counter_vec, register_int_gauge_vec, IntCounterVec, IntGaugeVec,
171 };
172
173 const METRIC_LABELS: [&str; 3] = ["api_host_names", "service_id", "network"];
175
176 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_HIT: LazyLock<IntCounterVec> =
178 LazyLock::new(|| {
179 register_int_counter_vec!(
180 "rbac_persistent_public_keys_cache_hit",
181 "A total count of persistent public keys cache hits",
182 &METRIC_LABELS
183 )
184 .unwrap()
185 });
186
187 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_MISS: LazyLock<IntCounterVec> =
189 LazyLock::new(|| {
190 register_int_counter_vec!(
191 "rbac_persistent_public_keys_cache_miss",
192 "A total count of persistent public keys cache misses",
193 &METRIC_LABELS
194 )
195 .unwrap()
196 });
197
198 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_SIZE: LazyLock<IntGaugeVec> =
200 LazyLock::new(|| {
201 register_int_gauge_vec!(
202 "rbac_persistent_public_keys_cache_size",
203 "Size in memory allocated bytes of the persistent public keys cache",
204 &METRIC_LABELS
205 )
206 .unwrap()
207 });
208
209 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
211 LazyLock::new(|| {
212 register_int_gauge_vec!(
213 "rbac_persistent_public_keys_cache_entry_count",
214 "Number of entries in the persistent public keys cache",
215 &METRIC_LABELS
216 )
217 .unwrap()
218 });
219
220 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_HIT: LazyLock<IntCounterVec> =
222 LazyLock::new(|| {
223 register_int_counter_vec!(
224 "rbac_volatile_public_keys_cache_hit",
225 "A total count of volatile public keys cache hits",
226 &METRIC_LABELS
227 )
228 .unwrap()
229 });
230
231 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_MISS: LazyLock<IntCounterVec> =
233 LazyLock::new(|| {
234 register_int_counter_vec!(
235 "rbac_volatile_public_keys_cache_miss",
236 "A total count of volatile public keys cache misses",
237 &METRIC_LABELS
238 )
239 .unwrap()
240 });
241
242 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_SIZE: LazyLock<IntGaugeVec> =
244 LazyLock::new(|| {
245 register_int_gauge_vec!(
246 "rbac_volatile_public_keys_cache_size",
247 "Size in memory allocated bytes of the volatile public keys cache",
248 &METRIC_LABELS
249 )
250 .unwrap()
251 });
252
253 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
255 LazyLock::new(|| {
256 register_int_gauge_vec!(
257 "rbac_volatile_public_keys_cache_entry_count",
258 "Number of entries in the volatile public keys cache",
259 &METRIC_LABELS
260 )
261 .unwrap()
262 });
263
264 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_HIT: LazyLock<IntCounterVec> =
266 LazyLock::new(|| {
267 register_int_counter_vec!(
268 "rbac_persistent_stake_addresses_cache_hit",
269 "A total count of the persistent stake addresses cache hits",
270 &METRIC_LABELS
271 )
272 .unwrap()
273 });
274
275 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_MISS: LazyLock<IntCounterVec> =
277 LazyLock::new(|| {
278 register_int_counter_vec!(
279 "rbac_persistent_stake_addresses_cache_miss",
280 "A total count of the persistent stake addresses cache misses",
281 &METRIC_LABELS
282 )
283 .unwrap()
284 });
285
286 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_SIZE: LazyLock<IntGaugeVec> =
288 LazyLock::new(|| {
289 register_int_gauge_vec!(
290 "rbac_persistent_stake_addresses_cache_size",
291 "Size in memory allocated bytes of the persistent stake addresses cache",
292 &METRIC_LABELS
293 )
294 .unwrap()
295 });
296
297 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
299 LazyLock::new(|| {
300 register_int_gauge_vec!(
301 "rbac_persistent_stake_addresses_cache_entry_count",
302 "Number of entries in the persistent stake addresses cache",
303 &METRIC_LABELS
304 )
305 .unwrap()
306 });
307
308 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_HIT: LazyLock<IntCounterVec> =
310 LazyLock::new(|| {
311 register_int_counter_vec!(
312 "rbac_volatile_stake_addresses_cache_hit",
313 "A total count of the volatile stake addresses cache hits",
314 &METRIC_LABELS
315 )
316 .unwrap()
317 });
318
319 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_MISS: LazyLock<IntCounterVec> =
321 LazyLock::new(|| {
322 register_int_counter_vec!(
323 "rbac_volatile_stake_addresses_cache_miss",
324 "A total count of the volatile stake addresses cache misses",
325 &METRIC_LABELS
326 )
327 .unwrap()
328 });
329
330 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_SIZE: LazyLock<IntGaugeVec> =
332 LazyLock::new(|| {
333 register_int_gauge_vec!(
334 "rbac_volatile_stake_addresses_cache_size",
335 "Size in memory allocated bytes of the volatile stake addresses cache",
336 &METRIC_LABELS
337 )
338 .unwrap()
339 });
340
341 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
343 LazyLock::new(|| {
344 register_int_gauge_vec!(
345 "rbac_volatile_stake_addresses_cache_entry_count",
346 "Number of entries in the volatile stake addresses cache",
347 &METRIC_LABELS
348 )
349 .unwrap()
350 });
351
352 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_HIT: LazyLock<IntCounterVec> =
354 LazyLock::new(|| {
355 register_int_counter_vec!(
356 "rbac_persistent_transaction_ids_cache_hit",
357 "A total count of the persistent transaction IDs cache hits",
358 &METRIC_LABELS
359 )
360 .unwrap()
361 });
362
363 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_MISS: LazyLock<IntCounterVec> =
365 LazyLock::new(|| {
366 register_int_counter_vec!(
367 "rbac_persistent_transaction_ids_cache_miss",
368 "A total count of the persistent transaction IDs cache misses",
369 &METRIC_LABELS
370 )
371 .unwrap()
372 });
373
374 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_SIZE: LazyLock<IntGaugeVec> =
376 LazyLock::new(|| {
377 register_int_gauge_vec!(
378 "rbac_persistent_transaction_ids_cache_size",
379 "Size in memory allocated bytes of the persistent transaction IDs cache",
380 &METRIC_LABELS
381 )
382 .unwrap()
383 });
384
385 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
387 LazyLock::new(|| {
388 register_int_gauge_vec!(
389 "rbac_persistent_transaction_ids_cache_entry_count",
390 "Number of entries in the persistent transaction IDs cache",
391 &METRIC_LABELS
392 )
393 .unwrap()
394 });
395
396 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_HIT: LazyLock<IntCounterVec> =
398 LazyLock::new(|| {
399 register_int_counter_vec!(
400 "rbac_volatile_transaction_ids_cache_hit",
401 "A total count of volatile transaction IDs cache hits",
402 &METRIC_LABELS
403 )
404 .unwrap()
405 });
406
407 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_MISS: LazyLock<IntCounterVec> =
409 LazyLock::new(|| {
410 register_int_counter_vec!(
411 "rbac_volatile_transaction_ids_cache_miss",
412 "A total count of the volatile transaction IDs cache misses",
413 &METRIC_LABELS
414 )
415 .unwrap()
416 });
417
418 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_SIZE: LazyLock<IntGaugeVec> =
420 LazyLock::new(|| {
421 register_int_gauge_vec!(
422 "rbac_volatile_transaction_ids_cache_size",
423 "Size in memory allocated bytes of the volatile transaction IDs cache",
424 &METRIC_LABELS
425 )
426 .unwrap()
427 });
428
429 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
431 LazyLock::new(|| {
432 register_int_gauge_vec!(
433 "rbac_volatile_transaction_ids_cache_entry_count",
434 "Number of entries in the volatile transaction IDs cache",
435 &METRIC_LABELS
436 )
437 .unwrap()
438 });
439
440 pub(super) static PERSISTENT_CHAINS_CACHE_HIT: LazyLock<IntCounterVec> = LazyLock::new(|| {
442 register_int_counter_vec!(
443 "rbac_persistent_chains_cache_hit",
444 "A total count of the persistent RBAC chains cache hits",
445 &METRIC_LABELS
446 )
447 .unwrap()
448 });
449
450 pub(crate) static PERSISTENT_CHAINS_CACHE_MISS: LazyLock<IntCounterVec> = LazyLock::new(|| {
452 register_int_counter_vec!(
453 "rbac_persistent_chains_cache_miss",
454 "A total count of the persistent RBAC chains cache misses",
455 &METRIC_LABELS
456 )
457 .unwrap()
458 });
459
460 pub(super) static PERSISTENT_CHAINS_CACHE_SIZE: LazyLock<IntGaugeVec> = LazyLock::new(|| {
462 register_int_gauge_vec!(
463 "rbac_persistent_chains_cache_size",
464 "Size in memory allocated bytes of the persistent RBAC chains cache",
465 &METRIC_LABELS
466 )
467 .unwrap()
468 });
469
470 pub(super) static PERSISTENT_CHAINS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
472 LazyLock::new(|| {
473 register_int_gauge_vec!(
474 "rbac_persistent_transaction_ids_cache_entry_count",
475 "Number of entries in the persistent RBAC chains cache",
476 &METRIC_LABELS
477 )
478 .unwrap()
479 });
480
481 pub(super) static INDEXING_SYNCHRONIZATION_COUNT: LazyLock<IntCounterVec> =
484 LazyLock::new(|| {
485 register_int_counter_vec!(
486 "indexing_synchronization_count",
487 "Number of RBAC indexing synchronizations",
488 &METRIC_LABELS
489 )
490 .unwrap()
491 });
492
493 pub(super) static INVALID_RBAC_REGISTRATION_COUNT: LazyLock<IntCounterVec> =
496 LazyLock::new(|| {
497 register_int_counter_vec!(
498 "invalid_rbac_registration_count",
499 "Number of Invalid RBAC registrations found during indexing",
500 &METRIC_LABELS
501 )
502 .unwrap()
503 });
504}