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
use parity_scale_codec::{Decode, Encode};
use sp_std::prelude::*;
#[derive(Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub enum RuntimeMetricOp {
IncrementCounterVec(u64, RuntimeMetricLabelValues),
IncrementCounter(u64),
}
#[derive(Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct RuntimeMetricUpdate {
pub metric_name: Vec<u8>,
pub op: RuntimeMetricOp,
}
fn vec_to_str<'a>(v: &'a Vec<u8>, default: &'static str) -> &'a str {
return sp_std::str::from_utf8(v).unwrap_or(default)
}
impl RuntimeMetricLabels {
pub fn as_str_vec(&self) -> Vec<&str> {
self.0
.iter()
.map(|label_vec| vec_to_str(&label_vec.0, "invalid_label"))
.collect()
}
pub fn clear(&mut self) {
self.0.clear();
}
}
impl From<&[&'static str]> for RuntimeMetricLabels {
fn from(v: &[&'static str]) -> RuntimeMetricLabels {
RuntimeMetricLabels(
v.iter().map(|label| RuntimeMetricLabel(label.as_bytes().to_vec())).collect(),
)
}
}
impl RuntimeMetricUpdate {
pub fn metric_name(&self) -> &str {
vec_to_str(&self.metric_name, "invalid_metric_name")
}
}
#[derive(Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct RuntimeMetricLabels(Vec<RuntimeMetricLabel>);
#[derive(Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct RuntimeMetricLabel(Vec<u8>);
pub type RuntimeMetricLabelValue = RuntimeMetricLabel;
pub type RuntimeMetricLabelValues = RuntimeMetricLabels;
pub trait AsStr {
fn as_str(&self) -> Option<&str>;
}
impl AsStr for RuntimeMetricLabel {
fn as_str(&self) -> Option<&str> {
sp_std::str::from_utf8(&self.0).ok()
}
}
impl From<&'static str> for RuntimeMetricLabel {
fn from(s: &'static str) -> Self {
Self(s.as_bytes().to_vec())
}
}
pub mod metric_definitions {
pub struct CounterDefinition {
pub name: &'static str,
pub description: &'static str,
}
pub struct CounterVecDefinition<'a> {
pub name: &'static str,
pub description: &'static str,
pub labels: &'a [&'static str],
}
pub const PARACHAIN_INHERENT_DATA_WEIGHT: CounterVecDefinition = CounterVecDefinition {
name: "polkadot_parachain_inherent_data_weight",
description: "Inherent data weight before and after filtering",
labels: &["when"],
};
pub const PARACHAIN_INHERENT_DATA_BITFIELDS_PROCESSED: CounterDefinition = CounterDefinition {
name: "polkadot_parachain_inherent_data_bitfields_processed",
description: "Counts the number of bitfields processed in `enter_inner`.",
};
pub const PARACHAIN_INHERENT_DATA_CANDIDATES_PROCESSED: CounterVecDefinition =
CounterVecDefinition {
name: "polkadot_parachain_inherent_data_candidates_processed",
description:
"Counts the number of parachain block candidates processed in `enter_inner`.",
labels: &["category"],
};
pub const PARACHAIN_INHERENT_DATA_DISPUTE_SETS_PROCESSED: CounterVecDefinition =
CounterVecDefinition {
name: "polkadot_parachain_inherent_data_dispute_sets_processed",
description: "Counts the number of dispute statements sets processed in `enter_inner`.",
labels: &["category"],
};
pub const PARACHAIN_INHERENT_DATA_DISPUTE_SETS_INCLUDED: CounterDefinition =
CounterDefinition {
name: "polkadot_parachain_inherent_data_dispute_sets_included",
description:
"Counts the number of dispute statements sets included in a block in `enter_inner`.",
};
pub const PARACHAIN_CREATE_INHERENT_BITFIELDS_SIGNATURE_CHECKS: CounterVecDefinition =
CounterVecDefinition {
name: "polkadot_parachain_create_inherent_bitfields_signature_checks",
description: "Counts the number of bitfields signature checked in `enter_inner`.",
labels: &["validity"],
};
}