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

Update MetricPoint HistogramMeasurements #2664

Conversation

utpilla
Copy link
Contributor

@utpilla utpilla commented Nov 23, 2021

The objective of this PR is provide a way to abstract away the implementation detail of BucketCounts and ExplicitBounds and prevent the user from updating values for BucketCounts or ExplicitBounds.

This PR achieves it by providing an enumerator for MetricPoint.HistogramMeasurements which returns a new struct called HistogramMeasurement struct which has an ExplicitBound and BucketCount pair. The last pair has double.PositiveInfinity as the explicit bound.

This is built on @CodeBlanch 's idea: https://github.com/open-telemetry/opentelemetry-dotnet/compare/main...CodeBlanch:histogram-measurements?expand=1

Changes

  • Added an enumerator for Histograms that returns a HistogramMeasurement struct which has an ExplicitBound and BucketCount pair
  • Removed the public methods GetHistogramBucketCounts and GetHistogramExplicitBounds

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
  • Changes in public API reviewed

@utpilla utpilla requested a review from a team November 23, 2021 08:42
@codecov
Copy link

codecov bot commented Nov 23, 2021

Codecov Report

Merging #2664 (e41e84e) into main (cb4beda) will increase coverage by 0.03%.
The diff coverage is 91.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2664      +/-   ##
==========================================
+ Coverage   82.24%   82.28%   +0.03%     
==========================================
  Files         248      249       +1     
  Lines        8692     8703      +11     
==========================================
+ Hits         7149     7161      +12     
+ Misses       1543     1542       -1     
Impacted Files Coverage Δ
...tryProtocol/Implementation/MetricItemExtensions.cs 50.35% <0.00%> (+1.06%) ⬆️
src/OpenTelemetry/Metrics/MetricPoint.cs 87.71% <90.62%> (-1.17%) ⬇️
...ometheus/Implementation/PrometheusSerializerExt.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/Metrics/HistogramBucket.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/Metrics/HistogramBuckets.cs 100.00% <100.00%> (ø)
...ter.ZPages/Implementation/ZPagesActivityTracker.cs 97.14% <0.00%> (-2.86%) ⬇️

@utpilla utpilla mentioned this pull request Nov 23, 2021
2 tasks

namespace OpenTelemetry.Metrics
{
public readonly struct HistogramMeasurement
Copy link
Member

Choose a reason for hiding this comment

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

the term "measurement" is misleading as it refers to the raw data point reported through the API. https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#measurement

@@ -16,7 +16,7 @@

namespace OpenTelemetry.Metrics
{
internal class HistogramMeasurements
public class HistogramMeasurements
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public class HistogramMeasurements
public class HistogramMetricPoint

Copy link
Member

@reyang reyang Nov 23, 2021

Choose a reason for hiding this comment

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

Is this a HistogramMetricPoint or it is a HistogramMetricPointBucket?

If it is a HistogramMetricPoint, maybe it should inherit from MetricPoint?

Copy link
Member

Choose a reason for hiding this comment

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

HistogramMetricPointBucket is correct.

Copy link
Member

Choose a reason for hiding this comment

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

HistogramBuckets - this sounds better name.

Comment on lines 49 to 51
private readonly bool isHistogramSumCount;
private readonly int numberOfBuckets;
private readonly int numberofExplicitBounds;
Copy link
Member

Choose a reason for hiding this comment

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

If you look at the original one I did, I had a Count on the parent class which I used in MoveNext. The reason for that is it is better for perf to keep structs as small as possible. What I don't know is if that size-reduction provides more perf than caching these values in the struct to reference in each MoveNext invocation. Might be worth measuring and possibly adjusting (could be a follow-up).

At the least, I think we can remove bool isHistogramSumCount because this.numberOfBuckets will be 0 in that case so MoveNext will know to exit. Basically...

            public bool MoveNext()
            {
                if (this.index < this.numberOfBuckets)

...should be enough (I think)?

Copy link
Contributor Author

@utpilla utpilla Nov 23, 2021

Choose a reason for hiding this comment

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

I have removed isHistogramSumCount. I will do the benchmarking for size-reduction vs caching later on.

throw new NotSupportedException($"{nameof(this.GetBucketCounts)} is not supported for this metric type.");
}
}
public readonly HistogramMeasurements HistogramMeasurements { get; }
Copy link
Member

Choose a reason for hiding this comment

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

Just typing my understanding:

MetricPoint.GetHistogramSum, GetHistogramCount is used to retrieve sum/count of Histogram. (always expected for a Histogram)

For Buckets (optional), it'll be retrieved from the HistogramBuckets.

Copy link
Member

Choose a reason for hiding this comment

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

I think that might change after the struct layout stuff I'm looking at. I think leave it like this for now and then we can revisit?

Copy link
Member

Choose a reason for hiding this comment

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

yes exactly.


namespace OpenTelemetry.Metrics
{
public class HistogramBuckets
Copy link
Member

Choose a reason for hiding this comment

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

since this class holds more than buckets (sum,count) , this name is probably not correct as well.
Lets iterate on it a bit more, after @CodeBlanch does custom struct layout as well.

Also from the datamodel, (
https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/datamodel.md#histogram), the term bucket seem to indicate a "triplet" with lower bound, upper bound, and the count. So might need another name.

Not blocking this PR, but needs addressing before stable.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

have some comments, to be addressed as follow ups.

Copy link
Member

@CodeBlanch CodeBlanch left a comment

Choose a reason for hiding this comment

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

LGTM

@cijothomas cijothomas merged commit 8d339bb into open-telemetry:main Nov 23, 2021
@utpilla utpilla deleted the utpilla/Update-MetricPoint-HistogramMeasurements branch November 3, 2023 22:11
@utpilla utpilla restored the utpilla/Update-MetricPoint-HistogramMeasurements branch November 3, 2023 22:11
@utpilla utpilla deleted the utpilla/Update-MetricPoint-HistogramMeasurements branch November 3, 2023 22:11
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.

4 participants