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

feat(sdk-metrics-base): implement min/max recording for Histograms #3032

Merged
merged 14 commits into from
Jun 24, 2022

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented Jun 10, 2022

Which problem is this PR solving?

The Metrics SDK spec defines an option RecordMinMax to turn on or off min and max recordings on Explicit Bucket Histogram Aggregations.

This PR:

  • adds min/max recording to Histograms
  • makes this configurable via the ExplicitBucketHistogramAggregation
  • updates the proto to 0.18 so that min and max can be exported

Fixes #3010

Type of change

How Has This Been Tested?

  • Unit tests
  • Manual testing with different collector versions

Checklist:

  • Followed the style guidelines of this project
  • Unit tests have been added
  • Documentation has been updated

@codecov
Copy link

codecov bot commented Jun 10, 2022

Codecov Report

Merging #3032 (67785b1) into main (fa295a3) will decrease coverage by 0.00%.
The diff coverage is 93.10%.

@@            Coverage Diff             @@
##             main    #3032      +/-   ##
==========================================
- Coverage   92.65%   92.64%   -0.01%     
==========================================
  Files         187      187              
  Lines        6178     6198      +20     
  Branches     1304     1314      +10     
==========================================
+ Hits         5724     5742      +18     
- Misses        454      456       +2     
Impacted Files Coverage Δ
...telemetry-sdk-metrics-base/src/aggregator/types.ts 100.00% <ø> (ø)
...tal/packages/otlp-transformer/src/metrics/types.ts 100.00% <ø> (ø)
...metry-sdk-metrics-base/src/aggregator/Histogram.ts 96.87% <90.90%> (-3.13%) ⬇️
...telemetry-sdk-metrics-base/src/view/Aggregation.ts 98.46% <100.00%> (ø)
.../packages/otlp-transformer/src/metrics/internal.ts 98.14% <100.00%> (+0.07%) ⬆️

Copy link
Member

@dyladan dyladan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really makes me wish we had gone the route of having the histogram delta by default but oh well. Overall LGTM and i'm glad to have this feature in

@legendecas
Copy link
Member

Really makes me wish we had gone the route of having the histogram delta by default but oh well.

@dyladan I'm not getting what you are pointing at. Would you mind elaborating on this? I'd be happy to find out if we can do it in a better way.

Comment on lines 132 to 158
if(histogram.hasMinMax){
return {
attributes: toAttributes(dataPoint.attributes),
bucketCounts: histogram.buckets.counts,
explicitBounds: histogram.buckets.boundaries,
count: histogram.count,
sum: histogram.sum,
min: histogram.min,
max: histogram.max,
startTimeUnixNano: hrTimeToNanoseconds(dataPoint.startTime),
timeUnixNano: hrTimeToNanoseconds(
dataPoint.endTime
),
};
} else {
return {
attributes: toAttributes(dataPoint.attributes),
bucketCounts: histogram.buckets.counts,
explicitBounds: histogram.buckets.boundaries,
count: histogram.count,
sum: histogram.sum,
startTimeUnixNano: hrTimeToNanoseconds(dataPoint.startTime),
timeUnixNano: hrTimeToNanoseconds(
dataPoint.endTime
),
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this if/else? If min and max are not there won't they simply be undefined?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this. For some reason I thought that this was necessary, but it is not. 😅
I simplified this in b23b6f1. 🙂
min/max are not undefined when they get here, though (they are Inf and -1), so I still need to check hasMinMax and set undefined explicitly.

@dyladan
Copy link
Member

dyladan commented Jun 21, 2022

Really makes me wish we had gone the route of having the histogram delta by default but oh well.

@dyladan I'm not getting what you are pointing at. Would you mind elaborating on this? I'd be happy to find out if we can do it in a better way.

Sorry I confused myself a bit while reviewing. I was looking to see where merge is called and got a bit lost in the details of the SDK. I don't remember what I was specifically looking at when I made that comment sorry.

@pichlermarc
Copy link
Member Author

Really makes me wish we had gone the route of having the histogram delta by default but oh well.

@dyladan I'm not getting what you are pointing at. Would you mind elaborating on this? I'd be happy to find out if we can do it in a better way.

Look like it's related to the way diff() is handled in this PR. Since we're diffing two cumulative histograms, there's no way to get the delta min/max without resetting min/max after each diff(). 🙁

It was very elegant before, but now it's kind of counfusing. 😓

@dyladan dyladan added this to the Metrics GA milestone Jun 22, 2022
@legendecas
Copy link
Member

@pichlermarc I can not edit this PR so please update the PR with the latest main branch so that we can land this one :).

@dyladan dyladan merged commit d2de661 into open-telemetry:main Jun 24, 2022
@dyladan dyladan deleted the min-max branch June 24, 2022 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Histogram min/max support
4 participants