Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
palash25 committed Jan 28, 2023
2 parents 29661c0 + 51de116 commit 2ab4ac1
Show file tree
Hide file tree
Showing 25 changed files with 2,134 additions and 1,367 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -49,6 +51,8 @@ jobs:
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -85,6 +89,8 @@ jobs:
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
Expand All @@ -103,6 +109,8 @@ jobs:
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -134,6 +142,8 @@ jobs:
steps:
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
Expand Down
105 changes: 103 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,99 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.19.0] - unreleased
## [0.20.0] [unreleased]

### Added

- Introduce `Collector` abstraction allowing users to provide additional metrics
and their description on each scrape. See [PR 82].

- Introduce a `#[prometheus(flatten)]` attribute which can be used when deriving `EncodeLabelSet`, allowing
a nested struct to be flattened during encoding. See [PR 118].

For example:

```rust
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
struct CommonLabels {
a: u64,
b: u64,
}
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
struct Labels {
unique: u64,
#[prometheus(flatten)]
common: CommonLabels,
}
```

Would be encoded as:

```
my_metric{a="42",b="42",unique="42"} 42
```

[PR 82]: https://github.com/prometheus/client_rust/pull/82
[PR 118]: https://github.com/prometheus/client_rust/pull/118

## [0.19.0]

This is a large release including multiple breaking changes. Major user-facing
improvement of this release is support for the OpenMetrics Protobuf format.

### Upgrade guide:

- Don't box before registering.

```diff
registry.register(
"my_metric",
"This is my metric",
- Box::new(my_metric.clone()),
+ my_metric.clone(),
);
```

- Gauge uses `i64` instead of `u64`.

```diff
my_gauge
- .set(42u64);
+ .set(42i64);
```

- Derive `EncodeLabelSet` for `struct` and `EncodeLabelValue` for `enum` instead of just `Encode` for all and require `Debug`.

```diff
- #[derive(Clone, Hash, PartialEq, Eq, Encode)]
+ #[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
struct Labels {
path: String,
method: Method,
some_number: u64,
}

- #[derive(Clone, Hash, PartialEq, Eq, Encode)]
+ #[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
enum Method {
Get,
#[allow(dead_code)]
Put,
}
```

- Encode as utf-8 and not as `[u8]`.

```diff
- let mut buffer = vec![];
+ let mut buffer = String::new();
encode(&mut buffer, &registry).unwrap();
```

For details on each of these, see changelog entries below.

### Added

- Added support for the OpenMetrics protobuf format. See [PR 83].
- Added a `remove` method to `Family` to allow the removal of a specified label
set from a family. See [PR 85].
Expand All @@ -16,11 +106,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

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

[PR 83]: https://github.com/prometheus/client_rust/pull/83
[PR 85]: https://github.com/prometheus/client_rust/pull/85
[PR 96]: https://github.com/prometheus/client_rust/pull/96
[PR 105]: https://github.com/prometheus/client_rust/pull/105

## [0.18.1]

Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prometheus-client"
version = "0.19.0"
version = "0.20.0"
authors = ["Max Inden <[email protected]>"]
edition = "2021"
description = "Open Metrics client library allowing users to natively instrument applications."
Expand All @@ -11,7 +11,8 @@ homepage = "https://github.com/prometheus/client_rust"
documentation = "https://docs.rs/prometheus-client"

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

[workspace]
members = ["derive-encode"]
Expand All @@ -20,17 +21,16 @@ members = ["derive-encode"]
dtoa = "1.0"
itoa = "1.0"
parking_lot = "0.12"
prometheus-client-derive-encode = { version = "0.3.0", path = "derive-encode" }
prometheus-client-derive-encode = { version = "0.4.1", path = "derive-encode" }
prost = { version = "0.11.0", optional = true }
prost-types = { version = "0.11.0", optional = true }
void = { version = "1.0", optional = true }
quantiles = "0.7.1"

[dev-dependencies]
async-std = { version = "1", features = ["attributes"] }
criterion = "0.4"
http-types = "2"
pyo3 = "0.17"
pyo3 = "0.18"
quickcheck = "1"
rand = "0.8.4"
tide = "0.16"
Expand Down
46 changes: 22 additions & 24 deletions benches/encoding/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,80 @@
// https://github.com/tikv/rust-prometheus/blob/ab1ca7285d3463504381a5025ae1951e020d6796/benches/text_encoder.rs:write

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use prometheus_client::encoding::proto::{encode, EncodeMetric};
use prometheus_client::encoding::Encode;
use prometheus_client::encoding::protobuf;
use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::family::Family;
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
use prometheus_client::registry::Registry;
use std::fmt::{Display, Formatter};
use prometheus_client_derive_encode::{EncodeLabelSet, EncodeLabelValue};

pub fn proto(c: &mut Criterion) {
c.bench_function("encode", |b| {
#[derive(Clone, Hash, PartialEq, Eq, Encode)]
struct Labels {
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
struct CounterLabels {
path: String,
method: Method,
some_number: u64,
}

#[derive(Clone, Hash, PartialEq, Eq, Encode)]
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
enum Method {
Get,
#[allow(dead_code)]
Put,
}

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

#[derive(Clone, Hash, PartialEq, Eq, Encode)]
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
enum Region {
Africa,
#[allow(dead_code)]
Asia,
}

let mut registry = Registry::<Box<dyn EncodeMetric>>::default();
let mut registry = Registry::default();

for i in 0..100 {
let counter_family = Family::<Labels, Counter>::default();
let histogram_family = Family::<Region, Histogram>::new_with_constructor(|| {
Histogram::new(exponential_buckets(1.0, 2.0, 10))
});
let counter_family = Family::<CounterLabels, Counter>::default();
let histogram_family =
Family::<HistogramLabels, Histogram>::new_with_constructor(|| {
Histogram::new(exponential_buckets(1.0, 2.0, 10))
});

registry.register(
format!("my_counter{}", i),
"My counter",
Box::new(counter_family.clone()),
counter_family.clone(),
);
registry.register(
format!("my_histogram{}", i),
"My histogram",
Box::new(histogram_family.clone()),
histogram_family.clone(),
);

for j in 0_u32..100 {
counter_family
.get_or_create(&Labels {
.get_or_create(&CounterLabels {
path: format!("/path/{}", i),
method: Method::Get,
some_number: j.into(),
})
.inc();

histogram_family
.get_or_create(&Region::Africa)
.get_or_create(&HistogramLabels {
region: Region::Africa,
})
.observe(j.into());
}
}

b.iter(|| {
let metric_set = encode(&registry);
let metric_set = protobuf::encode(&registry).unwrap();
black_box(metric_set);
})
});
Expand Down
Loading

0 comments on commit 2ab4ac1

Please sign in to comment.