From 2f7c9fcd269a623bdd21993406f1ef485eb9753e Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Fri, 8 Nov 2019 11:25:19 +0800 Subject: [PATCH] Add NewLazyMetricWithTimestamp() API to stability framework. --- staging/src/k8s.io/component-base/metrics/value.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/staging/src/k8s.io/component-base/metrics/value.go b/staging/src/k8s.io/component-base/metrics/value.go index 5717338510e..4a19aaa3bf9 100644 --- a/staging/src/k8s.io/component-base/metrics/value.go +++ b/staging/src/k8s.io/component-base/metrics/value.go @@ -17,6 +17,8 @@ limitations under the License. package metrics import ( + "time" + "github.com/prometheus/client_golang/prometheus" ) @@ -44,3 +46,15 @@ func NewLazyConstMetric(desc *Desc, valueType ValueType, value float64, labelVal } return prometheus.MustNewConstMetric(desc.toPrometheusDesc(), valueType.toPromValueType(), value, labelValues...) } + +// NewLazyMetricWithTimestamp is a helper of NewMetricWithTimestamp. +// +// Warning: the Metric 'm' must be the one created by NewLazyConstMetric(), +// otherwise, no stability guarantees would be offered. +func NewLazyMetricWithTimestamp(t time.Time, m Metric) Metric { + if m == nil { + return nil + } + + return prometheus.NewMetricWithTimestamp(t, m) +}