Skip to content

Commit

Permalink
Update comments according to code review
Browse files Browse the repository at this point in the history
Signed-off-by: Jeanette Tan <jeanette.tan@grafana.com>
  • Loading branch information
zenador committed Feb 1, 2023
1 parent 4e9e3f5 commit 18a4214
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions model/value_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func marshalJSONIsEmpty(ptr unsafe.Pointer) bool {
return false
}

// from https://github.com/prometheus/prometheus/blob/main/util/jsonutil/marshal.go
// MarshalTimestamp marshals a point timestamp using the passed jsoniter stream.
func MarshalTimestamp(t int64, stream *jsoniter.Stream) {
// Write out the timestamp as a float divided by 1000.
Expand All @@ -48,7 +47,6 @@ func MarshalTimestamp(t int64, stream *jsoniter.Stream) {
}
}

// from https://github.com/prometheus/prometheus/blob/main/util/jsonutil/marshal.go
// MarshalValue marshals a point value using the passed jsoniter stream.
func MarshalValue(v float64, stream *jsoniter.Stream) {
stream.WriteRaw(`"`)
Expand All @@ -68,7 +66,8 @@ func MarshalValue(v float64, stream *jsoniter.Stream) {
stream.WriteRaw(`"`)
}

// adapted from https://github.com/prometheus/prometheus/blob/main/web/api/v1/api.go
// MarshalHistogramBucket writes something like: [ 3, "-0.25", "0.25", "3"]
// See MarshalHistogram to understand what the numbers mean
func MarshalHistogramBucket(b HistogramBucket, stream *jsoniter.Stream) {
stream.WriteArrayStart()
stream.WriteInt32(b.Boundaries)
Expand All @@ -81,7 +80,29 @@ func MarshalHistogramBucket(b HistogramBucket, stream *jsoniter.Stream) {
stream.WriteArrayEnd()
}

// adapted from https://github.com/prometheus/prometheus/blob/main/web/api/v1/api.go
// MarshalHistogram writes something like:
//
// {
// "count": "42",
// "sum": "34593.34",
// "buckets": [
// [ 3, "-0.25", "0.25", "3"],
// [ 0, "0.25", "0.5", "12"],
// [ 0, "0.5", "1", "21"],
// [ 0, "2", "4", "6"]
// ]
// }
//
// The 1st element in each bucket array determines if the boundaries are
// inclusive (AKA closed) or exclusive (AKA open):
//
// 0: lower exclusive, upper inclusive
// 1: lower inclusive, upper exclusive
// 2: both exclusive
// 3: both inclusive
//
// The 2nd and 3rd elements are the lower and upper boundary. The 4th element is
// the bucket count.
func MarshalHistogram(h SampleHistogram, stream *jsoniter.Stream) {
stream.WriteObjectStart()
stream.WriteObjectField(`count`)
Expand Down

0 comments on commit 18a4214

Please sign in to comment.