cat_gateway/metrics/chain_follower/
reporter.rs

1//! All the related Chain Follower reporting metrics to the Prometheus service are inside
2//! this module.
3
4use std::sync::LazyLock;
5
6use prometheus::{register_int_gauge_vec, IntGaugeVec};
7
8// TODO: directly map those network labels from `Network` variants instead
9/// Chain networks use as the metrics namespace.
10const FOLLOWER_METRIC_NETWORKS: [&str; 3] = ["mainnet", "preprod", "preview"];
11
12/// Labels for the chain follower metrics
13const FOLLOWER_METRIC_LABELS: [&str; 3] = ["api_host_names", "service_id", "network"];
14
15// -- Mithril
16
17/// Number of Mithril Snapshots that have downloaded successfully.
18pub(super) static MITHRIL_UPDATES: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
19    FOLLOWER_METRIC_NETWORKS.map(|network| {
20        register_int_gauge_vec!(
21            format!("{network}_follower_mithril_updates"),
22            "Number of Mithril Snapshots that have downloaded successfully",
23            &FOLLOWER_METRIC_LABELS
24        )
25        .unwrap()
26    })
27});
28
29/// Immutable TIP Slot# - Origin = No downloaded snapshot.
30pub(super) static MITHRIL_TIP: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
31    FOLLOWER_METRIC_NETWORKS.map(|network| {
32        register_int_gauge_vec!(
33            format!("{network}_follower_mithril_tip"),
34            "Immutable TIP Slot#",
35            &FOLLOWER_METRIC_LABELS
36        )
37        .unwrap()
38    })
39});
40
41/// Time we started downloading the current snapshot.
42pub(super) static MITHRIL_DL_START: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
43    FOLLOWER_METRIC_NETWORKS.map(|network| {
44        register_int_gauge_vec!(
45            format!("{network}_follower_mithril_dl_start"),
46            "Time we started downloading the current snapshot (UNIX timestamp)",
47            &FOLLOWER_METRIC_LABELS
48        )
49        .unwrap()
50    })
51});
52
53/// Time we finished downloading the current snapshot.
54pub(super) static MITHRIL_DL_END: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
55    FOLLOWER_METRIC_NETWORKS.map(|network| {
56        register_int_gauge_vec!(
57            format!("{network}_follower_mithril_dl_end"),
58            "Time we finished downloading the current snapshot (UNIX timestamp)",
59            &FOLLOWER_METRIC_LABELS
60        )
61        .unwrap()
62    })
63});
64
65/// Number of times download failed.
66pub(super) static MITHRIL_DL_FAILURES: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
67    FOLLOWER_METRIC_NETWORKS.map(|network| {
68        register_int_gauge_vec!(
69            format!("{network}_follower_mithril_dl_failures"),
70            "Number of times download failed",
71            &FOLLOWER_METRIC_LABELS
72        )
73        .unwrap()
74    })
75});
76
77/// Time the last download took.
78pub(super) static MITHRIL_LAST_DL_DURATION: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
79    FOLLOWER_METRIC_NETWORKS.map(|network| {
80        register_int_gauge_vec!(
81            format!("{network}_follower_mithril_last_dl_duration"),
82            "Time the last download took (seconds)",
83            &FOLLOWER_METRIC_LABELS
84        )
85        .unwrap()
86    })
87});
88
89/// Size of the download archive.
90pub(super) static MITHRIL_DL_SIZE: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
91    FOLLOWER_METRIC_NETWORKS.map(|network| {
92        register_int_gauge_vec!(
93            format!("{network}_follower_mithril_dl_size"),
94            "Size of the download archive (bytes)",
95            &FOLLOWER_METRIC_LABELS
96        )
97        .unwrap()
98    })
99});
100
101/// Number of times extraction failed.
102pub(super) static MITHRIL_EXTRACT_FAILURES: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
103    FOLLOWER_METRIC_NETWORKS.map(|network| {
104        register_int_gauge_vec!(
105            format!("{network}_follower_mithril_extract_failures"),
106            "Number of times extraction failed",
107            &FOLLOWER_METRIC_LABELS
108        )
109        .unwrap()
110    })
111});
112
113/// Extraction start time.
114pub(super) static MITHRIL_EXTRACT_START: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
115    FOLLOWER_METRIC_NETWORKS.map(|network| {
116        register_int_gauge_vec!(
117            format!("{network}_follower_mithril_extract_start"),
118            "Extraction start time (UNIX timestamp)",
119            &FOLLOWER_METRIC_LABELS
120        )
121        .unwrap()
122    })
123});
124
125/// Extraction end time.
126pub(super) static MITHRIL_EXTRACT_END: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
127    FOLLOWER_METRIC_NETWORKS.map(|network| {
128        register_int_gauge_vec!(
129            format!("{network}_follower_mithril_extract_end"),
130            "Extraction end time (UNIX timestamp)",
131            &FOLLOWER_METRIC_LABELS
132        )
133        .unwrap()
134    })
135});
136
137/// Size of last extracted snapshot.
138pub(super) static MITHRIL_EXTRACT_SIZE: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
139    FOLLOWER_METRIC_NETWORKS.map(|network| {
140        register_int_gauge_vec!(
141            format!("{network}_follower_mithril_extract_size"),
142            "Size of last extracted snapshot (bytes)",
143            &FOLLOWER_METRIC_LABELS
144        )
145        .unwrap()
146    })
147});
148
149/// Deduplicated Size vs previous snapshot.
150pub(super) static MITHRIL_DEDUPLICATED_SIZE: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
151    FOLLOWER_METRIC_NETWORKS.map(|network| {
152        register_int_gauge_vec!(
153            format!("{network}_follower_mithril_deduplicated_size"),
154            "Deduplicated Size vs previous snapshot",
155            &FOLLOWER_METRIC_LABELS
156        )
157        .unwrap()
158    })
159});
160
161/// Number of identical files deduplicated from previous snapshot.
162pub(super) static MITHRIL_DEDUPLICATED: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
163    FOLLOWER_METRIC_NETWORKS.map(|network| {
164        register_int_gauge_vec!(
165            format!("{network}_follower_mithril_deduplicated"),
166            "Number of identical files deduplicated from previous snapshot",
167            &FOLLOWER_METRIC_LABELS
168        )
169        .unwrap()
170    })
171});
172
173/// Number of changed files from previous snapshot.
174pub(super) static MITHRIL_CHANGED: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
175    FOLLOWER_METRIC_NETWORKS.map(|network| {
176        register_int_gauge_vec!(
177            format!("{network}_follower_mithril_changed"),
178            "Number of changed files from previous snapshot",
179            &FOLLOWER_METRIC_LABELS
180        )
181        .unwrap()
182    })
183});
184
185/// Number of new files from previous snapshot.
186pub(super) static MITHRIL_NEW: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
187    FOLLOWER_METRIC_NETWORKS.map(|network| {
188        register_int_gauge_vec!(
189            format!("{network}_follower_mithril_new"),
190            "Number of new files from previous snapshot",
191            &FOLLOWER_METRIC_LABELS
192        )
193        .unwrap()
194    })
195});
196
197/// Mithril Certificate Validation Start Time.
198pub(super) static MITHRIL_VALIDATE_START: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
199    FOLLOWER_METRIC_NETWORKS.map(|network| {
200        register_int_gauge_vec!(
201            format!("{network}_follower_mithril_validate_start"),
202            "Mithril Certificate Validation Start Time (UNIX timestamp)",
203            &FOLLOWER_METRIC_LABELS
204        )
205        .unwrap()
206    })
207});
208
209/// Mithril Certificate Validation End Time.
210pub(super) static MITHRIL_VALIDATE_END: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
211    FOLLOWER_METRIC_NETWORKS.map(|network| {
212        register_int_gauge_vec!(
213            format!("{network}_follower_mithril_validate_end"),
214            "Mithril Certificate Validation End Time (UNIX timestamp)",
215            &FOLLOWER_METRIC_LABELS
216        )
217        .unwrap()
218    })
219});
220
221/// Number of times validation failed (bad snapshot).
222pub(super) static MITHRIL_VALIDATE_FAILURES: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
223    FOLLOWER_METRIC_NETWORKS.map(|network| {
224        register_int_gauge_vec!(
225            format!("{network}_follower_mithril_validate_failures"),
226            "Number of times validation failed (bad snapshot)",
227            &FOLLOWER_METRIC_LABELS
228        )
229        .unwrap()
230    })
231});
232
233/// Blocks that failed to deserialize from the Mithril immutable chain.
234pub(super) static MITHRIL_INVALID_BLOCKS: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
235    FOLLOWER_METRIC_NETWORKS.map(|network| {
236        register_int_gauge_vec!(
237            format!("{network}_follower_mithril_invalid_blocks"),
238            "Blocks that failed to deserialize from the Mithril immutable chain",
239            &FOLLOWER_METRIC_LABELS
240        )
241        .unwrap()
242    })
243});
244
245/// Download or Validation Failed.
246pub(super) static MITHRIL_DOWNLOAD_OR_VALIDATION_FAILED: LazyLock<[IntGaugeVec; 3]> =
247    LazyLock::new(|| {
248        FOLLOWER_METRIC_NETWORKS.map(|network| {
249            register_int_gauge_vec!(
250                format!("{network}_follower_mithril_download_or_validation_failed"),
251                "Download or Validation Failed",
252                &FOLLOWER_METRIC_LABELS
253            )
254            .unwrap()
255        })
256    });
257
258/// Failed to get tip from Mithril snapshot.
259pub(super) static MITHRIL_FAILED_TO_GET_TIP: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
260    FOLLOWER_METRIC_NETWORKS.map(|network| {
261        register_int_gauge_vec!(
262            format!("{network}_follower_mithril_failed_to_get_tip"),
263            "Failed to get tip from Mithril snapshot",
264            &FOLLOWER_METRIC_LABELS
265        )
266        .unwrap()
267    })
268});
269
270/// Tip failed to advance.
271pub(super) static MITHRIL_TIP_DID_NOT_ADVANCE: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
272    FOLLOWER_METRIC_NETWORKS.map(|network| {
273        register_int_gauge_vec!(
274            format!("{network}_follower_mithril_tip_did_not_advance"),
275            "Tip failed to advance",
276            &FOLLOWER_METRIC_LABELS
277        )
278        .unwrap()
279    })
280});
281
282/// Failed to send new tip to updater.
283pub(super) static MITHRIL_TIP_FAILED_TO_SEND_TO_UPDATER: LazyLock<[IntGaugeVec; 3]> =
284    LazyLock::new(|| {
285        FOLLOWER_METRIC_NETWORKS.map(|network| {
286            register_int_gauge_vec!(
287                format!("{network}_follower_mithril_tip_failed_to_send_to_updater"),
288                "Failed to send new tip to updater",
289                &FOLLOWER_METRIC_LABELS
290            )
291            .unwrap()
292        })
293    });
294
295/// Failed to activate new snapshot.
296pub(super) static MITHRIL_FAILED_TO_ACTIVATE_NEW_SNAPSHOT: LazyLock<[IntGaugeVec; 3]> =
297    LazyLock::new(|| {
298        FOLLOWER_METRIC_NETWORKS.map(|network| {
299            register_int_gauge_vec!(
300                format!("{network}_follower_mithril_failed_to_activate_new_snapshot"),
301                "Failed to activate new snapshot",
302                &FOLLOWER_METRIC_LABELS
303            )
304            .unwrap()
305        })
306    });
307
308// -- Live
309
310/// The Time that synchronization to this blockchain started
311pub(super) static LIVE_SYNC_START: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
312    FOLLOWER_METRIC_NETWORKS.map(|network| {
313        register_int_gauge_vec!(
314            format!("{network}_follower_live_sync_start"),
315            "The Time that synchronization to this blockchain started",
316            &FOLLOWER_METRIC_LABELS
317        )
318        .unwrap()
319    })
320});
321
322/// The Time that synchronization to this blockchain was complete up-to-tip. None =
323/// Not yet synchronized.
324pub(super) static LIVE_SYNC_END: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
325    FOLLOWER_METRIC_NETWORKS.map(|network| {
326        register_int_gauge_vec!(
327            format!("{network}_follower_live_sync_end"),
328            "The Time that synchronization to this blockchain was complete up-to-tip",
329            &FOLLOWER_METRIC_LABELS
330        )
331        .unwrap()
332    })
333});
334
335/// When backfill started
336pub(super) static LIVE_BACKFILL_START: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
337    FOLLOWER_METRIC_NETWORKS.map(|network| {
338        register_int_gauge_vec!(
339            format!("{network}_follower_live_backfill_start"),
340            "When backfill started",
341            &FOLLOWER_METRIC_LABELS
342        )
343        .unwrap()
344    })
345});
346
347/// Backfill size to achieve synchronization. (0 before sync completed)
348pub(super) static LIVE_BACKFILL_SIZE: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
349    FOLLOWER_METRIC_NETWORKS.map(|network| {
350        register_int_gauge_vec!(
351            format!("{network}_follower_live_backfill_size"),
352            "Backfill size to achieve synchronization",
353            &FOLLOWER_METRIC_LABELS
354        )
355        .unwrap()
356    })
357});
358
359/// When backfill ended
360pub(super) static LIVE_BACKFILL_END: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
361    FOLLOWER_METRIC_NETWORKS.map(|network| {
362        register_int_gauge_vec!(
363            format!("{network}_follower_live_backfill_end"),
364            "When backfill ended",
365            &FOLLOWER_METRIC_LABELS
366        )
367        .unwrap()
368    })
369});
370
371/// Backfill Failures
372pub(super) static LIVE_BACKFILL_FAILURES: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
373    FOLLOWER_METRIC_NETWORKS.map(|network| {
374        register_int_gauge_vec!(
375            format!("{network}_follower_live_backfill_failures"),
376            "Backfill Failures",
377            &FOLLOWER_METRIC_LABELS
378        )
379        .unwrap()
380    })
381});
382
383/// The time of the last backfill failure
384pub(super) static LIVE_BACKFILL_FAILURE_TIME: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
385    FOLLOWER_METRIC_NETWORKS.map(|network| {
386        register_int_gauge_vec!(
387            format!("{network}_follower_live_backfill_failure_time"),
388            "The time of the last backfill failure",
389            &FOLLOWER_METRIC_LABELS
390        )
391        .unwrap()
392    })
393});
394
395/// Current Number of Live Blocks
396pub(super) static LIVE_BLOCKS: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
397    FOLLOWER_METRIC_NETWORKS.map(|network| {
398        register_int_gauge_vec!(
399            format!("{network}_follower_live_blocks"),
400            "Current Number of Live Blocks",
401            &FOLLOWER_METRIC_LABELS
402        )
403        .unwrap()
404    })
405});
406
407/// The current head of the live chain slot#
408pub(super) static LIVE_HEAD_SLOT: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
409    FOLLOWER_METRIC_NETWORKS.map(|network| {
410        register_int_gauge_vec!(
411            format!("{network}_follower_live_head_slot"),
412            "The current head of the live chain slot#",
413            &FOLLOWER_METRIC_LABELS
414        )
415        .unwrap()
416    })
417});
418
419/// The current live tip slot# as reported by the peer.
420pub(super) static LIVE_TIP: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
421    FOLLOWER_METRIC_NETWORKS.map(|network| {
422        register_int_gauge_vec!(
423            format!("{network}_follower_live_tip"),
424            "The current live tip slot# as reported by the peer",
425            &FOLLOWER_METRIC_LABELS
426        )
427        .unwrap()
428    })
429});
430
431/// Number of times we connected/re-connected to the Node.
432pub(super) static LIVE_RECONNECTS: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
433    FOLLOWER_METRIC_NETWORKS.map(|network| {
434        register_int_gauge_vec!(
435            format!("{network}_follower_live_reconnects"),
436            "Number of times we connected/re-connected to the Node",
437            &FOLLOWER_METRIC_LABELS
438        )
439        .unwrap()
440    })
441});
442
443/// Last reconnect time
444pub(super) static LIVE_LAST_CONNECT: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
445    FOLLOWER_METRIC_NETWORKS.map(|network| {
446        register_int_gauge_vec!(
447            format!("{network}_follower_live_last_connect"),
448            "Last reconnect time",
449            &FOLLOWER_METRIC_LABELS
450        )
451        .unwrap()
452    })
453});
454
455/// Last disconnect time
456pub(super) static LIVE_LAST_DISCONNECT: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
457    FOLLOWER_METRIC_NETWORKS.map(|network| {
458        register_int_gauge_vec!(
459            format!("{network}_follower_live_last_disconnect"),
460            "Last disconnect time",
461            &FOLLOWER_METRIC_LABELS
462        )
463        .unwrap()
464    })
465});
466
467/// Is there an active connection to the node
468pub(super) static LIVE_CONNECTED: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
469    FOLLOWER_METRIC_NETWORKS.map(|network| {
470        register_int_gauge_vec!(
471            format!("{network}_follower_live_connected"),
472            "Is there an active connection to the node",
473            &FOLLOWER_METRIC_LABELS
474        )
475        .unwrap()
476    })
477});
478
479/// Rollbacks we did on our live-chain in memory.
480pub(super) static LIVE_ROLLBACKS_LIVE_COUNT: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
481    FOLLOWER_METRIC_NETWORKS.map(|network| {
482        register_int_gauge_vec!(
483            format!("{network}_follower_live_rollbacks_live_count"),
484            "Number of live chain rollback",
485            &FOLLOWER_METRIC_LABELS
486        )
487        .unwrap()
488    })
489});
490
491/// Rollbacks reported by the Peer Node.
492pub(super) static LIVE_ROLLBACKS_PEER_COUNT: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
493    FOLLOWER_METRIC_NETWORKS.map(|network| {
494        register_int_gauge_vec!(
495            format!("{network}_follower_live_rollbacks_peer_count"),
496            "Number of rollbacks reported by the peer node",
497            &FOLLOWER_METRIC_LABELS
498        )
499        .unwrap()
500    })
501});
502
503/// Rollbacks synthesized for followers.
504pub(super) static LIVE_ROLLBACKS_FOLLOWER_COUNT: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
505    FOLLOWER_METRIC_NETWORKS.map(|network| {
506        register_int_gauge_vec!(
507            format!("{network}_follower_live_rollbacks_follower_count"),
508            "Number of rollbacks synthesized for followers",
509            &FOLLOWER_METRIC_LABELS
510        )
511        .unwrap()
512    })
513});
514
515/// New blocks read from blockchain.
516pub(super) static LIVE_NEW_BLOCKS: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
517    FOLLOWER_METRIC_NETWORKS.map(|network| {
518        register_int_gauge_vec!(
519            format!("{network}_follower_live_new_blocks"),
520            "New blocks read from blockchain",
521            &FOLLOWER_METRIC_LABELS
522        )
523        .unwrap()
524    })
525});
526
527/// Blocks that failed to deserialize from the blockchain.
528pub(super) static LIVE_INVALID_BLOCKS: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
529    FOLLOWER_METRIC_NETWORKS.map(|network| {
530        register_int_gauge_vec!(
531            format!("{network}_follower_live_invalid_blocks"),
532            "Blocks that failed to deserialize from the blockchain",
533            &FOLLOWER_METRIC_LABELS
534        )
535        .unwrap()
536    })
537});
538
539/// Number of active Followers
540pub(super) static LIVE_FOLLOWER_COUNT: LazyLock<[IntGaugeVec; 3]> = LazyLock::new(|| {
541    FOLLOWER_METRIC_NETWORKS.map(|network| {
542        register_int_gauge_vec!(
543            format!("{network}_follower_live_follower_count"),
544            "Number of active Followers",
545            &FOLLOWER_METRIC_LABELS
546        )
547        .unwrap()
548    })
549});