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.
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.
Would it be possible to add tags here?
| ], | |
| ], | |
| tags = [ | |
| "metrics", | |
| "test", | |
| ], |
| name = "aggregation_test", | ||
| srcs = [ | ||
| "aggregation_test.cc", | ||
| ], |
There was a problem hiding this comment.
| ], | |
| ], | |
| tags = [ | |
| "metrics", | |
| "test", | |
| ], |
|
|
||
| PointType LongLastValueAggregation::Collect() noexcept | ||
| { | ||
| if (!is_lastvalue_valid_) |
There was a problem hiding this comment.
Don't we need to protect is_lastvalue_valid_ here?
There was a problem hiding this comment.
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.
I'm afraid this would be a UB, and the lock for reading is unavoidable.
There was a problem hiding this comment.
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.
| 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.
The comments are not correct. also in DoubleHistogramAggregation
There was a problem hiding this comment.
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.
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.
Yes, have only kept the bucket number now. Thanks for noticing it.
| { | ||
| namespace metrics | ||
| { | ||
| class InstrumentMonotonicityAwareAggregation |
There was a problem hiding this comment.
Seems InstrumentMonotonicityAwareAggregation should be a subclass of Aggretation?
There was a problem hiding this comment.
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.mdupdated for non-trivial changes