-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protobuf support #83
Merged
Merged
Protobuf support #83
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
b78dbaf
Rough implementation to encode Counter
ackintosh e2e96f9
src/encoding/proto: Construct Registry with proto::EncodeMetric
mxinden abb66df
src/encoding/proto: Implement encoding for labels
ackintosh 33b527f
src/encoding/proto: Implement encoding for CounterWithExemplar
ackintosh a3e6afc
Move comment
ackintosh c3bb963
src/encoding/proto: Implement encoding for Gauge
ackintosh d29e2d3
src/encoding/proto: Implement encoding for Histogram
ackintosh 18ca645
src/encoding/proto: Tweak function name according to encoding::text
ackintosh 9c97af5
src/encoding/proto: Implement encoding for HistogramWithExemplars
ackintosh ca45f64
src/encoding/proto: Move function for readability
ackintosh d76e7a0
src/encoding/proto: Implement encoding for Info
ackintosh 4b31a21
src/encoding/proto: Add tests for Counter
ackintosh 571c707
src/encoding/proto: Add assertions for MetricType
ackintosh 84a0745
src/encoding/proto: DRY-ed tests with `extract_metric_point_value`
ackintosh 90d8b00
src/encoding/proto: Assert name and help
ackintosh 03fc057
src/encoding/proto: Refactor: use associated constants
ackintosh 745160c
src/encoding/proto: Add assertions for counter.exemplar
ackintosh 4b839c9
src/encoding/proto: Add assertion for Unit
ackintosh 202d457
src/encoding/proto: Refactoring: extract a method `Unit::as_str()`
ackintosh 2e7e35a
src/encoding/proto: Remove superfluous comments
ackintosh bd90dc3
src/encoding/proto: Add tests for Family
ackintosh c1b38a2
src/encoding/proto: Remove redundant test
ackintosh 92b4493
src/encoding/proto: Add doc
ackintosh 3cfe085
Introduce `protobuf` feature
ackintosh ee6344a
src/encoding/proto: Refactoring for loop
ackintosh cc0df24
Implement proc macro `EncodeProtobuf`
ackintosh 7040f2a
Add impl EncodeGaugeValue for u64
ackintosh 6cf6e09
Try Associated Type
ackintosh 887beff
Fix life parameter issue
ackintosh 49a3dfb
Make EncodeLabel::encode return iterator
ackintosh 3b8dc35
src/encoding/proto: Refactor EncodeLabel and EncodeMetric
mxinden f07148b
Fix assertions because of changes of the order of result
ackintosh 0583a66
Remove unnecessary lifetime parameter
ackintosh 88fe41e
Rename EncodeLabel -> EncodeLabels
ackintosh e5a37a3
Using `Void` to indicate the impossible case
ackintosh 7d2c6a0
Changed proc macro accordingly since `encode` returns iterator
ackintosh 2e55b46
Rename the proc macro since the name was a bit redundant
ackintosh 83a0b89
Add a test for Family (counter and histogram)
ackintosh 00dcdd1
Add benchmark code for proto encoding
ackintosh f20ae6b
Add a test for Family, Counter and Histogram
ackintosh 50ca0a9
Remove `Box` to reduce allocation count
ackintosh 6afc9b7
Use std::iter::Once on enums as enum returns single element
ackintosh 289241c
encoding/proto: Pass metric and label vec
mxinden dd69b89
derive-proto-encode: Update according to the changes in encoding/proto
ackintosh 2f8d1a3
Cargo.toml: Make `void` optional
ackintosh 547e1b4
benches: Update according to the changes in encoding/proto
ackintosh f8c621a
encoding/proto: same implementation to slice
ackintosh 2d169ad
Bump the crate version and add a changelog entry
ackintosh 4b7c75f
Add --all-features
ackintosh 48745c4
Remove unnecessary generic parameter
ackintosh f367ebf
Merge derive-proto-encode into derive-text-encode
ackintosh 870cdae
`protobuf` feature requires Display
ackintosh 26ec648
Rename `prometheus-client-derive-text-encode` to `prometheus-client-d…
ackintosh 2fb5f1f
derive-encode: Bump up patch version because of adding protobuf feature
ackintosh 1d70145
Merge branch 'master' into protobuf
ackintosh 15dc7a7
Fix missing docs
ackintosh bb08122
Fix clippy warnings: field assignment outside of initializer for an i…
ackintosh 766c650
Fix clippy warnings: an implementation of `From` is preferred
ackintosh e99575b
Fix redundant clone
ackintosh a6c797b
Fix clippy warnings: manual implementation of `Option::map`
ackintosh cc9f739
Fix clippy warnings: explicit lifetimes given in parameter types wher…
ackintosh d106aa3
Fix clippy warnings: called `map(..).flatten()` on `Option`
ackintosh 77c9c22
Allow some lint warnings on openmetrics.rs which is an auto-generated…
ackintosh ec56224
Remove unnecessary cfg
ackintosh d992bad
Move`Encode` trait from `prometheus_client::encoding::text` to `prome…
ackintosh 8fce756
Bump up the minor version as the unreleased contains breaking changes
ackintosh 639cb0a
Update a link to PR
ackintosh ca0f583
misc fixes
divagant-martian 8baf256
Remove a `Display` requirement
ackintosh 3a2190d
Remove unnecessary Display implementation
ackintosh 396512f
Disambiguate `Encode`
ackintosh 20fd62e
Fix `cannot find derive macro Encode in this scope` in docs
ackintosh 8ac25a5
Fix clippy warnings
ackintosh f5b61f1
Don't use AtomicI64 on unsupported platforms
ackintosh 69f85ba
Merge pull request #9 from ackintosh/remove-display
ackintosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "prometheus-client" | ||
version = "0.18.0" | ||
version = "0.19.0" | ||
authors = ["Max Inden <[email protected]>"] | ||
edition = "2021" | ||
description = "Open Metrics client library allowing users to natively instrument applications." | ||
|
@@ -10,14 +10,20 @@ repository = "https://github.com/prometheus/client_rust" | |
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"] | ||
|
||
[workspace] | ||
members = ["derive-text-encode"] | ||
members = ["derive-encode"] | ||
|
||
[dependencies] | ||
dtoa = "1.0" | ||
itoa = "1.0" | ||
parking_lot = "0.12" | ||
prometheus-client-derive-text-encode = { version = "0.3.0", path = "derive-text-encode" } | ||
prometheus-client-derive-encode = { version = "0.3.0", path = "derive-encode" } | ||
prost = { version = "0.9.0", optional = true } | ||
prost-types = { version = "0.9.0", optional = true } | ||
void = { version = "1.0", optional = true } | ||
|
||
[dev-dependencies] | ||
async-std = { version = "1", features = ["attributes"] } | ||
|
@@ -29,6 +35,9 @@ rand = "0.8.4" | |
tide = "0.16" | ||
actix-web = "4" | ||
|
||
[build-dependencies] | ||
prost-build = { version = "0.9.0", optional = true } | ||
|
||
[[bench]] | ||
name = "family" | ||
harness = false | ||
|
@@ -37,3 +46,10 @@ harness = false | |
name = "text" | ||
path = "benches/encoding/text.rs" | ||
harness = false | ||
required-features = [] | ||
|
||
[[bench]] | ||
name = "proto" | ||
path = "benches/encoding/proto.rs" | ||
harness = false | ||
required-features = ["protobuf"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Benchmark inspired by | ||
// 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::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}; | ||
|
||
pub fn proto(c: &mut Criterion) { | ||
c.bench_function("encode", |b| { | ||
#[derive(Clone, Hash, PartialEq, Eq, Encode)] | ||
struct Labels { | ||
path: String, | ||
method: Method, | ||
some_number: u64, | ||
} | ||
|
||
#[derive(Clone, Hash, PartialEq, Eq, Encode)] | ||
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, Encode)] | ||
enum Region { | ||
Africa, | ||
#[allow(dead_code)] | ||
Asia, | ||
} | ||
|
||
let mut registry = Registry::<Box<dyn EncodeMetric>>::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)) | ||
}); | ||
|
||
registry.register( | ||
format!("my_counter{}", i), | ||
"My counter", | ||
Box::new(counter_family.clone()), | ||
); | ||
registry.register( | ||
format!("my_histogram{}", i), | ||
"My histogram", | ||
Box::new(histogram_family.clone()), | ||
); | ||
|
||
for j in 0_u32..100 { | ||
counter_family | ||
.get_or_create(&Labels { | ||
path: format!("/path/{}", i), | ||
method: Method::Get, | ||
some_number: j.into(), | ||
}) | ||
.inc(); | ||
|
||
histogram_family | ||
.get_or_create(&Region::Africa) | ||
.observe(j.into()); | ||
} | ||
} | ||
|
||
b.iter(|| { | ||
let metric_set = encode(®istry); | ||
black_box(metric_set); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, proto); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use std::io::Result; | ||
|
||
fn main() -> Result<()> { | ||
#[cfg(feature = "protobuf")] | ||
prost_build::compile_protos( | ||
&["src/encoding/proto/openmetrics_data_model.proto"], | ||
&["src/encoding/proto/"], | ||
)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
[package] | ||
name = "prometheus-client-derive-text-encode" | ||
version = "0.3.0" | ||
name = "prometheus-client-derive-encode" | ||
version = "0.3.1" | ||
authors = ["Max Inden <[email protected]>"] | ||
edition = "2021" | ||
description = "Auxiliary crate to derive text Encode trait from prometheus-client." | ||
description = "Auxiliary crate to derive Encode trait from prometheus-client." | ||
license = "Apache-2.0 OR MIT" | ||
repository = "https://github.com/prometheus/client_rust" | ||
homepage = "https://github.com/prometheus/client_rust" | ||
documentation = "https://docs.rs/prometheus-client-derive-text-encode" | ||
|
||
[features] | ||
protobuf = [] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
|
@@ -17,7 +20,7 @@ quote = "1" | |
syn = "1" | ||
|
||
[dev-dependencies] | ||
prometheus-client = { path = "../" } | ||
prometheus-client = { path = "../", features = ["protobuf"] } | ||
|
||
[lib] | ||
proc-macro = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏