Skip to content

Commit 0147a77

Browse files
authored
docs: Add comment for go histogram (#96)
Address #94. The following comment is added to `go_metrics.go` to explain why `_sum` and `_count` is not available for go histogram metrics: ```go // There's no `_sum` for histogram, as go metrics only provided buckets and counter of each bucket. // See: https://github.com/golang/go/blob/3432c68467d50ffc622fed230a37cd401d82d4bf/src/runtime/metrics/histogram.go#L8 // // Prometheus SDK provides a (under)estimated `_sum` instead. // See: https://github.com/prometheus/client_golang/blob/5fe1d33cea76068edd4ece5f58e52f81d225b13c/prometheus/go_collector_latest.go#L498 // // Also, there's no need to provide a `_count` as it can be represented by the `+Inf` bucket. ```
1 parent 704aa40 commit 0147a77

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

go_metrics.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ func writeRuntimeHistogramMetric(w io.Writer, name string, h *runtimemetrics.Flo
178178
}
179179
totalCount += tailCount
180180
fmt.Fprintf(w, `%s_bucket{le="+Inf"} %d`+"\n", name, totalCount)
181+
// _sum and _count are not exposed because the Go runtime histogram lacks accurate sum data.
182+
// Estimating the sum (as Prometheus does) could be misleading, while exposing only `_count` without `_sum` is impractical.
183+
// We can reconsider if precise sum data becomes available.
184+
//
185+
// References:
186+
// - Go runtime histogram: https://github.com/golang/go/blob/3432c68467d50ffc622fed230a37cd401d82d4bf/src/runtime/metrics/histogram.go#L8
187+
// - Prometheus estimate: https://github.com/prometheus/client_golang/blob/5fe1d33cea76068edd4ece5f58e52f81d225b13c/prometheus/go_collector_latest.go#L498
188+
// - Related discussion: https://github.com/VictoriaMetrics/metrics/issues/94
181189
}
182190

183191
// Limit the number of buckets for Go runtime histograms in order to prevent from high cardinality issues at scraper side.

0 commit comments

Comments
 (0)