MCPcopy
hub / github.com/grafana/dskit / fold

Function fold

metrics/tenant_registries.go:470–486  ·  view source on GitHub ↗

fold returns value computed from multiple metrics, using folding function. if there are no metrics, it returns NaN.

(mf *dto.MetricFamily, fn func(*dto.Metric) float64, foldFn func(val, res float64) float64)

Source from the content-addressed store, hash-verified

468
469// fold returns value computed from multiple metrics, using folding function. if there are no metrics, it returns NaN.
470func fold(mf *dto.MetricFamily, fn func(*dto.Metric) float64, foldFn func(val, res float64) float64) float64 {
471 result := math.NaN()
472
473 for _, m := range mf.GetMetric() {
474 value := fn(m)
475 if math.IsNaN(value) {
476 continue
477 }
478 if math.IsNaN(result) {
479 result = value
480 } else {
481 result = foldFn(value, result)
482 }
483 }
484
485 return result
486}
487
488// This works even if m is nil, m.Counter is nil or m.Counter.Value is nil (it returns 0 in those cases)
489func counterValue(m *dto.Metric) float64 { return m.GetCounter().GetValue() }

Callers 2

MaxGaugesMethod · 0.85
MinGaugesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected