Skip to content

Commit 2ab4ac1

Browse files
committed
Fix conflicts
2 parents 29661c0 + 51de116 commit 2ab4ac1

25 files changed

+2134
-1367
lines changed

.github/workflows/rust.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
steps:
1010
- name: Install Protoc
1111
uses: arduino/setup-protoc@v1
12+
with:
13+
repo-token: ${{ secrets.GITHUB_TOKEN }}
1214
- uses: actions/checkout@v2
1315
- uses: actions-rs/toolchain@v1
1416
with:
@@ -49,6 +51,8 @@ jobs:
4951
steps:
5052
- name: Install Protoc
5153
uses: arduino/setup-protoc@v1
54+
with:
55+
repo-token: ${{ secrets.GITHUB_TOKEN }}
5256
- uses: actions/checkout@v2
5357
- uses: actions-rs/toolchain@v1
5458
with:
@@ -85,6 +89,8 @@ jobs:
8589
steps:
8690
- name: Install Protoc
8791
uses: arduino/setup-protoc@v1
92+
with:
93+
repo-token: ${{ secrets.GITHUB_TOKEN }}
8894
- uses: actions/checkout@v2
8995
- uses: actions-rs/toolchain@v1
9096
with:
@@ -103,6 +109,8 @@ jobs:
103109
steps:
104110
- name: Install Protoc
105111
uses: arduino/setup-protoc@v1
112+
with:
113+
repo-token: ${{ secrets.GITHUB_TOKEN }}
106114
- uses: actions/checkout@v2
107115
- uses: actions-rs/toolchain@v1
108116
with:
@@ -134,6 +142,8 @@ jobs:
134142
steps:
135143
- name: Install Protoc
136144
uses: arduino/setup-protoc@v1
145+
with:
146+
repo-token: ${{ secrets.GITHUB_TOKEN }}
137147
- uses: actions/checkout@v2
138148
- uses: actions-rs/toolchain@v1
139149
with:

CHANGELOG.md

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,99 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [0.19.0] - unreleased
7+
## [0.20.0] [unreleased]
88

99
### Added
10+
11+
- Introduce `Collector` abstraction allowing users to provide additional metrics
12+
and their description on each scrape. See [PR 82].
13+
14+
- Introduce a `#[prometheus(flatten)]` attribute which can be used when deriving `EncodeLabelSet`, allowing
15+
a nested struct to be flattened during encoding. See [PR 118].
16+
17+
For example:
18+
19+
```rust
20+
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
21+
struct CommonLabels {
22+
a: u64,
23+
b: u64,
24+
}
25+
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
26+
struct Labels {
27+
unique: u64,
28+
#[prometheus(flatten)]
29+
common: CommonLabels,
30+
}
31+
```
32+
33+
Would be encoded as:
34+
35+
```
36+
my_metric{a="42",b="42",unique="42"} 42
37+
```
38+
39+
[PR 82]: https://github.com/prometheus/client_rust/pull/82
40+
[PR 118]: https://github.com/prometheus/client_rust/pull/118
41+
42+
## [0.19.0]
43+
44+
This is a large release including multiple breaking changes. Major user-facing
45+
improvement of this release is support for the OpenMetrics Protobuf format.
46+
47+
### Upgrade guide:
48+
49+
- Don't box before registering.
50+
51+
```diff
52+
registry.register(
53+
"my_metric",
54+
"This is my metric",
55+
- Box::new(my_metric.clone()),
56+
+ my_metric.clone(),
57+
);
58+
```
59+
60+
- Gauge uses `i64` instead of `u64`.
61+
62+
```diff
63+
my_gauge
64+
- .set(42u64);
65+
+ .set(42i64);
66+
```
67+
68+
- Derive `EncodeLabelSet` for `struct` and `EncodeLabelValue` for `enum` instead of just `Encode` for all and require `Debug`.
69+
70+
```diff
71+
- #[derive(Clone, Hash, PartialEq, Eq, Encode)]
72+
+ #[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
73+
struct Labels {
74+
path: String,
75+
method: Method,
76+
some_number: u64,
77+
}
78+
79+
- #[derive(Clone, Hash, PartialEq, Eq, Encode)]
80+
+ #[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
81+
enum Method {
82+
Get,
83+
#[allow(dead_code)]
84+
Put,
85+
}
86+
```
87+
88+
- Encode as utf-8 and not as `[u8]`.
89+
90+
```diff
91+
- let mut buffer = vec![];
92+
+ let mut buffer = String::new();
93+
encode(&mut buffer, &registry).unwrap();
94+
```
95+
96+
For details on each of these, see changelog entries below.
97+
98+
### Added
99+
10100
- Added support for the OpenMetrics protobuf format. See [PR 83].
11101
- Added a `remove` method to `Family` to allow the removal of a specified label
12102
set from a family. See [PR 85].
@@ -16,11 +106,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16106

17107
### Changed
18108

19-
- Move`Encode` trait from `prometheus_client::encoding::text` to `prometheus_client::encoding`. See [PR 83].
109+
- Always use dynamic dispatch on `Registry`, i.e. remove generic type parameter `M` from `Registry`. See [PR 105].
110+
- Refactor encoding. See [PR 105].
111+
- Introducing separate traits to encode
112+
- value (e.g. `EncodeCounterValue`)
113+
- label set (`EncodeLabelSet`), derivable for structs via `prometheus-client-derive-encode`
114+
- label (`EncodeLabel`)
115+
- label key (`EncodeLabelKey`)
116+
- label value (`EncodeLabelValue`), derivable for enums via `prometheus-client-derive-encode`
117+
- Encode as UTF-8 strings, not bytes. I.e. use `std::fmt::Write` instead of `std::io::Write`.
118+
- Use signed integers for `Gauge` for compliance with OpenMetrics protobuf
119+
format. See [PR 105].
20120

21121
[PR 83]: https://github.com/prometheus/client_rust/pull/83
22122
[PR 85]: https://github.com/prometheus/client_rust/pull/85
23123
[PR 96]: https://github.com/prometheus/client_rust/pull/96
124+
[PR 105]: https://github.com/prometheus/client_rust/pull/105
24125

25126
## [0.18.1]
26127

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "prometheus-client"
3-
version = "0.19.0"
3+
version = "0.20.0"
44
authors = ["Max Inden <[email protected]>"]
55
edition = "2021"
66
description = "Open Metrics client library allowing users to natively instrument applications."
@@ -11,7 +11,8 @@ homepage = "https://github.com/prometheus/client_rust"
1111
documentation = "https://docs.rs/prometheus-client"
1212

1313
[features]
14-
protobuf = ["dep:prost", "dep:prost-types", "dep:prost-build", "dep:void", "prometheus-client-derive-encode/protobuf"]
14+
default = []
15+
protobuf = ["dep:prost", "dep:prost-types", "dep:prost-build"]
1516

1617
[workspace]
1718
members = ["derive-encode"]
@@ -20,17 +21,16 @@ members = ["derive-encode"]
2021
dtoa = "1.0"
2122
itoa = "1.0"
2223
parking_lot = "0.12"
23-
prometheus-client-derive-encode = { version = "0.3.0", path = "derive-encode" }
24+
prometheus-client-derive-encode = { version = "0.4.1", path = "derive-encode" }
2425
prost = { version = "0.11.0", optional = true }
2526
prost-types = { version = "0.11.0", optional = true }
26-
void = { version = "1.0", optional = true }
2727
quantiles = "0.7.1"
2828

2929
[dev-dependencies]
3030
async-std = { version = "1", features = ["attributes"] }
3131
criterion = "0.4"
3232
http-types = "2"
33-
pyo3 = "0.17"
33+
pyo3 = "0.18"
3434
quickcheck = "1"
3535
rand = "0.8.4"
3636
tide = "0.16"

benches/encoding/proto.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,82 +2,80 @@
22
// https://github.com/tikv/rust-prometheus/blob/ab1ca7285d3463504381a5025ae1951e020d6796/benches/text_encoder.rs:write
33

44
use criterion::{black_box, criterion_group, criterion_main, Criterion};
5-
use prometheus_client::encoding::proto::{encode, EncodeMetric};
6-
use prometheus_client::encoding::Encode;
5+
use prometheus_client::encoding::protobuf;
76
use prometheus_client::metrics::counter::Counter;
87
use prometheus_client::metrics::family::Family;
98
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
109
use prometheus_client::registry::Registry;
11-
use std::fmt::{Display, Formatter};
10+
use prometheus_client_derive_encode::{EncodeLabelSet, EncodeLabelValue};
1211

1312
pub fn proto(c: &mut Criterion) {
1413
c.bench_function("encode", |b| {
15-
#[derive(Clone, Hash, PartialEq, Eq, Encode)]
16-
struct Labels {
14+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
15+
struct CounterLabels {
1716
path: String,
1817
method: Method,
1918
some_number: u64,
2019
}
2120

22-
#[derive(Clone, Hash, PartialEq, Eq, Encode)]
21+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
2322
enum Method {
2423
Get,
2524
#[allow(dead_code)]
2625
Put,
2726
}
2827

29-
impl Display for Method {
30-
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31-
match self {
32-
Method::Get => write!(f, "Get"),
33-
Method::Put => write!(f, "Put"),
34-
}
35-
}
28+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
29+
struct HistogramLabels {
30+
region: Region,
3631
}
3732

38-
#[derive(Clone, Hash, PartialEq, Eq, Encode)]
33+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
3934
enum Region {
4035
Africa,
4136
#[allow(dead_code)]
4237
Asia,
4338
}
4439

45-
let mut registry = Registry::<Box<dyn EncodeMetric>>::default();
40+
let mut registry = Registry::default();
4641

4742
for i in 0..100 {
48-
let counter_family = Family::<Labels, Counter>::default();
49-
let histogram_family = Family::<Region, Histogram>::new_with_constructor(|| {
50-
Histogram::new(exponential_buckets(1.0, 2.0, 10))
51-
});
43+
let counter_family = Family::<CounterLabels, Counter>::default();
44+
let histogram_family =
45+
Family::<HistogramLabels, Histogram>::new_with_constructor(|| {
46+
Histogram::new(exponential_buckets(1.0, 2.0, 10))
47+
});
5248

5349
registry.register(
5450
format!("my_counter{}", i),
5551
"My counter",
56-
Box::new(counter_family.clone()),
52+
counter_family.clone(),
5753
);
5854
registry.register(
5955
format!("my_histogram{}", i),
6056
"My histogram",
61-
Box::new(histogram_family.clone()),
57+
histogram_family.clone(),
6258
);
6359

6460
for j in 0_u32..100 {
6561
counter_family
66-
.get_or_create(&Labels {
62+
.get_or_create(&CounterLabels {
6763
path: format!("/path/{}", i),
6864
method: Method::Get,
6965
some_number: j.into(),
7066
})
7167
.inc();
7268

7369
histogram_family
74-
.get_or_create(&Region::Africa)
70+
.get_or_create(&HistogramLabels {
71+
region: Region::Africa,
72+
})
7573
.observe(j.into());
7674
}
7775
}
7876

7977
b.iter(|| {
80-
let metric_set = encode(&registry);
78+
let metric_set = protobuf::encode(&registry).unwrap();
8179
black_box(metric_set);
8280
})
8381
});

0 commit comments

Comments
 (0)