sui_types/
metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use prometheus::{
5    Histogram, IntCounterVec, register_histogram_with_registry,
6    register_int_counter_vec_with_registry,
7};
8
9pub struct LimitsMetrics {
10    /// Execution limits metrics
11    pub excessive_estimated_effects_size: IntCounterVec,
12    pub excessive_written_objects_size: IntCounterVec,
13    pub excessive_new_move_object_ids: IntCounterVec,
14    pub excessive_deleted_move_object_ids: IntCounterVec,
15    pub excessive_transferred_move_object_ids: IntCounterVec,
16    pub excessive_object_runtime_cached_objects: IntCounterVec,
17    pub excessive_object_runtime_store_entries: IntCounterVec,
18}
19
20impl LimitsMetrics {
21    pub fn new(registry: &prometheus::Registry) -> LimitsMetrics {
22        Self {
23            excessive_estimated_effects_size: register_int_counter_vec_with_registry!(
24                "excessive_estimated_effects_size",
25                "Number of transactions with estimated effects size exceeding the limit",
26                &["metered", "limit_type"],
27                registry,
28            )
29                .unwrap(),
30            excessive_written_objects_size: register_int_counter_vec_with_registry!(
31                "excessive_written_objects_size",
32                "Number of transactions with written objects size exceeding the limit",
33                &["metered", "limit_type"],
34                registry,
35            )
36                .unwrap(),
37            excessive_new_move_object_ids: register_int_counter_vec_with_registry!(
38                "excessive_new_move_object_ids_size",
39                "Number of transactions with new move object ID count exceeding the limit",
40                &["metered", "limit_type"],
41                registry,
42            )
43                .unwrap(),
44            excessive_deleted_move_object_ids: register_int_counter_vec_with_registry!(
45                "excessive_deleted_move_object_ids_size",
46                "Number of transactions with deleted move object ID count exceeding the limit",
47                &["metered", "limit_type"],
48                registry,
49            )
50                .unwrap(),
51            excessive_transferred_move_object_ids: register_int_counter_vec_with_registry!(
52                "excessive_transferred_move_object_ids_size",
53                "Number of transactions with transferred move object ID count exceeding the limit",
54                &["metered", "limit_type"],
55                registry,
56            )
57                .unwrap(),
58            excessive_object_runtime_cached_objects: register_int_counter_vec_with_registry!(
59                "excessive_object_runtime_cached_objects_size",
60                "Number of transactions with object runtime cached object count exceeding the limit",
61                &["metered", "limit_type"],
62                registry,
63            )
64                .unwrap(),
65            excessive_object_runtime_store_entries: register_int_counter_vec_with_registry!(
66                "excessive_object_runtime_store_entries_size",
67                "Number of transactions with object runtime store entry count exceeding the limit",
68                &["metered", "limit_type"],
69                registry,
70            )
71                .unwrap(),
72        }
73    }
74}
75
76pub struct BytecodeVerifierMetrics {
77    /// Bytecode verifier metrics timeout counter
78    pub verifier_timeout_metrics: IntCounterVec,
79    /// Bytecode verifier runtime latency for each module successfully verified
80    pub verifier_runtime_per_module_success_latency: Histogram,
81    /// Bytecode verifier runtime latency for each programmable transaction block successfully verified
82    pub verifier_runtime_per_ptb_success_latency: Histogram,
83    /// Bytecode verifier runtime latency for each module which timed out
84    pub verifier_runtime_per_module_timeout_latency: Histogram,
85    /// Bytecode verifier runtime latency for each programmable transaction block which timed out
86    pub verifier_runtime_per_ptb_timeout_latency: Histogram,
87}
88
89impl BytecodeVerifierMetrics {
90    /// DEPRECATED in latest metered verifier, which only report overall success or timeout.
91    pub const MOVE_VERIFIER_TAG: &'static str = "move_verifier";
92
93    /// DEPRECATED in latest metered verifier, which only report overall success or timeout.
94    pub const SUI_VERIFIER_TAG: &'static str = "sui_verifier";
95
96    pub const OVERALL_TAG: &'static str = "overall";
97    pub const SUCCESS_TAG: &'static str = "success";
98    pub const TIMEOUT_TAG: &'static str = "failed";
99    const LATENCY_SEC_BUCKETS: &'static [f64] = &[
100        0.000_010, 0.000_025, 0.000_050, 0.000_100, /* sub 100 micros */
101        0.000_250, 0.000_500, 0.001_000, 0.002_500, 0.005_000, 0.010_000, /* sub 10 ms: p99 */
102        0.025_000, 0.050_000, 0.100_000, 0.250_000, 0.500_000, 1.000_000, /* sub 1 s */
103        10.000_000, 20.000_000, 50.000_000, 100.0, /* We should almost never get here */
104    ];
105    pub fn new(registry: &prometheus::Registry) -> Self {
106        Self {
107            verifier_timeout_metrics: register_int_counter_vec_with_registry!(
108                "verifier_timeout_metrics",
109                "Number of timeouts in bytecode verifier",
110                &["verifier_meter", "status"],
111                registry,
112            )
113            .unwrap(),
114            verifier_runtime_per_module_success_latency: register_histogram_with_registry!(
115                "verifier_runtime_per_module_success_latency",
116                "Time spent running bytecode verifier to completion at `run_metered_move_bytecode_verifier_impl`",
117                Self::LATENCY_SEC_BUCKETS.to_vec(),
118                registry
119            )
120            .unwrap(),
121            verifier_runtime_per_ptb_success_latency: register_histogram_with_registry!(
122                "verifier_runtime_per_ptb_success_latency",
123                "Time spent running bytecode verifier to completion over the entire PTB at `transaction_input_checker::check_non_system_packages_to_be_published`",
124                Self::LATENCY_SEC_BUCKETS.to_vec(),
125                registry
126            ).unwrap(),
127            verifier_runtime_per_module_timeout_latency:  register_histogram_with_registry!(
128                "verifier_runtime_per_module_timeout_latency",
129                "Time spent running bytecode verifier to timeout at `run_metered_move_bytecode_verifier_impl`",
130                Self::LATENCY_SEC_BUCKETS.to_vec(),
131                registry
132            )
133            .unwrap(),
134            verifier_runtime_per_ptb_timeout_latency: register_histogram_with_registry!(
135                "verifier_runtime_per_ptb_timeout_latency",
136                "Time spent running bytecode verifier to timeout over the entire PTB at `transaction_input_checker::check_non_system_packages_to_be_published`",
137                Self::LATENCY_SEC_BUCKETS.to_vec(),
138                registry
139            ).unwrap(),
140        }
141    }
142}