diff --git a/staging/src/k8s.io/component-base/metrics/processstarttime.go b/staging/src/k8s.io/component-base/metrics/processstarttime.go index 0fbbe2b47bc..8dde458814f 100644 --- a/staging/src/k8s.io/component-base/metrics/processstarttime.go +++ b/staging/src/k8s.io/component-base/metrics/processstarttime.go @@ -43,6 +43,12 @@ func RegisterProcessStartTime(registrationFunc func(Registerable) error) error { klog.Errorf("Could not get process start time, %v", err) 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() + } processStartTime.WithLabelValues().Set(start) return registrationFunc(processStartTime) }