Skip to content

Commit a2147a7

Browse files
committed
Add Ord to example
1 parent beafca7 commit a2147a7

2 files changed

Lines changed: 30 additions & 26 deletions

File tree

benches/encoding/proto.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,40 @@
11
// Benchmark inspired by
22
// https://github.com/tikv/rust-prometheus/blob/ab1ca7285d3463504381a5025ae1951e020d6796/benches/text_encoder.rs:write
33

4-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
5-
use prometheus_client::encoding::prometheus_protobuf;
6-
use prometheus_client::metrics::counter::Counter;
7-
use prometheus_client::metrics::family::Family;
8-
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
9-
use prometheus_client::registry::Registry;
4+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
5+
use prometheus_client::{
6+
encoding::prometheus_protobuf,
7+
metrics::{
8+
counter::Counter,
9+
family::Family,
10+
histogram::{Histogram, exponential_buckets},
11+
},
12+
registry::Registry,
13+
};
1014
use prometheus_client_derive_encode::{EncodeLabelSet, EncodeLabelValue};
1115

1216
pub fn proto(c: &mut Criterion) {
1317
c.bench_function("encode", |b| {
14-
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
18+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug, PartialOrd, Ord)]
1519
struct CounterLabels {
1620
path: String,
1721
method: Method,
1822
some_number: u64,
1923
}
2024

21-
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
25+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug, PartialOrd, Ord)]
2226
enum Method {
2327
Get,
2428
#[allow(dead_code)]
2529
Put,
2630
}
2731

28-
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
32+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug, PartialOrd, Ord)]
2933
struct HistogramLabels {
3034
region: Region,
3135
}
3236

33-
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
37+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug, PartialOrd, Ord)]
3438
enum Region {
3539
Africa,
3640
#[allow(dead_code)]

derive-encode/tests/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use std::sync::Arc;
22

3-
use prometheus_client::encoding::text::encode;
4-
use prometheus_client::encoding::{EncodeLabelSet, EncodeLabelValue};
5-
use prometheus_client::metrics::counter::Counter;
6-
use prometheus_client::metrics::family::Family;
7-
use prometheus_client::registry::Registry;
3+
use prometheus_client::{
4+
encoding::{EncodeLabelSet, EncodeLabelValue, text::encode},
5+
metrics::{counter::Counter, family::Family},
6+
registry::Registry,
7+
};
88

9-
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug)]
9+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelSet, Debug, PartialOrd, Ord)]
1010
struct Labels {
1111
method: Method,
1212
path: String,
1313
}
1414

15-
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug)]
15+
#[derive(Clone, Hash, PartialEq, Eq, EncodeLabelValue, Debug, PartialOrd, Ord)]
1616
enum Method {
1717
Get,
1818
#[allow(dead_code)]
@@ -47,11 +47,11 @@ fn basic_flow() {
4747

4848
mod protobuf {
4949
use crate::{Labels, Method};
50-
use prometheus_client::encoding::prometheus_protobuf::encode;
51-
use prometheus_client::encoding::prometheus_protobuf::prometheus_data_model;
52-
use prometheus_client::metrics::counter::Counter;
53-
use prometheus_client::metrics::family::Family;
54-
use prometheus_client::registry::Registry;
50+
use prometheus_client::{
51+
encoding::prometheus_protobuf::{encode, prometheus_data_model},
52+
metrics::{counter::Counter, family::Family},
53+
registry::Registry,
54+
};
5555

5656
#[test]
5757
fn structs() {
@@ -106,7 +106,7 @@ mod protobuf {
106106

107107
#[test]
108108
fn remap_keyword_identifiers() {
109-
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
109+
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug, PartialOrd, Ord)]
110110
struct Labels {
111111
// `r#type` is problematic as `r#` is not a valid OpenMetrics label name
112112
// but one needs to use keyword identifier syntax (aka. raw identifiers)
@@ -137,7 +137,7 @@ fn remap_keyword_identifiers() {
137137

138138
#[test]
139139
fn arc_string() {
140-
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
140+
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug, PartialOrd, Ord)]
141141
struct Labels {
142142
client_id: Arc<String>,
143143
}
@@ -167,12 +167,12 @@ fn arc_string() {
167167

168168
#[test]
169169
fn flatten() {
170-
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
170+
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug, PartialOrd, Ord)]
171171
struct CommonLabels {
172172
a: u64,
173173
b: u64,
174174
}
175-
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug)]
175+
#[derive(EncodeLabelSet, Hash, Clone, Eq, PartialEq, Debug, PartialOrd, Ord)]
176176
struct Labels {
177177
unique: u64,
178178
#[prometheus(flatten)]

0 commit comments

Comments
 (0)