-
Notifications
You must be signed in to change notification settings - Fork 468
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
resources: for native histograms show String() output in the UI #596
Conversation
resources/template.html
Outdated
<tr> | ||
<th scope="row">Sample Sum</th> | ||
<td>{{value .GetSampleSum}}</td> | ||
<td>{{.String}}</td> |
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.
The problem here is that this is just the string representation of the protobuf, which is not very human-readable.
There should be code somewhere already to convert a protobuf histogram to model.histogram.Histogram
or model.histogram.FloatHistogram
. Maybe we can utilize it to get a display here that looks similar to what we currently get in the Prometheus UI itself?
I'm in a hurry right now, but I can help you to find this conversion code if you cannot find it easily.
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.
No worries, I'll go dig. Thanks for the pointer.
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.
So the code that does this during scraping is unfortunately too tightly coupled with the parser:
https://github.com/prometheus/prometheus/blob/980e2895a2eebb9664af104e6d4e19932cc74432/model/textparse/protobufparse.go#L173-L214
Maybe you could extract a separate ProtoToHistogram(*dto.Histogram) (*histogram.Histogram, *histogram.FloatHistogram)
from that code (to be used there and then in the PGW, too).
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.
Or maybe not. In prometheus/prometheus, we use Gogo protobuf, in prometheus/pushgateway, we use the official Go protobuf library. So the dto.Histogram types are actually different.
I would just write the conversion code proto -> histogram.Histogram here in PGW for now. Depending on how long it is and where it is actually used, we can then move it somewhere else if needed.
yes indeed, hoping to have an update next week. |
e2ad8a6
to
1a206b5
Compare
Ok better late then never I suppose. Wdyt @beorn7 |
1a206b5
to
898ee2c
Compare
Looks great at first glance. I'm on vacation this week, but this is high on my list once I'm back in action. |
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.
Maybe I'm missing something, but I think this can be simplified, see comments.
go.mod
Outdated
@@ -41,3 +41,5 @@ require ( | |||
google.golang.org/appengine v1.6.8 // indirect | |||
gopkg.in/yaml.v2 v2.4.0 // indirect | |||
) | |||
|
|||
replace github.com/prometheus/prometheus v0.48.1 => ../prometheus |
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 probably a leftover from your local dev environment?
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.
Indeed. Apologies... 🤦
handler/status.go
Outdated
return fmt.Sprintf("{ count:%v sum:%v %s}", | ||
m.GetSampleCountFloat(), | ||
m.GetSampleSum(), | ||
histogram.BucketsAsString[float64](histogram.GetAPIFloatBuckets(fh))) |
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.
Wouldn't return h.String()
do the same?
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 sure does 👍
handler/status.go
Outdated
return fmt.Sprintf("{ count:%v sum:%v %s}", | ||
m.GetSampleCount(), | ||
m.GetSampleSum(), | ||
histogram.BucketsAsString[uint64](histogram.GetAPIBuckets(h))) |
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.
And here fh.String()
?
handler/status.go
Outdated
m.GetSampleCountFloat(), | ||
m.GetSampleSum(), | ||
histogram.BucketsAsString[float64](histogram.GetAPIFloatBuckets(fh))) | ||
} else { |
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.
This else
isn't really needed, is it? (You return
in the if
block above.)
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 the else branch if we have a histogram and not a float 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.
But since you return
in line 81, the current else
branch is anyway only taken if h!=nil
.
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 mean, don't remove the whole block, just remove the } else {
and the closing }
below and outdent the content of the block.
histogram/prometheus_model.go
Outdated
@@ -79,6 +80,32 @@ func BucketsAsJson[BC model.BucketCount](buckets []APIBucket[BC]) [][]interface{ | |||
return ret | |||
} | |||
|
|||
func BucketsAsString[BC model.BucketCount](buckets []APIBucket[BC]) string { |
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.
As said above, I assume you can use the String
method of the model histograms, and then you don't need this helper.
resources/template.html
Outdated
{{- with .Histogram}} | ||
<table class="table table-striped table-bordered"> | ||
{{- range .Bucket}} | ||
{{- if le (len .Bucket) 0}} |
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.
So there is the case of a "dual histogram", which has both classic buckets and the sparse buckets of a native histogram, so that the scraper can decide what kind of histogram it wants to ingest (possibly even both). In that case, we should probably display both the classic and the native histogram, maybe with a <th scope="row">Native Histogram representation</th>
.
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 see, so would then make sense to format classic histograms if there are classic buckets and native histograms if Schema != nil
?
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.
Schema is just an int32, so it never can be nil.
I would render a classic histogram if there are classic buckets, and I would render a native histogram if there are native buckets. The only edge case is if there are no buckets at all, but then the rendering of either isn't much of a difference (just sum and count), so you could pick any one rendering for that.
898ee2c
to
a944780
Compare
resources/template.html
Outdated
{{- with .Histogram}} | ||
<table class="table table-striped table-bordered"> | ||
{{- range .Bucket}} | ||
{{- if .Schema }} |
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, I guess this essentially tests if .Schema
is 0 or not, which is not what we want. (Schema 0 is a perfectly valid schema for native histograms.) As said in another comment, let's simply test if there are native buckets.
resources/template.html
Outdated
</tr> | ||
{{- end}} | ||
{{- if gt (len .Bucket) 0}} |
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.
Or if there are neither native nor classic buckets (to handle the case of a bucket-less histogram).
Sorry for sprinkling the comments instead of doing them in one review. But I think I have addressed all questions now. |
If a histogram has no classic buckets, assume its a native histogram and render a string version of it like Prometheus currently does. Signed-off-by: Jan Fajerski <[email protected]>
a944780
to
92ab250
Compare
Not at all, thanks a lot for your patience. I think all comments are addressed 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.
Wonderful. Thanks a lot.
Note that I'll update the commit description to the current state of affairs when merging.
If a histogram has no classic buckets, assume its a native histogram and render the stringyfied version of it.
Fixes: #515