Skip to content

Commit 6b30d7e

Browse files
author
Matthew Shapiro
committed
Final test fix
1 parent cd03300 commit 6b30d7e

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

+16-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ impl<T: Number<T>> Sum<T> {
154154
*start = t;
155155
}
156156

157-
(n, new_agg.map(|a| Box::new(a) as Box<_>))
157+
(
158+
s_data.data_points.len(),
159+
new_agg.map(|a| Box::new(a) as Box<_>),
160+
)
158161
}
159162

160163
pub(crate) fn cumulative(
@@ -220,7 +223,10 @@ impl<T: Number<T>> Sum<T> {
220223
});
221224
}
222225

223-
(n, new_agg.map(|a| Box::new(a) as Box<_>))
226+
(
227+
s_data.data_points.len(),
228+
new_agg.map(|a| Box::new(a) as Box<_>),
229+
)
224230
}
225231
}
226232

@@ -322,7 +328,10 @@ impl<T: Number<T>> PrecomputedSum<T> {
322328
*reported = new_reported;
323329
drop(reported); // drop before values guard is dropped
324330

325-
(n, new_agg.map(|a| Box::new(a) as Box<_>))
331+
(
332+
s_data.data_points.len(),
333+
new_agg.map(|a| Box::new(a) as Box<_>),
334+
)
326335
}
327336

328337
pub(crate) fn cumulative(
@@ -396,6 +405,9 @@ impl<T: Number<T>> PrecomputedSum<T> {
396405
*reported = new_reported;
397406
drop(reported); // drop before values guard is dropped
398407

399-
(n, new_agg.map(|a| Box::new(a) as Box<_>))
408+
(
409+
s_data.data_points.len(),
410+
new_agg.map(|a| Box::new(a) as Box<_>),
411+
)
400412
}
401413
}

opentelemetry-sdk/src/metrics/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,16 @@ mod tests {
578578
test_context.flush_metrics();
579579
let _ = test_context.get_aggregation::<data::Sum<u64>>("my_counter", "my_unit");
580580

581+
counter.add(50, &[KeyValue::new("a", "b")]);
581582
test_context.flush_metrics();
582583
let sum = test_context.get_aggregation::<data::Sum<u64>>("my_counter", "my_unit");
583584

584-
assert_eq!(sum.data_points.len(), 0, "Expected only one data point");
585+
let no_attr_data_point = sum.data_points.iter().find(|x| x.attributes.is_empty());
586+
587+
assert!(
588+
no_attr_data_point.is_none(),
589+
"Expected no data points with no attributes"
590+
);
585591
}
586592

587593
struct TestContext {

0 commit comments

Comments
 (0)