Skip to content
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

Clarify SumAggregation on asynchronous counter #2187

Closed
legendecas opened this issue Dec 3, 2021 · 2 comments · Fixed by #2208
Closed

Clarify SumAggregation on asynchronous counter #2187

legendecas opened this issue Dec 3, 2021 · 2 comments · Fixed by #2208
Assignees
Labels
spec:metrics Related to the specification/metrics directory

Comments

@legendecas
Copy link
Member

legendecas commented Dec 3, 2021

What are you trying to achieve?

In the SDK spec on DefaultAggregation, it suggests that for AsynchronousCounter a default SumAggregation is used for aggregation.

Instrument Kind Selected Aggregation
Counter Sum Aggregation
Asynchronous Counter Sum Aggregation
UpDownCounter Sum Aggregation
Asynchrounous UpDownCounter Sum Aggregation
Asynchronous Gauge Last Value Aggregation
Histogram Histogram Aggregation

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#default-aggregation

When implementing the SumAggregation for the asynchronous counter, I found that in the SumAggregation:

SumAggregation informs the SDK to collect:
The arithmetic sum of Measurement values.
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk.md#sum-aggregation

Whilst to the asynchronous counter, the Measurement values mean:

The callback function is responsible for reporting the Measurements.
Note: Unlike Counter.Add() which takes the increment/delta value, the callback function reports the absolute value of the counter.
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#asynchronous-counter

That's been said, the Measurement values in asynchronous counters are absolute values and not increments. To SumAggregation, the arithmetic sum of Measurement values of asynchronous counters doesn't seem to be meaningful.

This issue also applies to the Asynchronous UpDownCounter.

@legendecas legendecas added the spec:metrics Related to the specification/metrics directory label Dec 3, 2021
@jsuereth
Copy link
Contributor

jsuereth commented Dec 6, 2021

This is a good callout.

In the Java (early) prototype I actually had two types of measurements: Delta + Cumulative, where Async instruments (and Histogram) provided Cumulative measurements and Sync *Counter provided Delta measurements. This helped clarify what aggregation should do by default when it sees these measurements.

However, one thing that may not be clear, is that Sum-Aggregation is meaningful in the presence of Views. If I configure a View that removes a label from measurements of Async instruments, then I need to "sum" together any measurements I'm "joining" when removing the label.

So a quick table of Instrument => Measurement Type => Default Aggregation:

Instrument Measurement Type Default Aggregation
Async* Gauge Cumulative Last Value
Async* Counter Cumulative Sum
Async* UpDownCounter Cumulative Sum
Histogram Cumulative Explicit Bucket HIstogram
Counter Delta Sum
UpDownCounter Delta Sum

So, in all these cases, View can muck with how many measurements are seen. The Aggregation determines what to do, and it's the same regardless of measurement type. Might be worth a more in-depth discussion.

@jmacd jmacd assigned jmacd and unassigned jsuereth Dec 7, 2021
@jmacd
Copy link
Contributor

jmacd commented Dec 7, 2021

I thought this topic had been covered in the supplementary guidelines, https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/supplementary-guidelines.md, but I see that no such example is given. I will take this issue to update the guidelines to explicitly cover removal of an attribute from a cumulative counter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec:metrics Related to the specification/metrics directory
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants