Precomputed Sum aggregation should filter on collection #4217
Labels
area:metrics
Part of OpenTelemetry Metrics
bug
Something isn't working
pkg:SDK
Related to an SDK package
Milestone
Description
Using an asynchronous instrument that records two measurements for the same attribute set will correctly only report the last value (the value is interpreted as the pre-computed sum value). However, if an attribute filter is applied to the SDK and it affects the measurements the values are then added.
Environment
Steps To Reproduce
Using the following code:
and running ...
$ go run . logins: 2 (admin=true,user=Alice)
Correctly produces a value of
2
for the full attribute set ((admin=true,user=Alice)
).If a view is added to filter out the attribute where the key is
admin
:and running:
$ go run . logins: 3 (user=Alice)
Produces a value of
3
for the reduced attribute set ((user=Alice)
).Expected behavior
The second example with a view should produce the same value as the first:
2
. E.g.$ go run . logins: 2 (user=Alice)
Proposal
This behavior results from different treatment of values measured by the pre-computed sum aggregator:
opentelemetry-go/sdk/metric/internal/sum.go
Lines 183 to 216 in 844b107
The non-filtered values are treated as pre-computed, but the filtered values are all added to the non-filtered. There is no state tracking for the filtered value.
The correct behavior is to set all values, filtered or non-filtered, as the last value measured and when they are finally collected add all filtered values together and add to the non-filtered value.
The can be done by updating the implementation to not filter on measurement aggregation, but instead filtering on the collection operation.
By filtering during collection, it will produce the correct data, but it should also reduce the existing complexity around the pre-computed sums and filtering.
Design Issues
This means that using an attribute filter to reduce unbounded cardinality of attributes will not be effective against pre-computed sums.
This flaw is going to be a consequence of needing to produce the correct data regardless of the algorithm used.
Alternatives
Alternatively the existing design on filtering on aggregation input can be preserved and the
filtered
map can track all the raw unfiltered attribute sets that will eventually be filtered.This approach will produce the same end result, but it will persist or add to the complex filtering logic already associated with the pre-computed sum aggregation.
The text was updated successfully, but these errors were encountered: