Skip to content

Commit

Permalink
Merge branch 'main' into cijothomas/utkarsh-maintainer
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Oct 25, 2024
2 parents 5490e6d + 5628f66 commit f5d562a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ hyper-util = "0.1"
log = "0.4.21"
once_cell = "1.13"
ordered-float = "4.0"
pin-project-lite = "0.2"
pin-project-lite = "=0.2.14" # 0.2.15 is failing for cargo-check-external-types
prost = "0.13"
prost-build = "0.13"
prost-types = "0.13"
Expand Down
112 changes: 61 additions & 51 deletions opentelemetry-sdk/benches/metrics_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| ThreadLocal_Random_Generator_5 | 37 ns |
*/

use criterion::{criterion_group, criterion_main, Criterion};
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use opentelemetry::{
metrics::{Counter, MeterProvider as _},
KeyValue,
Expand Down Expand Up @@ -57,62 +57,72 @@ fn criterion_benchmark(c: &mut Criterion) {
fn counter_add_sorted(c: &mut Criterion) {
let counter = create_counter("Counter_Add_Sorted");
c.bench_function("Counter_Add_Sorted", |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];
counter.add(
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];
counter.add(
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 counter_add_unsorted(c: &mut Criterion) {
let counter = create_counter("Counter_Add_Unsorted");
c.bench_function("Counter_Add_Unsorted", |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];
counter.add(
1,
&[
KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]),
KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]),
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_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];
counter.add(
1,
&[
KeyValue::new("attribute2", ATTRIBUTE_VALUES[index_second_attribute]),
KeyValue::new("attribute3", ATTRIBUTE_VALUES[index_third_attribute]),
KeyValue::new("attribute1", ATTRIBUTE_VALUES[index_first_attribute]),
KeyValue::new("attribute4", ATTRIBUTE_VALUES[index_fourth_attribute]),
],
);
},
BatchSize::SmallInput,
);
});
}

Expand Down
17 changes: 13 additions & 4 deletions opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashMap, f64::consts::LOG2_E, sync::Mutex, time::SystemTime};

use once_cell::sync::Lazy;
use opentelemetry::{metrics::MetricsError, KeyValue};
use opentelemetry::{otel_debug, KeyValue};

use crate::{
metrics::data::{self, Aggregation, Temporality},
Expand Down Expand Up @@ -100,9 +100,18 @@ impl<T: Number> ExpoHistogramDataPoint<T> {
if (self.scale - scale_delta as i8) < EXPO_MIN_SCALE {
// With a scale of -10 there is only two buckets for the whole range of f64 values.
// This can only happen if there is a max size of 1.
opentelemetry::global::handle_error(MetricsError::Other(
"exponential histogram scale underflow".into(),
));

// TODO - to check if this should be logged as an error if this is auto-recoverable.
otel_debug!(
name: "ExponentialHistogramDataPoint.Scale.Underflow",
current_scale = self.scale,
scale_delta = scale_delta,
max_size = self.max_size,
min_scale = EXPO_MIN_SCALE,
value = format!("{:?}", v),
message = "The measurement will be dropped due to scale underflow. Check the histogram configuration"
);

return;
}
// Downscale
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-sdk/src/metrics/manual_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use std::{
};

use opentelemetry::{
global,
metrics::{MetricsError, Result},
otel_debug,
};

use super::{
Expand Down Expand Up @@ -77,9 +77,9 @@ impl MetricReader for ManualReader {
if inner.sdk_producer.is_none() {
inner.sdk_producer = Some(pipeline);
} else {
global::handle_error(MetricsError::Config(
"duplicate reader registration, did not register manual reader".into(),
))
otel_debug!(
name: "ManualReader.DuplicateRegistration",
message = "The pipeline is already registered to the Reader. Registering pipeline multiple times is not allowed.");
}
});
}
Expand Down
19 changes: 13 additions & 6 deletions opentelemetry-sdk/src/metrics/meter_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ use std::{
};

use opentelemetry::{
global,
metrics::{Meter, MeterProvider, MetricsError, Result},
KeyValue,
otel_debug, otel_error, KeyValue,
};

use crate::{instrumentation::Scope, Resource};
Expand Down Expand Up @@ -137,13 +136,21 @@ impl Drop for SdkMeterProviderInner {
fn drop(&mut self) {
// If user has already shutdown the provider manually by calling
// shutdown(), then we don't need to call shutdown again.
if !self.is_shutdown.load(Ordering::Relaxed) {
if let Err(err) = self.shutdown() {
global::handle_error(err);
}
if self.is_shutdown.load(Ordering::Relaxed) {
otel_debug!(
name: "MeterProvider.AlreadyShutdown",
message = "Meter provider was already shut down; drop will not attempt shutdown again."
);
} else if let Err(err) = self.shutdown() {
otel_error!(
name: "MeterProvider.ShutdownFailed",
message = "Shutdown attempt failed during drop of MeterProvider.",
reason = format!("{}", err)
);
}
}
}

impl MeterProvider for SdkMeterProvider {
fn versioned_meter(
&self,
Expand Down

0 comments on commit f5d562a

Please sign in to comment.