Skip to content

Conversation

@clementnuss
Copy link
Contributor

@clementnuss clementnuss commented May 16, 2025

as a follow-up/alternative to #45 and to solve #28, I'm starting this PR which adds support for OTLP histograms (the common le - static bucket type of histograms, not the complex exponential histograms/native histograms).

I know that VM focus is on log based buckets and really appreciate those, but having the opportunity to use "normal" histograms with this library would be greatly appreciated, as documented in #28

before working too much on this, I'd like to know whether support for normal / OTLP style buckets could be considered or not. I don't want to spend too much time on this PR if at the end @valyala @hagen1778 you decide against such a feature.

I'd also like to start a discussion on the name. I picked OTLPHistogram in reference to the histograms described in the OpenTelemetry Protocol, but perhaps the naming is bad.
[EDIT]: I think that CompatibleHistogram would make more sense than OTLPHistogram, had not thought about it until after I started implementing the functions

currently the basic functionality is implemented, and a testcase covers a simple usage. if there is a decision in favor of this PR, I will add the missing testcases and complete the implementation (add a function for custom buckets/upper bounds for example)

@clementnuss clementnuss marked this pull request as draft May 16, 2025 15:29
@clementnuss
Copy link
Contributor Author

clementnuss commented May 19, 2025

after a bit of reflexion, I believe it could also be possible to add a HistogramType field in here:

type Histogram struct {

that way we could have several implementations and depending on the histogram type use e.g. compatible/le-style or vmrange histograms. this would spare the choice of a new name for the histogram.

type HistogramType int

const (
	VictoriaMetrics = iota // or OTLP, Static, ...
        Compatible // or vmrange, log-based, VM, ...
)

@makasim makasim requested a review from hagen1778 May 20, 2025 14:09
@makasim makasim assigned hagen1778 and unassigned hagen1778 May 20, 2025
@hagen1778
Copy link
Contributor

Hello @clementnuss! Thanks for the initiative!

I think the rationale you provided, and the linked issues, all make sense. It would be beneficial for many users and for this package to support the traditional histograms with static list of buckets.
The only thing that concerns me is a picked name :) Reading the title about OTLP histogram type made me thinking me in another way. To me, the traditional histogram implementation is more like Prometheus type. Which, I believe, would be clearer to the users. Can we switch to this name if you agree?

after a bit of reflexion, I believe it could also be possible to add a HistogramType field in here:

To keep things simple, I'd suggest to have it as completely separate structure. It should be simpler from API and implementation perspective.

@clementnuss
Copy link
Contributor Author

My pleasure 🙃 I will change the name and complete the implementation.

which one works best?

  • PrometheusHistogram 🚀
  • CompatibleHistogram 👍🏼

@clementnuss clementnuss changed the title Feat/otlp histogram Prometheus compatible histograms May 28, 2025
cf VictoriaMetrics#28

test: add basic prometheus histogram test case
@clementnuss clementnuss force-pushed the feat/otlp_histogram branch from 860fd75 to d1c7648 Compare May 28, 2025 16:31
@clementnuss clementnuss marked this pull request as ready for review May 30, 2025 12:12
@clementnuss
Copy link
Contributor Author

clementnuss commented May 30, 2025

the PR is ready, let me know what needs to be fixed. I wasn't sure whether I should implement the set.Get... methods as they are less performant than .New... but I did implement those anyway, as they were implemented already for the other metric type.

@hagen1778 hagen1778 requested a review from f41gh7 May 30, 2025 14:05
@codecov
Copy link

codecov bot commented May 30, 2025

Codecov Report

Attention: Patch coverage is 93.87755% with 9 lines in your changes missing coverage. Please review.

Project coverage is 87.53%. Comparing base (704aa40) to head (5bfbe76).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
prometheus_histogram.go 95.65% 5 Missing ⚠️
set.go 87.50% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #93      +/-   ##
==========================================
+ Coverage   86.89%   87.53%   +0.64%     
==========================================
  Files          11       12       +1     
  Lines        1450     1597     +147     
==========================================
+ Hits         1260     1398     +138     
- Misses        142      149       +7     
- Partials       48       50       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@f41gh7 f41gh7 left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, please see few minor comments

@clementnuss clementnuss force-pushed the feat/otlp_histogram branch from 2541bd1 to 67ff519 Compare June 3, 2025 07:59
@clementnuss
Copy link
Contributor Author

@f41gh7 reviewing the coverage I noticed I had forgotten to delete the implementation of .Merge, I had only removed the tests. this is now fixed and I force-pushed.

Copy link
Contributor

@hagen1778 hagen1778 left a comment

Choose a reason for hiding this comment

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

Looks good! See some comments

Copy link
Contributor Author

@clementnuss clementnuss left a comment

Choose a reason for hiding this comment

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

did implement most of the suggestions. added a few questions as a result!

@clementnuss
Copy link
Contributor Author

and I already switched kubenurse to VictoriaMetrics/metrics go library with the prometheus histogram. seems that it works perfectly!
image

@hagen1778
Copy link
Contributor

Thanks for your contribution @clementnuss!
I hope to review&merge it this Friday.

* fix typos and comment formatting for godoc
* add ExponentialBuckets helper for exponential buckets, as it
seems to be most popular helper in prometheus sdk
* update obscure LinearBuckets test
* verify that neither ExponentialBuckets nor LinearBuckets produce non-increasing
buckets by enforcing `mustValidateBuckets` call
* fix example tests
* mention PrometheusHistogram in README
@hagen1778
Copy link
Contributor

@clementnuss please see review updates in 95d307d

Copy link
Contributor

@hagen1778 hagen1778 left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @clementnuss !

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.

3 participants