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 for Histograms #2657

Conversation

utpilla
Copy link
Contributor

@utpilla utpilla commented Nov 22, 2021

Partially fixes #2633

Changes

  • Added a new class HistogramMeasurements for Hisotgram related data
  • Added new public methods in MetricPoint: GetBucketCounts, GetExplicitBounds, GetHistogramCount, and GetHistogramSum

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 22, 2021 08:17
@codecov
Copy link

codecov bot commented Nov 22, 2021

Codecov Report

Merging #2657 (188d377) into main (a7129d8) will decrease coverage by 0.01%.
The diff coverage is 84.48%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2657      +/-   ##
==========================================
- Coverage   81.33%   81.32%   -0.02%     
==========================================
  Files         246      247       +1     
  Lines        8659     8670      +11     
==========================================
+ Hits         7043     7051       +8     
- Misses       1616     1619       +3     
Impacted Files Coverage Δ
...tryProtocol/Implementation/MetricItemExtensions.cs 49.29% <0.00%> (-0.71%) ⬇️
src/OpenTelemetry/Metrics/MetricPoint.cs 88.88% <94.73%> (-1.63%) ⬇️
...ometheus/Implementation/PrometheusSerializerExt.cs 100.00% <100.00%> (ø)
src/OpenTelemetry/Metrics/HistogramMeasurements.cs 100.00% <100.00%> (ø)
...ZPages/Implementation/ZPagesExporterEventSource.cs 62.50% <0.00%> (+6.25%) ⬆️

Copy link
Member

@joaopgrassi joaopgrassi left a comment

Choose a reason for hiding this comment

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

Nice! This looks so much better 😀. Just left some minor comments.

}
else
{
throw new InvalidOperationException($"{nameof(this.GetBucketCounts)} is not supported for this metric type.");
Copy link
Member

Choose a reason for hiding this comment

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

Should we really throw here? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

If we do want to throw, NotSupportedException is probably more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should throw here. If we don't there would be no way for exporters to know if they are working correctly as they would just get some default values which is not the actual metric value.

Assert.Null(histogramPoint.ExplicitBounds);
Assert.Equal(7, count);

Assert.Throws<InvalidOperationException>(() => histogramPoint.GetBucketCounts());
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 we should really evaluate if we want to throw in these getters, as this might be unexpected. Specially since now the behavior is changed.

}
else
{
throw new InvalidOperationException($"{nameof(this.GetHistogramSum)} is not supported for this metric type.");
Copy link
Member

Choose a reason for hiding this comment

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

Whatever we define (throw or just a log), I think it would be good to log the aggType or the metric type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AggType is private. We can create a mapping of AggType to MetricType and add that here. This could be done in a follow-up PR.

{
if (this.aggType == AggregationType.Histogram || this.aggType == AggregationType.HistogramSumCount)
{
return this.histogramMeasurements.Count;
Copy link
Member

Choose a reason for hiding this comment

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

we can simply use the long and double values from MetricPoint itself. No need to add them to HistogramMeasurements.

Copy link
Member

Choose a reason for hiding this comment

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

@CodeBlanch was planning to see if we can custom layout to overlap the long/double field. That'd mean we'd be able to still need one of them inside HistogramMeasurement.

Copy link
Member

Choose a reason for hiding this comment

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

can be addressed as a follow up.

OpenTelemetry.Metrics.MetricPoint.DoubleValue.get -> double
OpenTelemetry.Metrics.MetricPoint.EndTime.get -> System.DateTimeOffset
OpenTelemetry.Metrics.MetricPoint.ExplicitBounds.get -> double[]
OpenTelemetry.Metrics.MetricPoint.GetBucketCounts() -> long[]
Copy link
Member

Choose a reason for hiding this comment

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

as a follow up we need to do something similar to whats done for Tags. (readonly something)

@@ -133,6 +133,9 @@ public static int WriteMetric(byte[] buffer, int cursor, Metric metric)
}

// Histogram sum
var count = metricPoint.GetHistogramCount();
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to declare these variables here, or just use them inline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this in #2664

Copy link
Member

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM with minor suggestions/comments.

@cijothomas cijothomas merged commit 69ef5f8 into open-telemetry:main Nov 23, 2021
@utpilla utpilla deleted the utpilla/Update-MetricPoint-For-Histograms 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.

MetricPoint public API changes
5 participants