mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Histogram: Do not render empty buckets in JSON output
While empty buckets can make sense in the internal representation (by joining spans that would otherwise need more overhead for separate representation), there are no spans in the JSON rendering. Therefore, the JSON should not contain any empty buckets, since any buckets not included in the output counts as empty anyway. This changes both the inefficient MarshalJSON implementation as well as the jsoniter implementation. Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
parent
61d6d1df18
commit
d16b314b72
|
@ -146,6 +146,9 @@ func (p Point) MarshalJSON() ([]byte, error) {
|
|||
it := p.H.AllBucketIterator()
|
||||
for it.Next() {
|
||||
bucket := it.At()
|
||||
if bucket.Count == 0 {
|
||||
continue // No need to expose empty buckets in JSON.
|
||||
}
|
||||
boundaries := 2 // Exclusive on both sides AKA open interval.
|
||||
if bucket.LowerInclusive {
|
||||
if bucket.UpperInclusive {
|
||||
|
|
|
@ -1802,13 +1802,16 @@ func marshalHistogram(h *histogram.FloatHistogram, stream *jsoniter.Stream) {
|
|||
bucketFound := false
|
||||
it := h.AllBucketIterator()
|
||||
for it.Next() {
|
||||
bucket := it.At()
|
||||
if bucket.Count == 0 {
|
||||
continue // No need to expose empty buckets in JSON.
|
||||
}
|
||||
stream.WriteMore()
|
||||
if !bucketFound {
|
||||
stream.WriteObjectField(`buckets`)
|
||||
stream.WriteArrayStart()
|
||||
}
|
||||
bucketFound = true
|
||||
bucket := it.At()
|
||||
boundaries := 2 // Exclusive on both sides AKA open interval.
|
||||
if bucket.LowerInclusive {
|
||||
if bucket.UpperInclusive {
|
||||
|
|
Loading…
Reference in a new issue