Support exponential histograms in the prometheus bridge #5093
+239
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Support converting exponential histograms in the prometheus bridge. To use exponential histograms, users can enable the NativeHistogram... options when creating their prometheus histogram.
When prometheus native histograms are enabled, BOTH fixed-bucket and native histograms are available in the protobuf in a "combined" histogram format. Since we can only support one-or-the-other, we always use exponential histograms if they are available.
Alternatives
As an alternative, we could consider adding an option, like
WithExponentialHistograms()
to the bridge that a user would additionally need to enable to get exponential histograms. If the prometheus client decided in the future to enable native histograms by default, users of the bridge would suddenly start getting exponential histograms instead of fixed-bucket histograms. If their backend doesn't support native histograms, this would be breaking for them. If there was not a way to disable that behavior in the Prometheus client, they would be stuck.I have not implemented it here because we can always add it later if needed.
Implementation references
This follows the inverse of this specification: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/compatibility/prometheus_and_openmetrics.md#exponential-histograms.
It is also the inverse of the conversion here: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/translator/prometheusremotewrite/histograms.go
Thankfully, OTel doesn't have a min or max scale, so we don't have to handle scale up/scale down.
Future work
Exemplars on native histograms are not yet supported in the prometheus client. They were added to the protocol here: prometheus/client_model#80, but hasn't been released yet, and hasn't been implemented in the prometheus go client yet.
@bwplotka do you think we can/should rely on NativeHistogram.* options in HistogramOpts to determine whether users get an exponential vs fixed-bucket histogram? Or should we introduce our own option on the bridge to be safe.