Skip to content

Commit 7c50bd1

Browse files
committed
Bump metrics-exporter-prometheus dependency to 0.18.1
This commit uses the new APIs of the metrics-exporter-prometheues dependency which was bumped to 0.18.1.
1 parent 7c4f487 commit 7c50bd1

File tree

7 files changed

+60
-50
lines changed

7 files changed

+60
-50
lines changed

Cargo.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ jsonptr = "0.7.1"
174174
jsonschema = { version = "0.38.1", default-features = false }
175175
jsonwebtoken = { version = "10.2.0", features = ["aws_lc_rs"] }
176176
metrics = { version = "0.24" }
177-
metrics-exporter-prometheus = { version = "0.17", default-features = false, features = [
177+
metrics-exporter-prometheus = { version = "0.18.1", default-features = false, features = [
178178
"async-runtime",
179179
] }
180180
metrics-util = { version = "0.20.1" }

crates/node/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ derive_more = { workspace = true }
5959
enumset = { workspace = true }
6060
futures = { workspace = true }
6161
http = { workspace = true }
62+
indexmap = { workspace = true }
6263
itertools = { workspace = true }
6364
metrics = { workspace = true }
6465
metrics-exporter-prometheus = { workspace = true }

crates/node/src/network_server/metrics.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,7 @@ pub async fn render_metrics(State(state): State<NodeCtrlHandlerState>) -> String
208208
);
209209

210210
for db in &all_dbs {
211-
labels.push(format!(
212-
"db=\"{}\"",
213-
formatting::sanitize_label_value(db.name())
214-
));
211+
labels.insert("db".to_owned(), formatting::sanitize_label_value(db.name()));
215212

216213
// Tickers (Counters)
217214
for ticker in ROCKSDB_TICKERS {
@@ -274,8 +271,7 @@ pub async fn render_metrics(State(state): State<NodeCtrlHandlerState>) -> String
274271
// Properties (Gauges)
275272
// For properties, we need to get them for each column family.
276273
for cf in &db.cfs() {
277-
let sanitized_cf_name = formatting::sanitize_label_value(cf);
278-
labels.push(format!("cf=\"{sanitized_cf_name}\""));
274+
labels.insert("cf".to_owned(), formatting::sanitize_label_value(cf));
279275
for (property, unit) in ROCKSDB_CF_PROPERTIES {
280276
format_rocksdb_property_for_prometheus(
281277
&mut out,
@@ -288,9 +284,7 @@ pub async fn render_metrics(State(state): State<NodeCtrlHandlerState>) -> String
288284
.unwrap_or_default(),
289285
);
290286
}
291-
labels.pop();
292287
}
293-
labels.pop();
294288
}
295289
out
296290
}

crates/node/src/network_server/prometheus_helpers.rs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010

1111
use std::fmt::Write;
1212

13-
use metrics_exporter_prometheus::formatting;
14-
use restate_rocksdb::RocksDb;
13+
use indexmap::IndexMap;
14+
use metrics::{Key, Unit};
15+
use metrics_exporter_prometheus::{LabelSet, formatting};
1516
use rocksdb::statistics::{HistogramData, Ticker};
1617

18+
use restate_rocksdb::RocksDb;
19+
1720
static PREFIX: &str = "restate";
1821

1922
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
@@ -34,32 +37,33 @@ impl MetricUnit {
3437
MetricUnit::Count => value,
3538
}
3639
}
37-
fn normalized_unit(&self) -> &str {
40+
41+
fn normalized_unit(&self) -> Unit {
3842
match self {
39-
MetricUnit::Micros => "seconds",
40-
MetricUnit::Bytes => "bytes",
41-
MetricUnit::Count => "count",
43+
MetricUnit::Micros => Unit::Seconds,
44+
MetricUnit::Bytes => Unit::Bytes,
45+
MetricUnit::Count => Unit::Count,
4246
}
4347
}
4448
}
4549

4650
pub fn format_rocksdb_stat_ticker_for_prometheus(
4751
out: &mut String,
4852
db: &RocksDb,
49-
labels: &[String],
53+
labels: &IndexMap<String, String>,
5054
ticker: Ticker,
5155
) {
5256
let sanitized_name = format!(
53-
"{}_{}_total",
57+
"{}_{}",
5458
PREFIX,
5559
formatting::sanitize_metric_name(ticker.name())
5660
);
57-
formatting::write_type_line(out, &sanitized_name, "counter");
61+
formatting::write_type_line(out, &sanitized_name, None, Some("total"), "counter");
5862
formatting::write_metric_line::<&str, u64>(
5963
out,
6064
&sanitized_name,
6165
None,
62-
labels,
66+
&LabelSet::from_key_and_global(&Key::from_static_name("non-existent"), labels),
6367
None,
6468
db.get_ticker_count(ticker),
6569
None,
@@ -69,24 +73,29 @@ pub fn format_rocksdb_stat_ticker_for_prometheus(
6973

7074
pub fn format_rocksdb_property_for_prometheus(
7175
out: &mut String,
72-
labels: &[String],
76+
labels: &IndexMap<String, String>,
7377
unit: MetricUnit,
7478
property_name: &str,
7579
property_value: u64,
7680
) {
7781
let sanitized_name = format!(
78-
"{}_{}_{}",
82+
"{}_{}",
7983
PREFIX,
8084
formatting::sanitize_metric_name(property_name),
81-
unit.normalized_unit()
8285
);
8386

84-
formatting::write_type_line(out, &sanitized_name, "gauge");
87+
formatting::write_type_line(
88+
out,
89+
&sanitized_name,
90+
Some(unit.normalized_unit()),
91+
None,
92+
"gauge",
93+
);
8594
formatting::write_metric_line::<&str, u64>(
8695
out,
8796
&sanitized_name,
8897
None,
89-
labels,
98+
&LabelSet::from_key_and_global(&Key::from_static_name("non-existent"), labels),
9099
None,
91100
property_value,
92101
None,
@@ -109,21 +118,23 @@ pub fn format_rocksdb_histogram_for_prometheus(
109118
name: &str,
110119
data: HistogramData,
111120
unit: MetricUnit,
112-
labels: &[String],
121+
labels: &IndexMap<String, String>,
113122
) {
114-
let base_sanitized_name = format!(
115-
"{}_{}_{}",
116-
PREFIX,
117-
formatting::sanitize_metric_name(name),
118-
unit.normalized_unit()
123+
let base_sanitized_name = format!("{}_{}", PREFIX, formatting::sanitize_metric_name(name),);
124+
formatting::write_type_line(
125+
out,
126+
&base_sanitized_name,
127+
Some(unit.normalized_unit()),
128+
None,
129+
"summary",
119130
);
120-
formatting::write_type_line(out, &base_sanitized_name, "summary");
121131

132+
let labels = LabelSet::from_key_and_global(&Key::from_static_name("non-existent"), labels);
122133
formatting::write_metric_line::<&str, f64>(
123134
out,
124135
&base_sanitized_name,
125136
None,
126-
labels,
137+
&labels,
127138
Some(("quantile", "0.5")),
128139
unit.normalize_value(data.median()),
129140
None,
@@ -132,7 +143,7 @@ pub fn format_rocksdb_histogram_for_prometheus(
132143
out,
133144
&base_sanitized_name,
134145
None,
135-
labels,
146+
&labels,
136147
Some(("quantile", "0.95")),
137148
unit.normalize_value(data.p95()),
138149
None,
@@ -141,7 +152,7 @@ pub fn format_rocksdb_histogram_for_prometheus(
141152
out,
142153
&base_sanitized_name,
143154
None,
144-
labels,
155+
&labels,
145156
Some(("quantile", "0.99")),
146157
unit.normalize_value(data.p99()),
147158
None,
@@ -150,7 +161,7 @@ pub fn format_rocksdb_histogram_for_prometheus(
150161
out,
151162
&base_sanitized_name,
152163
None,
153-
labels,
164+
&labels,
154165
Some(("quantile", "1.0")),
155166
unit.normalize_value(data.max()),
156167
None,
@@ -159,7 +170,7 @@ pub fn format_rocksdb_histogram_for_prometheus(
159170
out,
160171
&base_sanitized_name,
161172
Some("sum"),
162-
labels,
173+
&labels,
163174
None,
164175
unit.normalize_value(data.sum() as f64),
165176
None,
@@ -168,7 +179,7 @@ pub fn format_rocksdb_histogram_for_prometheus(
168179
out,
169180
&base_sanitized_name,
170181
Some("count"),
171-
labels,
182+
&labels,
172183
None,
173184
data.count(),
174185
None,

crates/tracing-instrumentation/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ restate-types = { workspace = true }
2727

2828
console-subscriber = { version = "0.5.0", features = ["parking_lot"], optional = true }
2929
http = { workspace = true }
30+
indexmap = { workspace = true }
3031
metrics = { workspace = true, optional = true }
3132
metrics-exporter-prometheus = { workspace = true, optional = true }
3233
metrics-util = { workspace = true, optional = true }

crates/tracing-instrumentation/src/prometheus_metrics.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// the Business Source License, use of this software will be governed
99
// by the Apache License, Version 2.0.
1010

11+
use indexmap::IndexMap;
1112
use metrics_exporter_prometheus::formatting;
1213
use metrics_exporter_prometheus::{PrometheusBuilder, PrometheusHandle};
1314
use tokio::task::AbortHandle;
@@ -20,7 +21,7 @@ use restate_types::config::CommonOptions;
2021
pub struct Prometheus {
2122
handle: Option<PrometheusHandle>,
2223
upkeep_task: Option<AbortHandle>,
23-
global_labels: Vec<String>,
24+
global_labels: IndexMap<String, String>,
2425
}
2526

2627
impl Prometheus {
@@ -34,7 +35,7 @@ impl Prometheus {
3435
return Self {
3536
handle: None,
3637
upkeep_task: None,
37-
global_labels: vec![],
38+
global_labels: IndexMap::default(),
3839
};
3940
}
4041
let builder = PrometheusBuilder::default()
@@ -53,24 +54,24 @@ impl Prometheus {
5354
Self {
5455
handle: Some(prometheus_handle),
5556
upkeep_task: None,
56-
global_labels: vec![
57-
format!(
58-
"cluster_name=\"{}\"",
59-
formatting::sanitize_label_value(opts.cluster_name())
57+
global_labels: IndexMap::from([
58+
(
59+
"cluster_name".to_owned(),
60+
formatting::sanitize_label_value(opts.cluster_name()),
6061
),
61-
format!(
62-
"node_name=\"{}\"",
63-
formatting::sanitize_label_value(opts.node_name())
62+
(
63+
"node_name".to_owned(),
64+
formatting::sanitize_label_value(opts.node_name()),
6465
),
65-
],
66+
]),
6667
}
6768
}
6869

6970
pub fn handle(&self) -> Option<&PrometheusHandle> {
7071
self.handle.as_ref()
7172
}
7273

73-
pub fn global_labels(&self) -> &Vec<String> {
74+
pub fn global_labels(&self) -> &IndexMap<String, String> {
7475
&self.global_labels
7576
}
7677

0 commit comments

Comments
 (0)