-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[1617] Add ConstnativeHistogram #1654
base: main
Are you sure you want to change the base?
Conversation
85c4d89
to
473720d
Compare
@ArthurSens Maybe you can take a look at this PR. |
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.
Thanks for working on this! I've added a few comments but I'm not a native histogram expert, it would be nice if @beorn7 or @krajorama could also take a look here.
question: Have you tried using your commit on OTel's side to make sure you can translate their format into ours?
Will have a look ASAP (which won't be before next week, sorry). |
96eeddd
to
ad21924
Compare
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.
Hi, I understand the use case of wanting to expose OTEL exponential histograms from the Prometheus exporter in the collector. How would you use it actually? Constantly register and unregister the metric to update the exposed values? Or just use it's Write()
method to get to the data?
In any case, the naming is going to be weird as you're not actually using it as a const :)
If I understand correctly, currently it will only work for counter histograms, not gauge histograms due to limitations in client_golang.
I'm a little afraid of abuse of this interface, but don't see true stoppers for now, will consult @beorn7 .
prometheus/histogram.go
Outdated
zeroBucket uint64 | ||
} | ||
|
||
func NewConstNativeHistogram(desc *Desc, count uint64, sum float64, postiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64, |
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.
Needs doc string to explain the arguments and the fact that this is exposed as a counter type histogram, treated as a counter on scrape.
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.
In fact, I do actually think that exposing a gauge histogram will be one of the common use cases for using this function. So let's maybe add a bool argument here so that the user can switch between counter and gauge histogram.
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.
Style nit: Prometheus code usually does a line break after the opening parenthesis in case of multiline argument lists.
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.
Tried this. Wouldn't this blow up the argument list? Is it better to create a seperate a constNaticveGuageHistogram ?
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.
I'm still unclear about including a gauge histogram
. As per my understanding , we will need to add postiveBuckets, negativeBuckets of type map[int]float64 as an argument (or use a generic parameter). Adding a boolean parameter will not suffice.
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.
It sounds like you are thinking about a float histogram. That's something we might want to add later (ideally together with the option of creating classic float histograms). However, the use case for float histograms in instrumentation is very rare.
I am in fact talking about a gauge histogram. It merely requires to set a different MetricType
in the MetricFamily
. However, I've just realized that we currently have no way of communicating the difference of counter histogram (i.e. the "normal" histogram) and gauge histogram during metrics collection. For that, we needed Desc
to have a metric type field (which was the plan for quite some time).
So I'm pretty sure we cannot solve this problem in this PR, because it needed too much re-architecting.
But if we assume that the difference between counter histogram and gauge histogram will be in the Desc
, we actually don't need a bool parameter here, but just have to later allow the option of creating "typed" Desc
s.
In conclusion, let's not do gauge histograms right now.
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.
That's true. I was indeed confused about a float histogram and gauge histogram.
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.
Thanks @shivanthzen for tackling this, and thanks for the review so far @krajorama and @ArthurSens . If I haven't commented on a previous review comment, I agree with it. :)
prometheus/histogram.go
Outdated
zeroBucket uint64 | ||
} | ||
|
||
func NewConstNativeHistogram(desc *Desc, count uint64, sum float64, postiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64, |
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.
In fact, I do actually think that exposing a gauge histogram will be one of the common use cases for using this function. So let's maybe add a bool argument here so that the user can switch between counter and gauge histogram.
prometheus/histogram.go
Outdated
zeroBucket uint64 | ||
} | ||
|
||
func NewConstNativeHistogram(desc *Desc, count uint64, sum float64, postiveBuckets, negativeBuckets map[int]int64, zeroBucket uint64, |
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.
Style nit: Prometheus code usually does a line break after the opening parenthesis in case of multiline argument lists.
Thanks for the comments. I'll resolve them this weekend |
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.
I had just a quick look today :)
prometheus/histogram.go
Outdated
if err := validateCount(count, negativeBuckets, positiveBuckets, zeroBucket); err != nil { | ||
return nil, err | ||
} |
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.
Do we need to validate Sum as well?
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.
Not really. Sum could by anything. I mean, there could be consistency checks like the sum cannot be negative if there are only positive observations, or the sum has to be zero without any observations, and many more. But I don't know if that would be very helpful. We should only check for conditions that would make Prometheus reject the histogram upon ingestion.
prometheus/histogram.go
Outdated
return nil | ||
} | ||
|
||
func makeBucketsAny(buckets map[int]int64) ([]*dto.BucketSpan, []int64) { |
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.
hey, could you clarify what Any
means here?
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.
Probably "positive or negative".
I would just call it makeBuckets
.
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.
+1 for makeBuckets
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.
Hmm, makebuckets alreadyexists in the namespace. I could do makeBucketfrommap
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.
Looks good in general.
Despite the frequent nit pickings about naming etc., I haven't yet checked the technical correctness very deeply yet (although it looks fine as far as I can see right now).
return nil | ||
} | ||
|
||
func NewConstNativeHistogram( |
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.
Needs doc comment.
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.
We should also have a version MustNewConstNativeHistogram
(which wraps NewConstNativeHistogram
, panicking where NewConstNativeHistogram
would have returned an error).
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 the docstring
prometheus/histogram.go
Outdated
if err := validateCount(count, negativeBuckets, positiveBuckets, zeroBucket); err != nil { | ||
return nil, err | ||
} |
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.
Not really. Sum could by anything. I mean, there could be consistency checks like the sum cannot be negative if there are only positive observations, or the sum has to be zero without any observations, and many more. But I don't know if that would be very helpful. We should only check for conditions that would make Prometheus reject the histogram upon ingestion.
prometheus/histogram.go
Outdated
return nil | ||
} | ||
|
||
func makeBucketsAny(buckets map[int]int64) ([]*dto.BucketSpan, []int64) { |
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.
Probably "positive or negative".
I would just call it makeBuckets
.
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.
LGTM, but let's wait for an approval from Beorn or Krajo as well
Thanks for the work!
Oh, looks like some commits weren't signed and there's one test failing 🤔 The test seems to be flaky, it's also failing in other PRs |
I can sign the commits once the PR is approved, It seems signing will need a force push |
Yes, it changes the commits and therefore needs a force-push. However, it is essential to sign before approval. That's kind of the point. |
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.
Thanks for addressing the feedback.
I have no realized something about exemplars we had not discussed before.
I have also realized we cannot do gauge histograms right now. Needs more discussion and planning, which is out of scope of this PR.
afbdefd
to
f900abb
Compare
Force pushed with signed commits. |
356875e
to
698a313
Compare
@shivanthzen, looks like you accidentally added unrelated commits to your PR, could you keep only the ones that you've authored here? |
Signed-off-by: Shivanth <[email protected]>
Co-authored-by: Arthur Silva Sens <[email protected]> Signed-off-by: Shivanth MP <[email protected]> Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
Signed-off-by: Shivanth <[email protected]>
698a313
to
d7d3022
Compare
@ArthurSens Removed other commits from the branch |
Fixes: #1617
Add exported ConstNativeHistogram - this can be used to build native histograms if one already has the relevant data without calling the observe function. A viable use case is while converting exponential histograms to nativehistograms.