1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
use polkadot_node_subsystem_util::metrics::{
self,
prometheus::{self, Counter, CounterVec, Histogram, Opts, PrometheusError, Registry, U64},
};
#[derive(Clone, Default)]
pub struct Metrics(Option<MetricsInner>);
#[derive(Clone)]
struct MetricsInner {
chunk_requests_issued: Counter<U64>,
chunk_requests_finished: CounterVec<U64>,
time_chunk_request: Histogram,
time_erasure_recovery: Histogram,
time_full_recovery: Histogram,
full_recoveries_finished: CounterVec<U64>,
full_recoveries_started: Counter<U64>,
}
impl Metrics {
pub fn new_dummy() -> Self {
Metrics(None)
}
pub fn on_chunk_request_issued(&self) {
if let Some(metrics) = &self.0 {
metrics.chunk_requests_issued.inc()
}
}
pub fn on_chunk_request_timeout(&self) {
if let Some(metrics) = &self.0 {
metrics.chunk_requests_finished.with_label_values(&["timeout"]).inc()
}
}
pub fn on_chunk_request_no_such_chunk(&self) {
if let Some(metrics) = &self.0 {
metrics.chunk_requests_finished.with_label_values(&["no_such_chunk"]).inc()
}
}
pub fn on_chunk_request_error(&self) {
if let Some(metrics) = &self.0 {
metrics.chunk_requests_finished.with_label_values(&["error"]).inc()
}
}
pub fn on_chunk_request_invalid(&self) {
if let Some(metrics) = &self.0 {
metrics.chunk_requests_finished.with_label_values(&["invalid"]).inc()
}
}
pub fn on_chunk_request_succeeded(&self) {
if let Some(metrics) = &self.0 {
metrics.chunk_requests_finished.with_label_values(&["success"]).inc()
}
}
pub fn time_chunk_request(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.time_chunk_request.start_timer())
}
pub fn time_erasure_recovery(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.time_erasure_recovery.start_timer())
}
pub fn time_full_recovery(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
self.0.as_ref().map(|metrics| metrics.time_full_recovery.start_timer())
}
pub fn on_recovery_succeeded(&self) {
if let Some(metrics) = &self.0 {
metrics.full_recoveries_finished.with_label_values(&["success"]).inc()
}
}
pub fn on_recovery_failed(&self) {
if let Some(metrics) = &self.0 {
metrics.full_recoveries_finished.with_label_values(&["failure"]).inc()
}
}
pub fn on_recovery_invalid(&self) {
if let Some(metrics) = &self.0 {
metrics.full_recoveries_finished.with_label_values(&["invalid"]).inc()
}
}
pub fn on_recovery_started(&self) {
if let Some(metrics) = &self.0 {
metrics.full_recoveries_started.inc()
}
}
}
impl metrics::Metrics for Metrics {
fn try_register(registry: &Registry) -> Result<Self, PrometheusError> {
let metrics = MetricsInner {
chunk_requests_issued: prometheus::register(
Counter::new(
"polkadot_parachain_availability_recovery_chunk_requests_issued",
"Total number of issued chunk requests.",
)?,
registry,
)?,
chunk_requests_finished: prometheus::register(
CounterVec::new(
Opts::new(
"polkadot_parachain_availability_recovery_chunk_requests_finished",
"Total number of chunk requests finished.",
),
&["result"],
)?,
registry,
)?,
time_chunk_request: prometheus::register(
prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
"polkadot_parachain_availability_recovery_time_chunk_request",
"Time spent waiting for a response to a chunk request",
))?,
registry,
)?,
time_erasure_recovery: prometheus::register(
prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
"polkadot_parachain_availability_recovery_time_erasure_recovery",
"Time spent to recover the erasure code and verify the merkle root by re-encoding as erasure chunks",
))?,
registry,
)?,
time_full_recovery: prometheus::register(
prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
"polkadot_parachain_availability_recovery_time_total",
"Time a full recovery process took, either until failure or successful erasure decoding.",
))?,
registry,
)?,
full_recoveries_finished: prometheus::register(
CounterVec::new(
Opts::new(
"polkadot_parachain_availability_recovery_recoveries_finished",
"Total number of recoveries that finished.",
),
&["result"],
)?,
registry,
)?,
full_recoveries_started: prometheus::register(
Counter::new(
"polkadot_parachain_availability_recovery_recovieries_started",
"Total number of started recoveries.",
)?,
registry,
)?,
};
Ok(Metrics(Some(metrics)))
}
}