Bug Fix for process_start_time_metric initialization

This commit is contained in:
Jiawei Wang 2020-11-10 14:53:44 -08:00
parent a5bce462d0
commit aa78f2d1b4

View File

@ -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)
}