@@ -25,7 +25,6 @@ func marshalJSONIsEmpty(ptr unsafe.Pointer) bool {
2525 return false
2626}
2727
28- // from https://github.com/prometheus/prometheus/blob/main/util/jsonutil/marshal.go
2928// MarshalTimestamp marshals a point timestamp using the passed jsoniter stream.
3029func MarshalTimestamp (t int64 , stream * jsoniter.Stream ) {
3130 // Write out the timestamp as a float divided by 1000.
@@ -48,7 +47,6 @@ func MarshalTimestamp(t int64, stream *jsoniter.Stream) {
4847 }
4948}
5049
51- // from https://github.com/prometheus/prometheus/blob/main/util/jsonutil/marshal.go
5250// MarshalValue marshals a point value using the passed jsoniter stream.
5351func MarshalValue (v float64 , stream * jsoniter.Stream ) {
5452 stream .WriteRaw (`"` )
@@ -68,7 +66,8 @@ func MarshalValue(v float64, stream *jsoniter.Stream) {
6866 stream .WriteRaw (`"` )
6967}
7068
71- // adapted from https://github.com/prometheus/prometheus/blob/main/web/api/v1/api.go
69+ // MarshalHistogramBucket writes something like: [ 3, "-0.25", "0.25", "3"]
70+ // See MarshalHistogram to understand what the numbers mean
7271func MarshalHistogramBucket (b HistogramBucket , stream * jsoniter.Stream ) {
7372 stream .WriteArrayStart ()
7473 stream .WriteInt32 (b .Boundaries )
@@ -81,7 +80,29 @@ func MarshalHistogramBucket(b HistogramBucket, stream *jsoniter.Stream) {
8180 stream .WriteArrayEnd ()
8281}
8382
84- // adapted from https://github.com/prometheus/prometheus/blob/main/web/api/v1/api.go
83+ // MarshalHistogram writes something like:
84+ //
85+ // {
86+ // "count": "42",
87+ // "sum": "34593.34",
88+ // "buckets": [
89+ // [ 3, "-0.25", "0.25", "3"],
90+ // [ 0, "0.25", "0.5", "12"],
91+ // [ 0, "0.5", "1", "21"],
92+ // [ 0, "2", "4", "6"]
93+ // ]
94+ // }
95+ //
96+ // The 1st element in each bucket array determines if the boundaries are
97+ // inclusive (AKA closed) or exclusive (AKA open):
98+ //
99+ // 0: lower exclusive, upper inclusive
100+ // 1: lower inclusive, upper exclusive
101+ // 2: both exclusive
102+ // 3: both inclusive
103+ //
104+ // The 2nd and 3rd elements are the lower and upper boundary. The 4th element is
105+ // the bucket count.
85106func MarshalHistogram (h SampleHistogram , stream * jsoniter.Stream ) {
86107 stream .WriteObjectStart ()
87108 stream .WriteObjectField (`count` )
0 commit comments