1use prometheus::{
7 Histogram, HistogramVec, IntCounter, IntCounterVec, IntGauge, Registry,
8 register_histogram_vec_with_registry, register_histogram_with_registry,
9 register_int_counter_vec_with_registry, register_int_counter_with_registry,
10 register_int_gauge_with_registry,
11};
12
13const FINALITY_LATENCY_SEC_BUCKETS: &[f64] = &[
14 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85,
15 0.9, 0.95, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6,
16 2.7, 2.8, 2.9, 3.0, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5,
17 7.0, 7.5, 8.0, 8.5, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0,
18 25.0,
19];
20
21#[derive(Clone)]
22pub struct QuorumDriverMetrics {
23 pub(crate) total_requests: IntCounter,
24 pub(crate) total_enqueued: IntCounter,
25 pub(crate) total_ok_responses: IntCounter,
26 pub(crate) total_err_responses: IntCounterVec,
27 pub(crate) attempt_times_ok_response: Histogram,
28
29 pub(crate) current_requests_in_flight: IntGauge,
31
32 pub(crate) total_retryable_overload_errors: IntCounter,
33 pub(crate) transaction_retry_count: Histogram,
34 pub(crate) current_transactions_in_retry: IntGauge,
35
36 pub(crate) settlement_finality_latency: HistogramVec,
37}
38
39impl QuorumDriverMetrics {
40 pub fn new(registry: &Registry) -> Self {
41 Self {
42 total_requests: register_int_counter_with_registry!(
43 "quorum_driver_total_requests",
44 "Total number of requests received",
45 registry,
46 )
47 .unwrap(),
48 total_enqueued: register_int_counter_with_registry!(
49 "quorum_driver_total_enqueued",
50 "Total number of requests enqueued",
51 registry,
52 )
53 .unwrap(),
54 total_ok_responses: register_int_counter_with_registry!(
55 "quorum_driver_total_ok_responses",
56 "Total number of requests processed with Ok responses",
57 registry,
58 )
59 .unwrap(),
60 total_err_responses: register_int_counter_vec_with_registry!(
61 "quorum_driver_total_err_responses",
62 "Total number of requests returned with Err responses, grouped by error type",
63 &["error"],
64 registry,
65 )
66 .unwrap(),
67 attempt_times_ok_response: register_histogram_with_registry!(
68 "quorum_driver_attempt_times_ok_response",
69 "Total attempt times of ok response",
70 iota_metrics::COUNT_BUCKETS.to_vec(),
71 registry,
72 )
73 .unwrap(),
74 current_requests_in_flight: register_int_gauge_with_registry!(
75 "current_requests_in_flight",
76 "Current number of requests being processed in QuorumDriver",
77 registry,
78 )
79 .unwrap(),
80 total_retryable_overload_errors: register_int_counter_with_registry!(
81 "quorum_driver_total_retryable_overload_errors",
82 "Total number of transactions experiencing retryable overload error",
83 registry,
84 )
85 .unwrap(),
86 transaction_retry_count: register_histogram_with_registry!(
87 "quorum_driver_transaction_retry_count",
88 "Histogram of transaction retry count",
89 iota_metrics::COUNT_BUCKETS.to_vec(),
90 registry,
91 )
92 .unwrap(),
93 current_transactions_in_retry: register_int_gauge_with_registry!(
94 "current_transactions_in_retry",
95 "Current number of transactions in retry loop in QuorumDriver",
96 registry,
97 )
98 .unwrap(),
99 settlement_finality_latency: register_histogram_vec_with_registry!(
100 "quorum_driver_settlement_finality_latency",
101 "Settlement finality latency observed from quorum driver",
102 &["tx_type"],
103 FINALITY_LATENCY_SEC_BUCKETS.to_vec(),
104 registry,
105 )
106 .unwrap(),
107 }
108 }
109
110 pub fn new_for_tests() -> Self {
111 let registry = Registry::new();
112 Self::new(®istry)
113 }
114}