Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more stable metrics sdk tests #1768

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions opentelemetry-sdk/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@
counter.add(50, &[]);
test_context.flush_metrics();
let _ = test_context.get_aggregation::<data::Sum<u64>>("my_counter", None);
test_context.reset_metrics();

counter.add(5, &[]);
test_context.flush_metrics();
Expand All @@ -810,6 +811,7 @@
counter.add(50, &[]);
test_context.flush_metrics();
let _ = test_context.get_aggregation::<data::Sum<u64>>("my_counter", None);
test_context.reset_metrics();

counter.add(5, &[]);
test_context.flush_metrics();
Expand All @@ -836,6 +838,7 @@
counter.add(50, &[]);
test_context.flush_metrics();
let _ = test_context.get_aggregation::<data::Sum<u64>>("my_counter", None);
test_context.reset_metrics();

counter.add(50, &[KeyValue::new("a", "b")]);
test_context.flush_metrics();
Expand Down Expand Up @@ -886,6 +889,7 @@
.expect("datapoint with key1=value2 expected");
assert_eq!(data_point1.value, 3);

test_context.exporter.reset();

Check warning on line 892 in opentelemetry-sdk/src/metrics/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/mod.rs#L892

Added line #L892 was not covered by tests
// flush again, and validate that nothing is flushed
// as delta temporality.
test_context.flush_metrics();
Expand Down Expand Up @@ -1072,6 +1076,10 @@
self.meter_provider.force_flush().unwrap();
}

fn reset_metrics(&self) {
self.exporter.reset();
}

fn get_aggregation<T: data::Aggregation>(
&mut self,
counter_name: &str,
Expand All @@ -1087,8 +1095,14 @@
"no metrics were exported"
);

// Get the latest resource metric in case of multiple flushes/exports
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
let resource_metric = self.resource_metrics.last().unwrap();
assert!(
self.resource_metrics.len() == 1,
"Expected single resource metrics."

Check warning on line 1100 in opentelemetry-sdk/src/metrics/mod.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-sdk/src/metrics/mod.rs#L1100

Added line #L1100 was not covered by tests
);
let resource_metric = self
.resource_metrics
.first()
.expect("This should contain exactly one resource metric, as validated above.");

assert!(
!resource_metric.scope_metrics.is_empty(),
Expand Down
Loading