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)
| 468 | |
| 469 | // fold returns value computed from multiple metrics, using folding function. if there are no metrics, it returns NaN. |
| 470 | func 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) |
| 489 | func counterValue(m *dto.Metric) float64 { return m.GetCounter().GetValue() } |