1#[cfg(not(target_arch = "wasm32"))]
6use prometheus_filtered::{
7 Histogram, IntCounterVec, register_histogram_with_registry,
8 register_int_counter_vec_with_registry,
9};
10
11#[cfg(not(target_arch = "wasm32"))]
12pub struct LimitsMetrics {
13 pub excessive_estimated_effects_size: IntCounterVec,
15 pub excessive_written_objects_size: IntCounterVec,
16 pub excessive_new_move_object_ids: IntCounterVec,
17 pub excessive_deleted_move_object_ids: IntCounterVec,
18 pub excessive_transferred_move_object_ids: IntCounterVec,
19 pub excessive_object_runtime_cached_objects: IntCounterVec,
20 pub excessive_object_runtime_store_entries: IntCounterVec,
21 pub excessive_move_call_argument_nodes: IntCounterVec,
22 pub move_call_argument_nodes: Histogram,
23}
24
25#[cfg(not(target_arch = "wasm32"))]
26impl LimitsMetrics {
27 const MOVE_CALL_ARGUMENT_NODES_BUCKETS: &'static [f64] = &[
28 1.0, 4.0, 16.0, 64.0, 256.0, 1024.0, 4096.0, 16384.0, 65536.0, 262144.0, 1048576.0,
29 2097152.0,
30 ];
31
32 pub fn new(registry: &prometheus_filtered::Registry) -> LimitsMetrics {
33 Self {
34 excessive_estimated_effects_size: register_int_counter_vec_with_registry!(
35 "excessive_estimated_effects_size",
36 "Number of transactions with estimated effects size exceeding the limit",
37 &["metered", "limit_type"],
38 registry,
39 )
40 .unwrap(),
41 excessive_written_objects_size: register_int_counter_vec_with_registry!(
42 "excessive_written_objects_size",
43 "Number of transactions with written objects size exceeding the limit",
44 &["metered", "limit_type"],
45 registry,
46 )
47 .unwrap(),
48 excessive_new_move_object_ids: register_int_counter_vec_with_registry!(
49 "excessive_new_move_object_ids_size",
50 "Number of transactions with new move object ID count exceeding the limit",
51 &["metered", "limit_type"],
52 registry,
53 )
54 .unwrap(),
55 excessive_deleted_move_object_ids: register_int_counter_vec_with_registry!(
56 "excessive_deleted_move_object_ids_size",
57 "Number of transactions with deleted move object ID count exceeding the limit",
58 &["metered", "limit_type"],
59 registry,
60 )
61 .unwrap(),
62 excessive_transferred_move_object_ids: register_int_counter_vec_with_registry!(
63 "excessive_transferred_move_object_ids_size",
64 "Number of transactions with transferred move object ID count exceeding the limit",
65 &["metered", "limit_type"],
66 registry,
67 )
68 .unwrap(),
69 excessive_object_runtime_cached_objects: register_int_counter_vec_with_registry!(
70 "excessive_object_runtime_cached_objects_size",
71 "Number of transactions with object runtime cached object count exceeding the limit",
72 &["metered", "limit_type"],
73 registry,
74 )
75 .unwrap(),
76 excessive_object_runtime_store_entries: register_int_counter_vec_with_registry!(
77 "excessive_object_runtime_store_entries_size",
78 "Number of transactions with object runtime store entry count exceeding the limit",
79 &["metered", "limit_type"],
80 registry,
81 )
82 .unwrap(),
83 excessive_move_call_argument_nodes: register_int_counter_vec_with_registry!(
84 "excessive_move_call_argument_nodes",
85 "Number of Move calls whose arguments exceed the per-call or per-transaction value limit",
86 &["limit_type"],
87 registry,
88 )
89 .unwrap(),
90 move_call_argument_nodes: register_histogram_with_registry!(
91 "move_call_argument_nodes",
92 "Struct, enum and vector values in the arguments of one Move call",
93 Self::MOVE_CALL_ARGUMENT_NODES_BUCKETS.to_vec(),
94 registry,
95 )
96 .unwrap(),
97 }
98 }
99}
100
101#[cfg(not(target_arch = "wasm32"))]
102pub struct BytecodeVerifierMetrics {
103 pub verifier_timeout_metrics: IntCounterVec,
105 pub verifier_runtime_per_module_success_latency: Histogram,
107 pub verifier_runtime_per_ptb_success_latency: Histogram,
110 pub verifier_runtime_per_module_timeout_latency: Histogram,
112 pub verifier_runtime_per_ptb_timeout_latency: Histogram,
115}
116
117#[cfg(not(target_arch = "wasm32"))]
118impl BytecodeVerifierMetrics {
119 pub const OVERALL_TAG: &'static str = "overall";
120 pub const SUCCESS_TAG: &'static str = "success";
121 pub const TIMEOUT_TAG: &'static str = "failed";
122 const LATENCY_SEC_BUCKETS: &'static [f64] = &[
123 0.000_010, 0.000_025, 0.000_050, 0.000_100, 0.000_250, 0.000_500, 0.001_000, 0.002_500, 0.005_000, 0.010_000, 0.025_000, 0.050_000, 0.100_000, 0.250_000, 0.500_000, 1.000_000, 10.000_000, 20.000_000, 50.000_000, 100.0, ];
128 pub fn new(registry: &prometheus_filtered::Registry) -> Self {
129 Self {
130 verifier_timeout_metrics: register_int_counter_vec_with_registry!(
131 "verifier_timeout_metrics",
132 "Number of timeouts in bytecode verifier",
133 &["verifier_meter", "status"],
134 registry,
135 )
136 .unwrap(),
137 verifier_runtime_per_module_success_latency: register_histogram_with_registry!(
138 "verifier_runtime_per_module_success_latency",
139 "Time spent running bytecode verifier to completion at `run_metered_move_bytecode_verifier_impl`",
140 Self::LATENCY_SEC_BUCKETS.to_vec(),
141 registry
142 )
143 .unwrap(),
144 verifier_runtime_per_ptb_success_latency: register_histogram_with_registry!(
145 "verifier_runtime_per_ptb_success_latency",
146 "Time spent running bytecode verifier to completion over the entire PTB at `transaction_input_checker::check_non_system_packages_to_be_published`",
147 Self::LATENCY_SEC_BUCKETS.to_vec(),
148 registry
149 ).unwrap(),
150 verifier_runtime_per_module_timeout_latency: register_histogram_with_registry!(
151 "verifier_runtime_per_module_timeout_latency",
152 "Time spent running bytecode verifier to timeout at `run_metered_move_bytecode_verifier_impl`",
153 Self::LATENCY_SEC_BUCKETS.to_vec(),
154 registry
155 )
156 .unwrap(),
157 verifier_runtime_per_ptb_timeout_latency: register_histogram_with_registry!(
158 "verifier_runtime_per_ptb_timeout_latency",
159 "Time spent running bytecode verifier to timeout over the entire PTB at `transaction_input_checker::check_non_system_packages_to_be_published`",
160 Self::LATENCY_SEC_BUCKETS.to_vec(),
161 registry
162 ).unwrap(),
163 }
164 }
165}
166
167#[cfg(target_arch = "wasm32")]
170mod wasm_stubs {
171 #[derive(Default, Clone)]
172 pub struct StubCounter;
173 impl StubCounter {
174 pub fn inc(&self) {}
175 pub fn inc_by(&self, _v: u64) {}
176 }
177
178 #[derive(Default, Clone)]
179 pub struct StubCounterVec;
180 impl StubCounterVec {
181 pub fn with_label_values(&self, _labels: &[&str]) -> StubCounter {
182 StubCounter
183 }
184 }
185
186 pub struct StubTimer;
187 impl StubTimer {
188 pub fn observe_duration(self) {}
189 pub fn stop_and_record(self) -> f64 {
190 0.0
191 }
192 pub fn stop_and_discard(self) -> f64 {
193 0.0
194 }
195 }
196
197 #[derive(Default, Clone)]
198 pub struct StubHistogram;
199 impl StubHistogram {
200 pub fn observe(&self, _v: f64) {}
201 pub fn start_timer(&self) -> StubTimer {
202 StubTimer
203 }
204 }
205
206 pub struct LimitsMetrics {
207 pub excessive_estimated_effects_size: StubCounterVec,
208 pub excessive_written_objects_size: StubCounterVec,
209 pub excessive_new_move_object_ids: StubCounterVec,
210 pub excessive_deleted_move_object_ids: StubCounterVec,
211 pub excessive_transferred_move_object_ids: StubCounterVec,
212 pub excessive_object_runtime_cached_objects: StubCounterVec,
213 pub excessive_object_runtime_store_entries: StubCounterVec,
214 pub excessive_move_call_argument_nodes: StubCounterVec,
215 pub move_call_argument_nodes: StubHistogram,
216 }
217
218 impl LimitsMetrics {
219 pub fn new_stub() -> Self {
220 Self {
221 excessive_estimated_effects_size: StubCounterVec,
222 excessive_written_objects_size: StubCounterVec,
223 excessive_new_move_object_ids: StubCounterVec,
224 excessive_deleted_move_object_ids: StubCounterVec,
225 excessive_transferred_move_object_ids: StubCounterVec,
226 excessive_object_runtime_cached_objects: StubCounterVec,
227 excessive_object_runtime_store_entries: StubCounterVec,
228 excessive_move_call_argument_nodes: StubCounterVec,
229 move_call_argument_nodes: StubHistogram,
230 }
231 }
232 }
233
234 pub struct BytecodeVerifierMetrics {
235 pub verifier_timeout_metrics: StubCounterVec,
236 pub verifier_runtime_per_module_success_latency: StubHistogram,
237 pub verifier_runtime_per_ptb_success_latency: StubHistogram,
238 pub verifier_runtime_per_module_timeout_latency: StubHistogram,
239 pub verifier_runtime_per_ptb_timeout_latency: StubHistogram,
240 }
241
242 impl BytecodeVerifierMetrics {
243 pub const OVERALL_TAG: &'static str = "overall";
244 pub const SUCCESS_TAG: &'static str = "success";
245 pub const TIMEOUT_TAG: &'static str = "failed";
246
247 pub fn new_stub() -> Self {
248 Self {
249 verifier_timeout_metrics: StubCounterVec,
250 verifier_runtime_per_module_success_latency: StubHistogram,
251 verifier_runtime_per_ptb_success_latency: StubHistogram,
252 verifier_runtime_per_module_timeout_latency: StubHistogram,
253 verifier_runtime_per_ptb_timeout_latency: StubHistogram,
254 }
255 }
256 }
257}
258
259#[cfg(target_arch = "wasm32")]
260pub use wasm_stubs::*;