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 use std::sync::LazyLock;
166
167 use prometheus::{
168 register_int_counter_vec, register_int_gauge_vec, IntCounterVec, IntGaugeVec,
169 };
170
171 const METRIC_LABELS: [&str; 3] = ["api_host_names", "service_id", "network"];
173
174 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_HIT: LazyLock<IntCounterVec> =
176 LazyLock::new(|| {
177 register_int_counter_vec!(
178 "rbac_persistent_public_keys_cache_hit",
179 "A total count of persistent public keys cache hits",
180 &METRIC_LABELS
181 )
182 .unwrap()
183 });
184
185 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_MISS: LazyLock<IntCounterVec> =
187 LazyLock::new(|| {
188 register_int_counter_vec!(
189 "rbac_persistent_public_keys_cache_miss",
190 "A total count of persistent public keys cache misses",
191 &METRIC_LABELS
192 )
193 .unwrap()
194 });
195
196 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_SIZE: LazyLock<IntGaugeVec> =
198 LazyLock::new(|| {
199 register_int_gauge_vec!(
200 "rbac_persistent_public_keys_cache_size",
201 "Size in memory allocated bytes of the persistent public keys cache",
202 &METRIC_LABELS
203 )
204 .unwrap()
205 });
206
207 pub(super) static PERSISTENT_PUBLIC_KEYS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
209 LazyLock::new(|| {
210 register_int_gauge_vec!(
211 "rbac_persistent_public_keys_cache_entry_count",
212 "Number of entries in the persistent public keys cache",
213 &METRIC_LABELS
214 )
215 .unwrap()
216 });
217
218 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_HIT: LazyLock<IntCounterVec> =
220 LazyLock::new(|| {
221 register_int_counter_vec!(
222 "rbac_volatile_public_keys_cache_hit",
223 "A total count of volatile public keys cache hits",
224 &METRIC_LABELS
225 )
226 .unwrap()
227 });
228
229 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_MISS: LazyLock<IntCounterVec> =
231 LazyLock::new(|| {
232 register_int_counter_vec!(
233 "rbac_volatile_public_keys_cache_miss",
234 "A total count of volatile public keys cache misses",
235 &METRIC_LABELS
236 )
237 .unwrap()
238 });
239
240 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_SIZE: LazyLock<IntGaugeVec> =
242 LazyLock::new(|| {
243 register_int_gauge_vec!(
244 "rbac_volatile_public_keys_cache_size",
245 "Size in memory allocated bytes of the volatile public keys cache",
246 &METRIC_LABELS
247 )
248 .unwrap()
249 });
250
251 pub(super) static VOLATILE_PUBLIC_KEYS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
253 LazyLock::new(|| {
254 register_int_gauge_vec!(
255 "rbac_volatile_public_keys_cache_entry_count",
256 "Number of entries in the volatile public keys cache",
257 &METRIC_LABELS
258 )
259 .unwrap()
260 });
261
262 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_HIT: LazyLock<IntCounterVec> =
264 LazyLock::new(|| {
265 register_int_counter_vec!(
266 "rbac_persistent_stake_addresses_cache_hit",
267 "A total count of the persistent stake addresses cache hits",
268 &METRIC_LABELS
269 )
270 .unwrap()
271 });
272
273 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_MISS: LazyLock<IntCounterVec> =
275 LazyLock::new(|| {
276 register_int_counter_vec!(
277 "rbac_persistent_stake_addresses_cache_miss",
278 "A total count of the persistent stake addresses cache misses",
279 &METRIC_LABELS
280 )
281 .unwrap()
282 });
283
284 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_SIZE: LazyLock<IntGaugeVec> =
286 LazyLock::new(|| {
287 register_int_gauge_vec!(
288 "rbac_persistent_stake_addresses_cache_size",
289 "Size in memory allocated bytes of the persistent stake addresses cache",
290 &METRIC_LABELS
291 )
292 .unwrap()
293 });
294
295 pub(super) static PERSISTENT_STAKE_ADDRESSES_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
297 LazyLock::new(|| {
298 register_int_gauge_vec!(
299 "rbac_persistent_stake_addresses_cache_entry_count",
300 "Number of entries in the persistent stake addresses cache",
301 &METRIC_LABELS
302 )
303 .unwrap()
304 });
305
306 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_HIT: LazyLock<IntCounterVec> =
308 LazyLock::new(|| {
309 register_int_counter_vec!(
310 "rbac_volatile_stake_addresses_cache_hit",
311 "A total count of the volatile stake addresses cache hits",
312 &METRIC_LABELS
313 )
314 .unwrap()
315 });
316
317 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_MISS: LazyLock<IntCounterVec> =
319 LazyLock::new(|| {
320 register_int_counter_vec!(
321 "rbac_volatile_stake_addresses_cache_miss",
322 "A total count of the volatile stake addresses cache misses",
323 &METRIC_LABELS
324 )
325 .unwrap()
326 });
327
328 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_SIZE: LazyLock<IntGaugeVec> =
330 LazyLock::new(|| {
331 register_int_gauge_vec!(
332 "rbac_volatile_stake_addresses_cache_size",
333 "Size in memory allocated bytes of the volatile stake addresses cache",
334 &METRIC_LABELS
335 )
336 .unwrap()
337 });
338
339 pub(super) static VOLATILE_STAKE_ADDRESSES_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
341 LazyLock::new(|| {
342 register_int_gauge_vec!(
343 "rbac_volatile_stake_addresses_cache_entry_count",
344 "Number of entries in the volatile stake addresses cache",
345 &METRIC_LABELS
346 )
347 .unwrap()
348 });
349
350 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_HIT: LazyLock<IntCounterVec> =
352 LazyLock::new(|| {
353 register_int_counter_vec!(
354 "rbac_persistent_transaction_ids_cache_hit",
355 "A total count of the persistent transaction IDs cache hits",
356 &METRIC_LABELS
357 )
358 .unwrap()
359 });
360
361 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_MISS: LazyLock<IntCounterVec> =
363 LazyLock::new(|| {
364 register_int_counter_vec!(
365 "rbac_persistent_transaction_ids_cache_miss",
366 "A total count of the persistent transaction IDs cache misses",
367 &METRIC_LABELS
368 )
369 .unwrap()
370 });
371
372 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_SIZE: LazyLock<IntGaugeVec> =
374 LazyLock::new(|| {
375 register_int_gauge_vec!(
376 "rbac_persistent_transaction_ids_cache_size",
377 "Size in memory allocated bytes of the persistent transaction IDs cache",
378 &METRIC_LABELS
379 )
380 .unwrap()
381 });
382
383 pub(super) static PERSISTENT_TRANSACTION_IDS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
385 LazyLock::new(|| {
386 register_int_gauge_vec!(
387 "rbac_persistent_transaction_ids_cache_entry_count",
388 "Number of entries in the persistent transaction IDs cache",
389 &METRIC_LABELS
390 )
391 .unwrap()
392 });
393
394 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_HIT: LazyLock<IntCounterVec> =
396 LazyLock::new(|| {
397 register_int_counter_vec!(
398 "rbac_volatile_transaction_ids_cache_hit",
399 "A total count of volatile transaction IDs cache hits",
400 &METRIC_LABELS
401 )
402 .unwrap()
403 });
404
405 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_MISS: LazyLock<IntCounterVec> =
407 LazyLock::new(|| {
408 register_int_counter_vec!(
409 "rbac_volatile_transaction_ids_cache_miss",
410 "A total count of the volatile transaction IDs cache misses",
411 &METRIC_LABELS
412 )
413 .unwrap()
414 });
415
416 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_SIZE: LazyLock<IntGaugeVec> =
418 LazyLock::new(|| {
419 register_int_gauge_vec!(
420 "rbac_volatile_transaction_ids_cache_size",
421 "Size in memory allocated bytes of the volatile transaction IDs cache",
422 &METRIC_LABELS
423 )
424 .unwrap()
425 });
426
427 pub(super) static VOLATILE_TRANSACTION_IDS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
429 LazyLock::new(|| {
430 register_int_gauge_vec!(
431 "rbac_volatile_transaction_ids_cache_entry_count",
432 "Number of entries in the volatile transaction IDs cache",
433 &METRIC_LABELS
434 )
435 .unwrap()
436 });
437
438 pub(super) static PERSISTENT_CHAINS_CACHE_HIT: LazyLock<IntCounterVec> = LazyLock::new(|| {
440 register_int_counter_vec!(
441 "rbac_persistent_chains_cache_hit",
442 "A total count of the persistent RBAC chains cache hits",
443 &METRIC_LABELS
444 )
445 .unwrap()
446 });
447
448 pub(crate) static PERSISTENT_CHAINS_CACHE_MISS: LazyLock<IntCounterVec> = LazyLock::new(|| {
450 register_int_counter_vec!(
451 "rbac_persistent_chains_cache_miss",
452 "A total count of the persistent RBAC chains cache misses",
453 &METRIC_LABELS
454 )
455 .unwrap()
456 });
457
458 pub(super) static PERSISTENT_CHAINS_CACHE_SIZE: LazyLock<IntGaugeVec> = LazyLock::new(|| {
460 register_int_gauge_vec!(
461 "rbac_persistent_chains_cache_size",
462 "Size in memory allocated bytes of the persistent RBAC chains cache",
463 &METRIC_LABELS
464 )
465 .unwrap()
466 });
467
468 pub(super) static PERSISTENT_CHAINS_CACHE_ENTRY_COUNT: LazyLock<IntGaugeVec> =
470 LazyLock::new(|| {
471 register_int_gauge_vec!(
472 "rbac_persistent_transaction_ids_cache_entry_count",
473 "Number of entries in the persistent RBAC chains cache",
474 &METRIC_LABELS
475 )
476 .unwrap()
477 });
478
479 pub(super) static INDEXING_SYNCHRONIZATION_COUNT: LazyLock<IntCounterVec> =
482 LazyLock::new(|| {
483 register_int_counter_vec!(
484 "indexing_synchronization_count",
485 "Number of RBAC indexing synchronizations",
486 &METRIC_LABELS
487 )
488 .unwrap()
489 });
490
491 pub(super) static INVALID_RBAC_REGISTRATION_COUNT: LazyLock<IntCounterVec> =
494 LazyLock::new(|| {
495 register_int_counter_vec!(
496 "invalid_rbac_registration_count",
497 "Number of Invalid RBAC registrations found during indexing",
498 &METRIC_LABELS
499 )
500 .unwrap()
501 });
502}