sui_core/quorum_driver/
metrics.rs

1// Copyright (c) 2021, Facebook, Inc. and its affiliates
2// Copyright (c) Mysten Labs, Inc.
3// SPDX-License-Identifier: Apache-2.0
4
5use prometheus::{
6    Histogram, HistogramVec, IntCounter, IntCounterVec, IntGauge, Registry,
7    register_histogram_vec_with_registry, register_histogram_with_registry,
8    register_int_counter_vec_with_registry, register_int_counter_with_registry,
9    register_int_gauge_with_registry,
10};
11
12#[derive(Clone)]
13pub struct QuorumDriverMetrics {
14    pub(crate) total_requests: IntCounter,
15    pub(crate) total_enqueued: IntCounter,
16    pub(crate) total_ok_responses: IntCounter,
17    pub(crate) total_err_responses: IntCounterVec,
18    pub(crate) attempt_times_ok_response: Histogram,
19
20    // TODO: add histogram of attempt that tx succeeds
21    pub(crate) current_requests_in_flight: IntGauge,
22
23    pub(crate) total_retryable_overload_errors: IntCounter,
24    pub(crate) transaction_retry_count: Histogram,
25    pub(crate) current_transactions_in_retry: IntGauge,
26
27    pub(crate) settlement_finality_latency: HistogramVec,
28}
29
30impl QuorumDriverMetrics {
31    pub fn new(registry: &Registry) -> Self {
32        Self {
33            total_requests: register_int_counter_with_registry!(
34                "quorum_driver_total_requests",
35                "Total number of requests received",
36                registry,
37            )
38            .unwrap(),
39            total_enqueued: register_int_counter_with_registry!(
40                "quorum_driver_total_enqueued",
41                "Total number of requests enqueued",
42                registry,
43            )
44            .unwrap(),
45            total_ok_responses: register_int_counter_with_registry!(
46                "quorum_driver_total_ok_responses",
47                "Total number of requests processed with Ok responses",
48                registry,
49            )
50            .unwrap(),
51            total_err_responses: register_int_counter_vec_with_registry!(
52                "quorum_driver_total_err_responses",
53                "Total number of requests returned with Err responses, grouped by error type",
54                &["error"],
55                registry,
56            )
57            .unwrap(),
58            attempt_times_ok_response: register_histogram_with_registry!(
59                "quorum_driver_attempt_times_ok_response",
60                "Total attempt times of ok response",
61                mysten_metrics::COUNT_BUCKETS.to_vec(),
62                registry,
63            )
64            .unwrap(),
65            current_requests_in_flight: register_int_gauge_with_registry!(
66                "current_requests_in_flight",
67                "Current number of requests being processed in QuorumDriver",
68                registry,
69            )
70            .unwrap(),
71            total_retryable_overload_errors: register_int_counter_with_registry!(
72                "quorum_driver_total_retryable_overload_errors",
73                "Total number of transactions experiencing retryable overload error",
74                registry,
75            )
76            .unwrap(),
77            transaction_retry_count: register_histogram_with_registry!(
78                "quorum_driver_transaction_retry_count",
79                "Histogram of transaction retry count",
80                mysten_metrics::COUNT_BUCKETS.to_vec(),
81                registry,
82            )
83            .unwrap(),
84            current_transactions_in_retry: register_int_gauge_with_registry!(
85                "current_transactions_in_retry",
86                "Current number of transactions in retry loop in QuorumDriver",
87                registry,
88            )
89            .unwrap(),
90            settlement_finality_latency: register_histogram_vec_with_registry!(
91                "quorum_driver_settlement_finality_latency",
92                "Settlement finality latency observed from quorum driver",
93                &["tx_type"],
94                mysten_metrics::LATENCY_SEC_BUCKETS.to_vec(),
95                registry,
96            )
97            .unwrap(),
98        }
99    }
100
101    pub fn new_for_tests() -> Self {
102        let registry = Registry::new();
103        Self::new(&registry)
104    }
105}