Skip to content

Commit

Permalink
Final test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Shapiro committed Feb 8, 2024
1 parent cd03300 commit 6b30d7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 16 additions & 4 deletions opentelemetry-sdk/src/metrics/internal/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ impl<T: Number<T>> Sum<T> {
*start = t;
}

(n, new_agg.map(|a| Box::new(a) as Box<_>))
(
s_data.data_points.len(),
new_agg.map(|a| Box::new(a) as Box<_>),
)
}

pub(crate) fn cumulative(
Expand Down Expand Up @@ -220,7 +223,10 @@ impl<T: Number<T>> Sum<T> {
});
}

(n, new_agg.map(|a| Box::new(a) as Box<_>))
(
s_data.data_points.len(),
new_agg.map(|a| Box::new(a) as Box<_>),
)
}
}

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

(n, new_agg.map(|a| Box::new(a) as Box<_>))
(
s_data.data_points.len(),
new_agg.map(|a| Box::new(a) as Box<_>),
)
}

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

(n, new_agg.map(|a| Box::new(a) as Box<_>))
(
s_data.data_points.len(),
new_agg.map(|a| Box::new(a) as Box<_>),
)
}
}
8 changes: 7 additions & 1 deletion opentelemetry-sdk/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,16 @@ mod tests {
test_context.flush_metrics();
let _ = test_context.get_aggregation::<data::Sum<u64>>("my_counter", "my_unit");

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

assert_eq!(sum.data_points.len(), 0, "Expected only one data point");
let no_attr_data_point = sum.data_points.iter().find(|x| x.attributes.is_empty());

assert!(
no_attr_data_point.is_none(),
"Expected no data points with no attributes"
);
}

struct TestContext {
Expand Down

0 comments on commit 6b30d7e

Please sign in to comment.