Skip to content

Commit

Permalink
test: fix UpDownCounter logic to account for temporality preference
Browse files Browse the repository at this point in the history
  • Loading branch information
pitoniak32 committed Oct 17, 2024
1 parent a094cd9 commit 2fcb26a
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions opentelemetry-sdk/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,11 @@ mod tests {

assert_eq!(sum.data_points.len(), 1, "Expected only one data point");
assert!(!sum.is_monotonic, "Should not produce monotonic.");
assert_eq!(sum.temporality, Temporality::Delta, "Should produce Delta");
assert_eq!(
sum.temporality,
Temporality::Cumulative,
"Should produce Cumulative for UpDownCounter"
);

let data_point = &sum.data_points[0];
assert!(data_point.attributes.is_empty(), "Non-empty attribute set");
Expand Down Expand Up @@ -2251,15 +2255,11 @@ mod tests {
!sum.is_monotonic,
"UpDownCounter should produce non-monotonic."
);
if let Temporality::Cumulative = temporality {
assert_eq!(
sum.temporality,
Temporality::Cumulative,
"Should produce cumulative"
);
} else {
assert_eq!(sum.temporality, Temporality::Delta, "Should produce delta");
}
assert_eq!(
sum.temporality,
Temporality::Cumulative,
"Should produce Cumulative for UpDownCounter"

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L2261 was not covered by tests
);

// find and validate key1=value2 datapoint
let data_point1 = find_datapoint_with_key_value(&sum.data_points, "key1", "value1")
Expand Down Expand Up @@ -2288,19 +2288,11 @@ mod tests {
assert_eq!(sum.data_points.len(), 2);
let data_point1 = find_datapoint_with_key_value(&sum.data_points, "key1", "value1")
.expect("datapoint with key1=value1 expected");
if temporality == Temporality::Cumulative {
assert_eq!(data_point1.value, 10);
} else {
assert_eq!(data_point1.value, 5);
}
assert_eq!(data_point1.value, 10);

let data_point1 = find_datapoint_with_key_value(&sum.data_points, "key1", "value2")
.expect("datapoint with key1=value2 expected");
if temporality == Temporality::Cumulative {
assert_eq!(data_point1.value, 14);
} else {
assert_eq!(data_point1.value, 7);
}
assert_eq!(data_point1.value, 14);
}

fn find_datapoint_with_key_value<'a, T>(
Expand Down

0 comments on commit 2fcb26a

Please sign in to comment.