Skip to content

Commit

Permalink
Merge branch 'main' into fix-metrics-u64-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Jan 15, 2025
2 parents c64d3b3 + 1904d4b commit c811133
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 98 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ for specific dates and for Zoom meeting links. "OTel Rust SIG" is the name of
meeting for this group.

Meeting notes are available as a public [Google
doc](https://docs.google.com/document/d/1tGKuCsSnyT2McDncVJrMgg74_z8V06riWZa0Sr79I_4/edit).
doc](https://docs.google.com/document/d/12upOzNk8c3SFTjsL6IRohCWMgzLKoknSCOOdMakbWo4/edit).
If you have trouble accessing the doc, please get in touch on
[Slack](https://cloud-native.slack.com/archives/C03GDP0H023).

Expand Down
5 changes: 4 additions & 1 deletion opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
- Feature flag "populate-logs-event-name" is removed as no longer relevant.
LogRecord's `event_name()` is now automatically populated on the newly added
"event_name" field in LogRecord proto definition.

- Remove "grpc-tonic" feature from default, and instead add "http-proto" and
"reqwest-blocking-client" features as default, to align with the
specification.
[2516](https://github.com/open-telemetry/opentelemetry-rust/pull/2516)

## 0.27.0

Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal-logs = ["tracing", "opentelemetry/internal-logs"]
# add ons
serialize = ["serde", "serde_json"]

default = ["grpc-tonic", "trace", "metrics", "logs", "internal-logs"]
default = ["http-proto", "reqwest-blocking-client", "trace", "metrics", "logs", "internal-logs"]

# grpc using tonic
grpc-tonic = ["tonic", "prost", "http", "tokio", "opentelemetry-proto/gen-tonic"]
Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-otlp/examples/basic-otlp-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ license = "Apache-2.0"
publish = false

[features]
default = ["reqwest-blocking"]
reqwest-blocking = ["opentelemetry-otlp/reqwest-blocking-client"]
hyper = ["opentelemetry-otlp/hyper-client"]

[dependencies]
once_cell = { workspace = true }
opentelemetry = { path = "../../../opentelemetry" }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio", "experimental_metrics_periodicreader_with_async_runtime"]}
opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "logs", "internal-logs"] , default-features = false}
opentelemetry-otlp = { path = "../..", features = ["http-proto", "http-json", "logs", "internal-logs"]}
opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false}

tokio = { workspace = true, features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-otlp/examples/basic-otlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false
once_cell = { workspace = true }
opentelemetry = { path = "../../../opentelemetry" }
opentelemetry_sdk = { path = "../../../opentelemetry-sdk", features = ["rt-tokio"] }
opentelemetry-otlp = { path = "../../../opentelemetry-otlp" }
opentelemetry-otlp = { path = "../../../opentelemetry-otlp", features = ["grpc-tonic"] }
tokio = { version = "1.0", features = ["full"] }
opentelemetry-appender-tracing = { path = "../../../opentelemetry-appender-tracing", default-features = false}
tracing = { workspace = true, features = ["std"]}
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ path = "tests/json_serde.rs"

[features]
default = ["full"]
full = ["gen-tonic", "trace", "logs", "metrics", "zpages", "with-serde"]
full = ["gen-tonic", "trace", "logs", "metrics", "zpages", "with-serde", "internal-logs"]

# crates used to generate rs files
gen-tonic = ["gen-tonic-messages", "tonic/transport"]
Expand All @@ -44,6 +44,7 @@ zpages = ["trace"]
testing = ["opentelemetry/testing"]

# add ons
internal-logs = ["tracing"]
with-schemars = ["schemars"]
with-serde = ["serde", "hex"]

Expand All @@ -55,6 +56,7 @@ opentelemetry_sdk = { version = "0.27", default-features = false, path = "../ope
schemars = { version = "0.8", optional = true }
serde = { workspace = true, optional = true, features = ["serde_derive"] }
hex = { version = "0.4.3", optional = true }
tracing = {workspace = true, optional = true} # optional for opentelemetry internal logging

[dev-dependencies]
opentelemetry = { features = ["testing"], path = "../opentelemetry" }
Expand Down
76 changes: 67 additions & 9 deletions opentelemetry-sdk/benches/metrics_counter.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/*
The benchmark results:
criterion = "0.5.1"
rustc 1.82.0 (f6e511eec 2024-10-15)
OS: Ubuntu 22.04.3 LTS (5.15.167.4-microsoft-standard-WSL2)
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
rustc 1.83.0 (90b35a623 2024-11-26)
OS: Ubuntu 22.04.4 LTS (5.15.167.4-microsoft-standard-WSL2)
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz 2.79 GHz
RAM: 64.0 GB
| Test | Average time|
|--------------------------------|-------------|
| Counter_Add_Sorted | 172 ns |
| Counter_Add_Unsorted | 183 ns |
| Counter_Overflow | 562 ns |
| ThreadLocal_Random_Generator_5 | 37 ns |
| Test | Average time|
|-------------------------------------------------------|-------------|
| Counter_Add_Sorted | 160 ns |
| Counter_Add_Unsorted | 164 ns |
| Counter_Add_Sorted_With_Non_Static_Values | 238 ns |
| Counter_Overflow | 562 ns |
| ThreadLocal_Random_Generator_5 | 37 ns |
*/

use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
Expand Down Expand Up @@ -51,6 +52,15 @@ fn create_counter(name: &'static str) -> Counter<u64> {
fn criterion_benchmark(c: &mut Criterion) {
counter_add_sorted(c);
counter_add_unsorted(c);

let attribute_values: [String; 10] = (1..=10)
.map(|i| format!("value{}", i))
.collect::<Vec<String>>()
.try_into()
.expect("Expected a Vec of length 10");

counter_add_sorted_with_non_static_values(c, attribute_values);

counter_overflow(c);
random_generator(c);
}
Expand Down Expand Up @@ -127,6 +137,54 @@ fn counter_add_unsorted(c: &mut Criterion) {
});
}

fn counter_add_sorted_with_non_static_values(c: &mut Criterion, attribute_values: [String; 10]) {
let counter = create_counter("Counter_Add_Sorted_With_Non_Static_Values");
c.bench_function("Counter_Add_Sorted_With_Non_Static_Values", |b| {
b.iter_batched(
|| {
// 4*4*10*10 = 1600 time series.
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
]
})
},
|rands| {
let index_first_attribute = rands[0];
let index_second_attribute = rands[1];
let index_third_attribute = rands[2];
let index_fourth_attribute = rands[3];
counter.add(
1,
&[
KeyValue::new(
"attribute1",
attribute_values[index_first_attribute].as_str().to_owned(),
),
KeyValue::new(
"attribute2",
attribute_values[index_second_attribute].as_str().to_owned(),
),
KeyValue::new(
"attribute3",
attribute_values[index_third_attribute].as_str().to_owned(),
),
KeyValue::new(
"attribute4",
attribute_values[index_fourth_attribute].as_str().to_owned(),
),
],
);
},
BatchSize::SmallInput,
);
});
}

fn counter_overflow(c: &mut Criterion) {
let counter = create_counter("Counter_Overflow");
// Cause overflow.
Expand Down
124 changes: 93 additions & 31 deletions opentelemetry-sdk/benches/metrics_histogram.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/*
The benchmark results:
criterion = "0.5.1"
rustc 1.82.0 (f6e511eec 2024-10-15)
rustc 1.83.0 (90b35a623 2024-11-26)
OS: Ubuntu 22.04.4 LTS (5.15.167.4-microsoft-standard-WSL2)
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz 2.79 GHz
RAM: 64.0 GB
| Test | Average time|
|--------------------------------|-------------|
| Histogram_Record | 225.04 ns |
| Test | Average time|
|-------------------------------------------------------|-------------|
| Histogram_Record | 186.24 ns |
| Histogram_Record_With_Non_Static_Values | 264.70 ns |
*/

use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use opentelemetry::{
metrics::{Histogram, MeterProvider as _},
KeyValue,
Expand Down Expand Up @@ -48,36 +49,97 @@ fn create_histogram(name: &'static str) -> Histogram<u64> {

fn criterion_benchmark(c: &mut Criterion) {
histogram_record(c);

let attribute_values: [String; 10] = (1..=10)
.map(|i| format!("value{}", i))
.collect::<Vec<String>>()
.try_into()
.expect("Expected a Vec of length 10");

histogram_record_with_non_static_values(c, attribute_values);
}

fn histogram_record(c: &mut Criterion) {
let histogram = create_histogram("Histogram_Record");
c.bench_function("Histogram_Record", |b| {
b.iter(|| {
// 4*4*10*10 = 1600 time series.
let rands = CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
]
});
let index_first_attribute = rands[0];
let index_second_attribute = rands[1];
let index_third_attribute = rands[2];
let index_fourth_attribute = rands[3];
histogram.record(
1,
&[
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),
KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]),
KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]),
KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]),
],
);
});
b.iter_batched(
|| {
// 4*4*10*10 = 1600 time series.
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
]
})
},
|rands| {
let index_first_attribute = rands[0];
let index_second_attribute = rands[1];
let index_third_attribute = rands[2];
let index_fourth_attribute = rands[3];
histogram.record(
1,
&[
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),
KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]),
KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]),
KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]),
],
);
},
BatchSize::SmallInput,
);
});
}

fn histogram_record_with_non_static_values(c: &mut Criterion, attribute_values: [String; 10]) {
let histogram = create_histogram("Histogram_Record_With_Non_Static_Values");
c.bench_function("Histogram_Record_With_Non_Static_Values", |b| {
b.iter_batched(
|| {
// 4*4*10*10 = 1600 time series.
CURRENT_RNG.with(|rng| {
let mut rng = rng.borrow_mut();
[
rng.gen_range(0..4),
rng.gen_range(0..4),
rng.gen_range(0..10),
rng.gen_range(0..10),
]
})
},
|rands| {
let index_first_attribute = rands[0];
let index_second_attribute = rands[1];
let index_third_attribute = rands[2];
let index_fourth_attribute = rands[3];
histogram.record(
1,
&[
KeyValue::new(
"attribute1",
attribute_values[index_first_attribute].as_str().to_owned(),
),
KeyValue::new(
"attribute2",
attribute_values[index_second_attribute].as_str().to_owned(),
),
KeyValue::new(
"attribute3",
attribute_values[index_third_attribute].as_str().to_owned(),
),
KeyValue::new(
"attribute4",
attribute_values[index_fourth_attribute].as_str().to_owned(),
),
],
);
},
BatchSize::SmallInput,
);
});
}

Expand Down
Loading

0 comments on commit c811133

Please sign in to comment.