forked from github/multus-cni
Downgrade Kubernetes vendor version
Multus community decide that multus support the Kubernetes that Kubernetes community supports, so changed vendor code to the oldest version of currently supported.
This commit is contained in:
26
vendor/k8s.io/component-base/metrics/processstarttime.go
generated
vendored
26
vendor/k8s.io/component-base/metrics/processstarttime.go
generated
vendored
@@ -17,8 +17,11 @@ limitations under the License.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/procfs"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
@@ -41,11 +44,24 @@ 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 need to register the metric first and then set the value for it
|
||||
if err = registrationFunc(processStartTime); err != nil {
|
||||
return err
|
||||
// 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)
|
||||
}
|
||||
|
||||
func getProcessStart() (float64, error) {
|
||||
pid := os.Getpid()
|
||||
p, err := procfs.NewProc(pid)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
processStartTime.WithLabelValues().Set(start)
|
||||
return nil
|
||||
if stat, err := p.Stat(); err == nil {
|
||||
return stat.StartTime()
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user