-
Notifications
You must be signed in to change notification settings - Fork 506
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
Metric attributes need sort with keys only #1718
Merged
cijothomas
merged 3 commits into
open-telemetry:main
from
cijothomas:cijothomas/simplify-sort
May 8, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -607,6 +607,104 @@ mod tests { | |
assert_eq!(data_point.value, 30); | ||
} | ||
|
||
// "multi_thread" tokio flavor must be used else flush won't | ||
// be able to make progress! | ||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
async fn counter_aggregation_attribute_order() { | ||
// Run this test with stdout enabled to see output. | ||
// cargo test counter_aggregation_attribute_order --features=metrics,testing -- --nocapture | ||
|
||
// Arrange | ||
let exporter = InMemoryMetricsExporter::default(); | ||
let reader = PeriodicReader::builder(exporter.clone(), runtime::Tokio).build(); | ||
let meter_provider = SdkMeterProvider::builder().with_reader(reader).build(); | ||
|
||
// Act | ||
let meter = meter_provider.meter("test"); | ||
let counter = meter.u64_counter("my_counter").init(); | ||
// Add the same set of attributes in different order. (they are expected | ||
// to be treated as same attributes) | ||
counter.add( | ||
1, | ||
&[ | ||
KeyValue::new("A", "a"), | ||
KeyValue::new("B", "b"), | ||
KeyValue::new("C", "c"), | ||
], | ||
); | ||
counter.add( | ||
1, | ||
&[ | ||
KeyValue::new("A", "a"), | ||
KeyValue::new("C", "c"), | ||
KeyValue::new("B", "b"), | ||
], | ||
); | ||
counter.add( | ||
1, | ||
&[ | ||
KeyValue::new("B", "b"), | ||
KeyValue::new("A", "a"), | ||
KeyValue::new("C", "c"), | ||
], | ||
); | ||
counter.add( | ||
1, | ||
&[ | ||
KeyValue::new("B", "b"), | ||
KeyValue::new("C", "c"), | ||
KeyValue::new("A", "a"), | ||
], | ||
); | ||
counter.add( | ||
1, | ||
&[ | ||
KeyValue::new("C", "c"), | ||
KeyValue::new("B", "b"), | ||
KeyValue::new("A", "a"), | ||
], | ||
); | ||
counter.add( | ||
1, | ||
&[ | ||
KeyValue::new("C", "c"), | ||
KeyValue::new("A", "a"), | ||
KeyValue::new("B", "b"), | ||
], | ||
); | ||
|
||
meter_provider.force_flush().unwrap(); | ||
|
||
// Assert | ||
let resource_metrics = exporter | ||
.get_finished_metrics() | ||
.expect("metrics are expected to be exported."); | ||
assert!(!resource_metrics.is_empty()); | ||
let metric = &resource_metrics[0].scope_metrics[0].metrics[0]; | ||
assert_eq!(metric.name, "my_counter"); | ||
let sum = metric | ||
.data | ||
.as_any() | ||
.downcast_ref::<data::Sum<u64>>() | ||
.expect("Sum aggregation expected for Counter instruments by default"); | ||
|
||
// Expecting 1 time-series. | ||
assert_eq!( | ||
sum.data_points.len(), | ||
1, | ||
"Expected only one data point as attributes are same, but just reordered." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could probably add an assertion to verify that the attributes of the datapoint match what we expect. |
||
); | ||
assert_eq!( | ||
sum.temporality, | ||
data::Temporality::Cumulative, | ||
"Should produce cumulative by default." | ||
); | ||
|
||
// validate the sole datapoint | ||
let data_point1 = &sum.data_points[0]; | ||
assert_eq!(data_point1.value, 6); | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
async fn no_attr_cumulative_counter() { | ||
let mut test_context = TestContext::new(Some(Temporality::Cumulative)); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test to ensure that the dedupe + sort is case-sensitive as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
coming next PR