From edf9e03660ccb4d9e9f76542f715e9bba218e456 Mon Sep 17 00:00:00 2001 From: Jiawei Wang Date: Mon, 25 Jan 2021 17:30:31 -0800 Subject: [PATCH] Bug Fix for process_start_time_metric initialization --- .../k8s.io/component-base/metrics/processstarttime.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/staging/src/k8s.io/component-base/metrics/processstarttime.go b/staging/src/k8s.io/component-base/metrics/processstarttime.go index 8dde458814f..0ac34dc6b2e 100644 --- a/staging/src/k8s.io/component-base/metrics/processstarttime.go +++ b/staging/src/k8s.io/component-base/metrics/processstarttime.go @@ -44,13 +44,13 @@ func RegisterProcessStartTime(registrationFunc func(Registerable) error) error { start = float64(time.Now().Unix()) } // processStartTime is a lazy metric which only get initialized after registered. - // so we have to explicitly create it before setting the label value. Otherwise - // it is a noop. - if !processStartTime.IsCreated() { - processStartTime.initializeMetric() + // so we need to register the metric first and then set the value for it + if err = registrationFunc(processStartTime); err != nil { + return err } + processStartTime.WithLabelValues().Set(start) - return registrationFunc(processStartTime) + return nil } func getProcessStart() (float64, error) {