iota_types/
metrics.rs

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