MCPcopy
hub / github.com/prometheus/client_golang / unwrapScalarRMValue

Function unwrapScalarRMValue

prometheus/go_collector_latest.go:375–394  ·  view source on GitHub ↗

unwrapScalarRMValue unwraps a runtime/metrics value that is assumed to be scalar and returns the equivalent float64 value. Panics if the value is not scalar.

(v metrics.Value)

Source from the content-addressed store, hash-verified

373// to be scalar and returns the equivalent float64 value. Panics if the
374// value is not scalar.
375func unwrapScalarRMValue(v metrics.Value) float64 {
376 switch v.Kind() {
377 case metrics.KindUint64:
378 return float64(v.Uint64())
379 case metrics.KindFloat64:
380 return v.Float64()
381 case metrics.KindBad:
382 // Unsupported metric.
383 //
384 // This should never happen because we always populate our metric
385 // set from the runtime/metrics package.
386 panic("unexpected bad kind metric")
387 default:
388 // Unsupported metric kind.
389 //
390 // This should never happen because we check for this during initialization
391 // and flag and filter metrics whose kinds we don't understand.
392 panic(fmt.Sprintf("unexpected unsupported metric: %v", v.Kind()))
393 }
394}
395
396// exactSumFor takes a runtime/metrics metric name (that is assumed to
397// be of kind KindFloat64Histogram) and returns its exact sum and whether

Callers 2

CollectMethod · 0.85
exactSumForMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected