-
Notifications
You must be signed in to change notification settings - Fork 423
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
Add Aggregation as part of metrics SDK. #1178
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1178 +/- ##
==========================================
+ Coverage 93.35% 93.44% +0.10%
==========================================
Files 177 185 +8
Lines 6502 6720 +218
==========================================
+ Hits 6069 6279 +210
- Misses 433 441 +8
|
public: | ||
virtual void Aggregate(long value, const PointAttributes &attributes = {}) noexcept = 0; | ||
|
||
virtual void Aggregate(double value, const PointAttributes &attributes = {}) noexcept = 0; |
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.
Preferred overloaded methods over the template ( for double and long type) to avoid having header-only metrics sdk. The template use had a cascading effect here, forcing to make all inter-related classes as templates. Since this is not a customer-facing API, we have the flexibility to change it later.
…pp into aggregation-sdk-3
name = "view_registry_test", | ||
srcs = [ | ||
"view_registry_test.cc", | ||
], |
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.
Would it be possible to add tags here?
], | |
], | |
tags = [ | |
"metrics", | |
"test", | |
], |
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.
Thanks. Added it.
name = "aggregation_test", | ||
srcs = [ | ||
"aggregation_test.cc", | ||
], |
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.
], | |
], | |
tags = [ | |
"metrics", | |
"test", | |
], |
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.
Added.
|
||
PointType LongLastValueAggregation::Collect() noexcept | ||
{ | ||
if (!is_lastvalue_valid_) |
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.
Don't we need to protect is_lastvalue_valid_
here?
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.
Good point. I thought it should be fine to return an invalid value in given Collect() call, as long as the subsequent call would return a valid value. Worst case, we may miss a given metric (first few ones depending on collect interval) in a series of Collect() calls, but this way we can avoid a lock.
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.
I'm afraid this would be a UB, and the lock for reading is unavoidable.
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.
I thought UB should be fine as long as is_lastvalue_valid_
returns either true/false (was not expecting strong consistency here). As in one of the next few iterations, it would be true eventually. But have added the lock if it's causing confusion.
sdk/test/metrics/aggregation_test.cc
Outdated
ASSERT_TRUE(nostd::holds_alternative<std::vector<long>>(histogram_data.boundaries_)); | ||
EXPECT_EQ(nostd::get<long>(histogram_data.sum_), 0); | ||
EXPECT_EQ(histogram_data.count_, 0); | ||
EXPECT_NO_THROW(aggr.Aggregate(12l, {})); // lies in third bucket (indexed at 0) |
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.
The comments are not correct. also in DoubleHistogramAggregation
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.
Do you mean 12 does lie in 3rd bucket? The default buckets here are: [-infinity to 0], [0 to 5], [5 to10], [10 to 25] , and so on (refer - https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#histogram-aggregation ). So 12 will lie in the third bucket.
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.
No I mean indexed at 0
part, this should be 2 or I'm getting sth wrong here?
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.
Yes, have only kept the bucket number now. Thanks for noticing it.
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.
Thanks for the PR. LGTM
{ | ||
namespace metrics | ||
{ | ||
class InstrumentMonotonicityAwareAggregation |
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.
Seems InstrumentMonotonicityAwareAggregation
should be a subclass of Aggretation
?
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.
Yes or else we can also move this functionality within the Aggregation class. I thought of keeping it a separate class as not sure right now how to use it for Asynchronous aggregation. We can refactor this later once we have more complete implementation.
Fixes #1090
Changes
Splitting #1173 into smaller PRs for ease of review. This PR adds aggregation for Sum, LastValue, and Histogram.
Implementation is based on the specs here:
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#aggregation
Please provide a brief description of the changes here.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes