Skip to content

Commit c83c5cc

Browse files
authored
resources: naive rendering for native histograms (#596)
Classic buckets are rendered as before, if there are any. If there are native buckets, a string version of the native histogram is rendered like Prometheus currently does. This approach also handles "dual use" histograms (both classic and native buckets). A histogram without any buckets is rendered as such, just with count and sum. Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
1 parent 35f23fc commit c83c5cc

4 files changed

Lines changed: 114 additions & 82 deletions

File tree

‎asset/assets_vfsdata.go‎

Lines changed: 65 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎handler/status.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import (
2626
"github.com/go-kit/log"
2727
"github.com/go-kit/log/level"
2828

29+
dto "github.com/prometheus/client_model/go"
2930
"github.com/prometheus/common/version"
31+
"github.com/prometheus/pushgateway/histogram"
3032
"github.com/prometheus/pushgateway/storage"
3133
)
3234

@@ -73,6 +75,16 @@ func Status(
7375
"base64": func(s string) string {
7476
return base64.RawURLEncoding.EncodeToString([]byte(s))
7577
},
78+
"formatHistogram": func(m *dto.Histogram) string {
79+
h, fh := histogram.NewModelHistogram(m)
80+
if h == nil {
81+
return fh.String()
82+
}
83+
return h.String()
84+
},
85+
"add": func(x, y int) int {
86+
return x + y
87+
},
7688
})
7789

7890
f, err := root.Open("template.html")

‎histogram/prometheus_model.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ func GetAPIFloatBuckets(h *model.FloatHistogram) []APIBucket[float64] {
132132
}
133133

134134
func makeBucket[BC model.BucketCount](bucket model.Bucket[BC]) APIBucket[BC] {
135-
boundaries := uint64(2) // Exclusive on both sides AKA open interval.
135+
boundaries := uint64(2) // () Exclusive on both sides AKA open interval.
136136
if bucket.LowerInclusive {
137137
if bucket.UpperInclusive {
138-
boundaries = 3 // Inclusive on both sides AKA closed interval.
138+
boundaries = 3 // [] Inclusive on both sides AKA closed interval.
139139
} else {
140-
boundaries = 1 // Inclusive only on lower end AKA right open.
140+
boundaries = 1 // [) Inclusive only on lower end AKA right open.
141141
}
142142
} else {
143143
if bucket.UpperInclusive {
144-
boundaries = 0 // Inclusive only on upper end AKA left open.
144+
boundaries = 0 // (] Inclusive only on upper end AKA left open.
145145
}
146146
}
147147
return APIBucket[BC]{

‎resources/template.html‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
</div>
5454
</div>
5555
</nav>
56-
5756
<div class="container-fluid" id="metrics-div">
5857
{{- $data := .}}
5958
{{- if eq (index .Flags "web.enable-admin-api") "true"}}
@@ -140,22 +139,43 @@ <h2 class="mb-0">
140139
</tr>
141140
</table>
142141
{{- else}}
142+
{{- $h := .Histogram}}
143143
{{- with .Histogram}}
144+
{{- $numBuckets := len .Bucket}}
145+
{{- $numNBuckets := add (len .PositiveSpan) (len .NegativeSpan)}}
144146
<table class="table table-striped table-bordered">
145-
{{- range .Bucket}}
147+
{{- if gt $numNBuckets 0}}
146148
<tr>
147-
<th scope="row">Sample values &le; {{value .GetUpperBound}}</th>
148-
<td>{{.GetCumulativeCount}}</td>
149-
</tr>
150-
{{- end}}
151-
<tr>
152-
<th scope="row">Total sample Count</th>
153-
<td>{{.GetSampleCount}}</td>
154-
</tr>
155-
<tr>
156-
<th scope="row">Sample Sum</th>
157-
<td>{{value .GetSampleSum}}</td>
149+
<th scope="row">Native Histogram representation</th>
150+
<td>{{formatHistogram $h}}</td>
158151
</tr>
152+
{{- end}}
153+
{{- if gt $numBuckets 0}}
154+
{{- range .Bucket}}
155+
<tr>
156+
<th scope="row">Sample values &le; {{value .GetUpperBound}}</th>
157+
<td>{{.GetCumulativeCount}}</td>
158+
</tr>
159+
{{- end}}
160+
<tr>
161+
<th scope="row">Total sample Count</th>
162+
<td>{{.GetSampleCount}}</td>
163+
</tr>
164+
<tr>
165+
<th scope="row">Sample Sum</th>
166+
<td>{{value .GetSampleSum}}</td>
167+
</tr>
168+
{{- end}}
169+
{{- if eq (add $numNBuckets $numBuckets) 0}}
170+
<tr>
171+
<th scope="row">Total sample Count</th>
172+
<td>{{.GetSampleCount}}</td>
173+
</tr>
174+
<tr>
175+
<th scope="row">Sample Sum</th>
176+
<td>{{value .GetSampleSum}}</td>
177+
</tr>
178+
{{- end}}
159179
</table>
160180
{{- end}}
161181
{{- end}}

0 commit comments

Comments
 (0)
⌂ 换网址