Skip to content

exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms.#777

Merged
dashpole merged 31 commits into
GoogleCloudPlatform:mainfrom
franciscovalentecastro:main
Mar 4, 2024
Merged

exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms.#777
dashpole merged 31 commits into
GoogleCloudPlatform:mainfrom
franciscovalentecastro:main

Conversation

@franciscovalentecastro
Copy link
Copy Markdown
Contributor

@franciscovalentecastro franciscovalentecastro commented Dec 11, 2023

This PR adds the following functionality to the exporter/metric :

  • Added support to export ExponentialHistogram.
  • Added support to export TypedValue Distribution (either Histogram and ExponentialHistogram) with exemplars.
  • Adds exponential_histogram example with a dashboard.json to visualize it.

Details :

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 11, 2023

Codecov Report

Attention: Patch coverage is 4.21053% with 91 lines in your changes are missing coverage. Please review.

Project coverage is 59.79%. Comparing base (87124ac) to head (1590aff).

Files Patch % Lines
exporter/metric/metric.go 4.21% 89 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #777      +/-   ##
==========================================
- Coverage   60.73%   59.79%   -0.95%     
==========================================
  Files          56       56              
  Lines        5649     5743      +94     
==========================================
+ Hits         3431     3434       +3     
- Misses       2070     2159      +89     
- Partials      148      150       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@franciscovalentecastro franciscovalentecastro changed the title [Draft] exporter/metric: Add support to export Distribution with Exemplars. [Draft] exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms. Dec 12, 2023
@dashpole
Copy link
Copy Markdown
Contributor

The feature has been implemented in the OTel SDK: https://github.com/open-telemetry/opentelemetry-go/blob/main/sdk/metric/internal/x/README.md#exemplars

Let me know if you are interested in contributing this.

@franciscovalentecastro franciscovalentecastro changed the title [Draft] exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms. exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms. Feb 23, 2024
@franciscovalentecastro franciscovalentecastro marked this pull request as ready for review February 23, 2024 21:49
@franciscovalentecastro franciscovalentecastro requested a review from a team as a code owner February 23, 2024 21:49
Comment thread exporter/metric/metric.go
func toDistributionExemplar[N int64 | float64](Exemplars []metricdata.Exemplar[N]) []*distribution.Distribution_Exemplar {
var exemplars []*distribution.Distribution_Exemplar
for _, e := range Exemplars {
exemplars = append(exemplars, &distribution.Distribution_Exemplar{Value: float64(e.Value), Timestamp: timestamppb.New(e.Time)})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verified Distribution_Exemplar only supports float64 values : https://pkg.go.dev/google.golang.org/genproto/googleapis/api/distribution#Distribution_Exemplar

Comment thread exporter/metric/metric.go Outdated
positiveBucketCounts := 0
growthFactor := math.Exp2(math.Exp2(-float64(hist.Scale)))
for i, v := range hist.PositiveBucket.Counts {
counts[i] = int64(v)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Opentelemetry Exponential Buckets support Negative Indices too, but AFAIU the TypedValue Exponential Buckets only support Positive Indices.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thats correct. All negative observations and zero observations should be in the underflow bucket. See

underflow := point.ZeroCount()
negativeBuckets := point.Negative().BucketCounts()
for i := 0; i < negativeBuckets.Len(); i++ {
underflow += negativeBuckets.At(i)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I used as reference the implementation of collector/metrics.go : exponentialHistogramPoint to reimplement all the mentioned details of expHistToDistribution in this review, but using the correct types and methods.

google.golang.org/protobuf v1.31.0 // indirect
)

replace github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric => ../../../exporter/metric
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added this to pick current changes (before merging) to metric.go.

Comment thread example/metric/exponential_histogram/example.go Outdated
Comment thread example/metric/exponential_histogram/example.go Outdated
Comment thread exporter/metric/metric.go Outdated
Comment thread exporter/metric/metric.go Outdated
positiveBucketCounts := 0
growthFactor := math.Exp2(math.Exp2(-float64(hist.Scale)))
for i, v := range hist.PositiveBucket.Counts {
counts[i] = int64(v)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thats correct. All negative observations and zero observations should be in the underflow bucket. See

underflow := point.ZeroCount()
negativeBuckets := point.Negative().BucketCounts()
for i := 0; i < negativeBuckets.Len(); i++ {
underflow += negativeBuckets.At(i)
}

Comment thread exporter/metric/metric.go Outdated
@franciscovalentecastro
Copy link
Copy Markdown
Contributor Author

franciscovalentecastro commented Mar 1, 2024

@dashpole Update on last changes to PR :

  • Added dashboard.json to visualize the exponential_histogram example. This may conflict/be confused with the other dashboard.json in the above folder. Is this the correct place and/or naming ? (I imported manually to GCM and it works correctly).
  • Fixed the open comments.
  • Added a TODO for the missing []attachments to the exemplar exporting (AFAIU, this will add the span_id, etc, though i'm not very knowledgable about how to do this correctly).

Comment thread example/metric/exponential_histogram/example.go Outdated
Comment thread example/metric/exponential_histogram/example.go Outdated
Comment thread exporter/metric/metric.go
franciscovalentecastro and others added 4 commits March 4, 2024 10:21
Co-authored-by: David Ashpole <dashpole@google.com>
Signed-off-by: Francisco Valente Castro <1435136+franciscovalentecastro@users.noreply.github.com>
@dashpole
Copy link
Copy Markdown
Contributor

dashpole commented Mar 4, 2024

Follow-up tasks required:

  • README for the example
  • Unit testing
  • Exemplar attachments
  • SumOfSquaredDeviations

@franciscovalentecastro can you add the README? You are welcome to work on the other tasks as well if you have time. Otherwise, I'll make sure they get done. Just let me know which you'd like to tackle

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.

2 participants