-
Notifications
You must be signed in to change notification settings - Fork 104
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
exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms. #777
exporter/metric: Add support to export Distribution with Exemplars and Exponential Histograms. #777
Conversation
Codecov ReportAttention: Patch coverage is
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. |
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. |
f1d62de
to
df2fd53
Compare
df2fd53
to
aa41056
Compare
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)}) |
There was a problem hiding this comment.
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
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) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
opentelemetry-operations-go/exporter/collector/metrics.go
Lines 989 to 993 in 87124ac
underflow := point.ZeroCount() | |
negativeBuckets := point.Negative().BucketCounts() | |
for i := 0; i < negativeBuckets.Len(); i++ { | |
underflow += negativeBuckets.At(i) | |
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
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) |
There was a problem hiding this comment.
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
opentelemetry-operations-go/exporter/collector/metrics.go
Lines 989 to 993 in 87124ac
underflow := point.ZeroCount() | |
negativeBuckets := point.Negative().BucketCounts() | |
for i := 0; i < negativeBuckets.Len(); i++ { | |
underflow += negativeBuckets.At(i) | |
} |
…t` as reference for `expHistToDistribution`.
@dashpole Update on last changes to PR :
|
Co-authored-by: David Ashpole <[email protected]> Signed-off-by: Francisco Valente Castro <[email protected]>
Follow-up tasks required:
@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 |
This PR adds the following functionality to the
exporter/metric
:ExponentialHistogram
.TypedValue
Distribution (eitherHistogram
andExponentialHistogram
) with exemplars.exponential_histogram
example with adashboard.json
to visualize it.Details :
Exemplar
to metricdata package open-telemetry/opentelemetry-go#3849 added theExemplar
data type and theExemplars
field to aHistogramDataPoint
.Exemplar
sampling support.