Skip to content

Commit 3042aa0

Browse files
authored
Simplify metric::data imports (#2536)
1 parent 57d1297 commit 3042aa0

File tree

8 files changed

+104
-100
lines changed

8 files changed

+104
-100
lines changed

opentelemetry-otlp/src/exporter/http/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ use std::time::Duration;
2727
#[cfg(feature = "metrics")]
2828
mod metrics;
2929

30+
#[cfg(feature = "metrics")]
31+
use opentelemetry_sdk::metrics::data::ResourceMetrics;
32+
3033
#[cfg(feature = "logs")]
3134
pub(crate) mod logs;
3235

@@ -336,7 +339,7 @@ impl OtlpHttpClient {
336339
#[cfg(feature = "metrics")]
337340
fn build_metrics_export_body(
338341
&self,
339-
metrics: &mut opentelemetry_sdk::metrics::data::ResourceMetrics,
342+
metrics: &mut ResourceMetrics,
340343
) -> opentelemetry_sdk::metrics::MetricResult<(Vec<u8>, &'static str)> {
341344
use opentelemetry_proto::tonic::collector::metrics::v1::ExportMetricsServiceRequest;
342345

opentelemetry-proto/src/transform/metrics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ pub mod tonic {
1010

1111
use opentelemetry::{otel_debug, Key, Value};
1212
use opentelemetry_sdk::metrics::data::{
13-
self, Exemplar as SdkExemplar, ExponentialHistogram as SdkExponentialHistogram,
14-
Gauge as SdkGauge, Histogram as SdkHistogram, Metric as SdkMetric,
13+
Exemplar as SdkExemplar, ExponentialHistogram as SdkExponentialHistogram,
14+
Gauge as SdkGauge, Histogram as SdkHistogram, Metric as SdkMetric, ResourceMetrics,
1515
ScopeMetrics as SdkScopeMetrics, Sum as SdkSum,
1616
};
1717
use opentelemetry_sdk::metrics::Temporality;
@@ -110,8 +110,8 @@ pub mod tonic {
110110
}
111111
}
112112

113-
impl From<&data::ResourceMetrics> for ExportMetricsServiceRequest {
114-
fn from(rm: &data::ResourceMetrics) -> Self {
113+
impl From<&ResourceMetrics> for ExportMetricsServiceRequest {
114+
fn from(rm: &ResourceMetrics) -> Self {
115115
ExportMetricsServiceRequest {
116116
resource_metrics: vec![TonicResourceMetrics {
117117
resource: Some((&rm.resource).into()),

opentelemetry-sdk/src/metrics/internal/exponential_histogram.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use opentelemetry::{otel_debug, KeyValue};
44
use std::sync::OnceLock;
55

66
use crate::metrics::{
7-
data::{self, Aggregation},
7+
data::{self, Aggregation, ExponentialHistogram},
88
Temporality,
99
};
1010

@@ -386,7 +386,7 @@ impl<T: Number> ExpoHistogram<T> {
386386
fn delta(&self, dest: Option<&mut dyn Aggregation>) -> (usize, Option<Box<dyn Aggregation>>) {
387387
let time = self.init_time.delta();
388388

389-
let h = dest.and_then(|d| d.as_mut().downcast_mut::<data::ExponentialHistogram<T>>());
389+
let h = dest.and_then(|d| d.as_mut().downcast_mut::<ExponentialHistogram<T>>());
390390
let mut new_agg = if h.is_none() {
391391
Some(data::ExponentialHistogram {
392392
data_points: vec![],
@@ -443,7 +443,7 @@ impl<T: Number> ExpoHistogram<T> {
443443
) -> (usize, Option<Box<dyn Aggregation>>) {
444444
let time = self.init_time.cumulative();
445445

446-
let h = dest.and_then(|d| d.as_mut().downcast_mut::<data::ExponentialHistogram<T>>());
446+
let h = dest.and_then(|d| d.as_mut().downcast_mut::<ExponentialHistogram<T>>());
447447
let mut new_agg = if h.is_none() {
448448
Some(data::ExponentialHistogram {
449449
data_points: vec![],
@@ -528,6 +528,7 @@ where
528528
mod tests {
529529
use std::{ops::Neg, time::SystemTime};
530530

531+
use data::{ExponentialHistogram, Gauge, Histogram, Sum};
531532
use tests::internal::AggregateFns;
532533

533534
use crate::metrics::internal::{self, AggregateBuilder};
@@ -1468,8 +1469,8 @@ mod tests {
14681469
test_name
14691470
);
14701471

1471-
if let Some(a) = a.as_any().downcast_ref::<data::Gauge<T>>() {
1472-
let b = b.as_any().downcast_ref::<data::Gauge<T>>().unwrap();
1472+
if let Some(a) = a.as_any().downcast_ref::<Gauge<T>>() {
1473+
let b = b.as_any().downcast_ref::<Gauge<T>>().unwrap();
14731474
assert_eq!(
14741475
a.data_points.len(),
14751476
b.data_points.len(),
@@ -1479,8 +1480,8 @@ mod tests {
14791480
for (a, b) in a.data_points.iter().zip(b.data_points.iter()) {
14801481
assert_gauge_data_points_eq(a, b, "mismatching gauge data points", test_name);
14811482
}
1482-
} else if let Some(a) = a.as_any().downcast_ref::<data::Sum<T>>() {
1483-
let b = b.as_any().downcast_ref::<data::Sum<T>>().unwrap();
1483+
} else if let Some(a) = a.as_any().downcast_ref::<Sum<T>>() {
1484+
let b = b.as_any().downcast_ref::<Sum<T>>().unwrap();
14841485
assert_eq!(
14851486
a.temporality, b.temporality,
14861487
"{} mismatching sum temporality",
@@ -1500,8 +1501,8 @@ mod tests {
15001501
for (a, b) in a.data_points.iter().zip(b.data_points.iter()) {
15011502
assert_sum_data_points_eq(a, b, "mismatching sum data points", test_name);
15021503
}
1503-
} else if let Some(a) = a.as_any().downcast_ref::<data::Histogram<T>>() {
1504-
let b = b.as_any().downcast_ref::<data::Histogram<T>>().unwrap();
1504+
} else if let Some(a) = a.as_any().downcast_ref::<Histogram<T>>() {
1505+
let b = b.as_any().downcast_ref::<Histogram<T>>().unwrap();
15051506
assert_eq!(
15061507
a.temporality, b.temporality,
15071508
"{}: mismatching hist temporality",
@@ -1516,10 +1517,10 @@ mod tests {
15161517
for (a, b) in a.data_points.iter().zip(b.data_points.iter()) {
15171518
assert_hist_data_points_eq(a, b, "mismatching hist data points", test_name);
15181519
}
1519-
} else if let Some(a) = a.as_any().downcast_ref::<data::ExponentialHistogram<T>>() {
1520+
} else if let Some(a) = a.as_any().downcast_ref::<ExponentialHistogram<T>>() {
15201521
let b = b
15211522
.as_any()
1522-
.downcast_ref::<data::ExponentialHistogram<T>>()
1523+
.downcast_ref::<ExponentialHistogram<T>>()
15231524
.unwrap();
15241525
assert_eq!(
15251526
a.temporality, b.temporality,

opentelemetry-sdk/src/metrics/internal/last_value.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::metrics::{
2-
data::{self, Aggregation, GaugeDataPoint},
2+
data::{self, Aggregation, Gauge, GaugeDataPoint},
33
Temporality,
44
};
55
use opentelemetry::KeyValue;
@@ -65,7 +65,7 @@ impl<T: Number> LastValue<T> {
6565
) -> (usize, Option<Box<dyn Aggregation>>) {
6666
let time = self.init_time.delta();
6767

68-
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<data::Gauge<T>>());
68+
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<Gauge<T>>());
6969
let mut new_agg = if s_data.is_none() {
7070
Some(data::Gauge {
7171
data_points: vec![],
@@ -97,7 +97,7 @@ impl<T: Number> LastValue<T> {
9797
dest: Option<&mut dyn Aggregation>,
9898
) -> (usize, Option<Box<dyn Aggregation>>) {
9999
let time = self.init_time.cumulative();
100-
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<data::Gauge<T>>());
100+
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<Gauge<T>>());
101101
let mut new_agg = if s_data.is_none() {
102102
Some(data::Gauge {
103103
data_points: vec![],

opentelemetry-sdk/src/metrics/internal/precomputed_sum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use opentelemetry::KeyValue;
22

3-
use crate::metrics::data::{self, Aggregation, SumDataPoint};
3+
use crate::metrics::data::{self, Aggregation, Sum, SumDataPoint};
44
use crate::metrics::Temporality;
55

66
use super::aggregate::{AggregateTimeInitiator, AttributeSetFilter};
@@ -40,7 +40,7 @@ impl<T: Number> PrecomputedSum<T> {
4040
) -> (usize, Option<Box<dyn Aggregation>>) {
4141
let time = self.init_time.delta();
4242

43-
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<data::Sum<T>>());
43+
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<Sum<T>>());
4444
let mut new_agg = if s_data.is_none() {
4545
Some(data::Sum {
4646
data_points: vec![],
@@ -91,7 +91,7 @@ impl<T: Number> PrecomputedSum<T> {
9191
) -> (usize, Option<Box<dyn Aggregation>>) {
9292
let time = self.init_time.cumulative();
9393

94-
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<data::Sum<T>>());
94+
let s_data = dest.and_then(|d| d.as_mut().downcast_mut::<Sum<T>>());
9595
let mut new_agg = if s_data.is_none() {
9696
Some(data::Sum {
9797
data_points: vec![],

0 commit comments

Comments
 (0)