From 916a11782ae49f6bd5757b6e7ab7ef76c4482855 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Fri, 23 Aug 2024 07:30:44 -0700 Subject: [PATCH] Update visibility of AttributeSet from pub to pub(crate) (#2045) --- opentelemetry-sdk/Cargo.toml | 4 --- opentelemetry-sdk/benches/attribute_set.rs | 40 ---------------------- opentelemetry-sdk/src/metrics/mod.rs | 27 ++------------- 3 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 opentelemetry-sdk/benches/attribute_set.rs diff --git a/opentelemetry-sdk/Cargo.toml b/opentelemetry-sdk/Cargo.toml index 8f569fa6f9..eb49acd7ad 100644 --- a/opentelemetry-sdk/Cargo.toml +++ b/opentelemetry-sdk/Cargo.toml @@ -72,10 +72,6 @@ harness = false name = "metrics_histogram" harness = false -[[bench]] -name = "attribute_set" -harness = false - [[bench]] name = "trace" harness = false diff --git a/opentelemetry-sdk/benches/attribute_set.rs b/opentelemetry-sdk/benches/attribute_set.rs deleted file mode 100644 index 3c89ddc44d..0000000000 --- a/opentelemetry-sdk/benches/attribute_set.rs +++ /dev/null @@ -1,40 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion}; -use opentelemetry::KeyValue; -use opentelemetry_sdk::metrics::AttributeSet; - -// Run this benchmark with: -// cargo bench --bench attribute_set - -fn criterion_benchmark(c: &mut Criterion) { - attribute_set(c); -} - -fn attribute_set(c: &mut Criterion) { - c.bench_function("AttributeSet_without_duplicates", |b| { - b.iter(|| { - let attributes: &[KeyValue] = &[ - KeyValue::new("attribute1", "value1"), - KeyValue::new("attribute2", "value2"), - KeyValue::new("attribute3", "value3"), - KeyValue::new("attribute4", "value4"), - ]; - let _attribute_set: AttributeSet = attributes.into(); - }); - }); - - c.bench_function("AttributeSet_with_duplicates", |b| { - b.iter(|| { - let attributes: &[KeyValue] = &[ - KeyValue::new("attribute1", "value1"), - KeyValue::new("attribute3", "value3"), - KeyValue::new("attribute3", "value3"), - KeyValue::new("attribute4", "value4"), - ]; - let _attribute_set: AttributeSet = attributes.into(); - }); - }); -} - -criterion_group!(benches, criterion_benchmark); - -criterion_main!(benches); diff --git a/opentelemetry-sdk/src/metrics/mod.rs b/opentelemetry-sdk/src/metrics/mod.rs index 6ad7303415..0e1f978525 100644 --- a/opentelemetry-sdk/src/metrics/mod.rs +++ b/opentelemetry-sdk/src/metrics/mod.rs @@ -72,7 +72,7 @@ use opentelemetry::{Key, KeyValue, Value}; /// This must implement [Hash], [PartialEq], and [Eq] so it may be used as /// HashMap keys and other de-duplication methods. #[derive(Clone, Default, Debug, PartialEq, Eq)] -pub struct AttributeSet(Vec, u64); +pub(crate) struct AttributeSet(Vec, u64); impl From<&[KeyValue]> for AttributeSet { fn from(values: &[KeyValue]) -> Self { @@ -109,34 +109,13 @@ impl AttributeSet { AttributeSet(values, hash) } - /// Returns `true` if the set contains no elements. - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - - /// Retains only the attributes specified by the predicate. - pub fn retain(&mut self, f: F) - where - F: Fn(&KeyValue) -> bool, - { - self.0.retain(|kv| f(kv)); - - // Recalculate the hash as elements are changed. - self.1 = calculate_hash(&self.0); - } - /// Iterate over key value pairs in the set - pub fn iter(&self) -> impl Iterator { + pub(crate) fn iter(&self) -> impl Iterator { self.0.iter().map(|kv| (&kv.key, &kv.value)) } - /// Returns a slice of the key value pairs in the set - pub fn as_slice(&self) -> &[KeyValue] { - &self.0 - } - /// Returns the underlying Vec of KeyValue pairs - pub fn into_vec(self) -> Vec { + pub(crate) fn into_vec(self) -> Vec { self.0 } }