Update k8s dependency version to 1.21

Signed-off-by: xinyanwu409 <wxinyan@vmware>
This commit is contained in:
wxinyan
2021-04-15 23:35:04 -07:00
committed by xinyanwu409
parent f255fe7b46
commit 17b8ffe7f8
1302 changed files with 108432 additions and 10464 deletions

View File

@@ -17,11 +17,8 @@ limitations under the License.
package metrics
import (
"os"
"time"
"github.com/prometheus/procfs"
"k8s.io/klog/v2"
)
@@ -44,24 +41,11 @@ 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)
}
func getProcessStart() (float64, error) {
pid := os.Getpid()
p, err := procfs.NewProc(pid)
if err != nil {
return 0, err
}
if stat, err := p.Stat(); err == nil {
return stat.StartTime()
}
return 0, err
return nil
}