diff --git a/promql/value.go b/promql/value.go index cd36c9a7e9..861dba6ae4 100644 --- a/promql/value.go +++ b/promql/value.go @@ -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 { diff --git a/web/api/v1/api.go b/web/api/v1/api.go index 2669350e04..ca63927a4c 100644 --- a/web/api/v1/api.go +++ b/web/api/v1/api.go @@ -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 {