From d95f4f2cf94fb7f699659c222fad9afe8616bc79 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 22 Dec 2020 19:16:11 -0800 Subject: [PATCH 1/2] add windows package --- staging/src/k8s.io/component-base/go.mod | 1 + .../metrics/processstarttime.go | 16 -------- .../metrics/processstarttime_others.go | 38 +++++++++++++++++++ .../metrics/processstarttime_windows.go | 33 ++++++++++++++++ 4 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 staging/src/k8s.io/component-base/metrics/processstarttime_others.go create mode 100644 staging/src/k8s.io/component-base/metrics/processstarttime_windows.go diff --git a/staging/src/k8s.io/component-base/go.mod b/staging/src/k8s.io/component-base/go.mod index 9aa7633a02d..db9db562c7f 100644 --- a/staging/src/k8s.io/component-base/go.mod +++ b/staging/src/k8s.io/component-base/go.mod @@ -20,6 +20,7 @@ require ( go.uber.org/atomic v1.4.0 // indirect go.uber.org/multierr v1.1.0 // indirect go.uber.org/zap v1.10.0 + golang.org/x/sys v0.0.0-20201112073958-5cba982894dd k8s.io/apimachinery v0.0.0 k8s.io/client-go v0.0.0 k8s.io/klog/v2 v2.5.0 diff --git a/staging/src/k8s.io/component-base/metrics/processstarttime.go b/staging/src/k8s.io/component-base/metrics/processstarttime.go index 0ac34dc6b2e..4b5e76935cb 100644 --- a/staging/src/k8s.io/component-base/metrics/processstarttime.go +++ b/staging/src/k8s.io/component-base/metrics/processstarttime.go @@ -17,11 +17,8 @@ limitations under the License. package metrics import ( - "os" "time" - "github.com/prometheus/procfs" - "k8s.io/klog/v2" ) @@ -52,16 +49,3 @@ func RegisterProcessStartTime(registrationFunc func(Registerable) error) error { processStartTime.WithLabelValues().Set(start) return nil } - -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 -} diff --git a/staging/src/k8s.io/component-base/metrics/processstarttime_others.go b/staging/src/k8s.io/component-base/metrics/processstarttime_others.go new file mode 100644 index 00000000000..89ea8a68e8b --- /dev/null +++ b/staging/src/k8s.io/component-base/metrics/processstarttime_others.go @@ -0,0 +1,38 @@ +// +build !windows + +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package metrics + +import ( + "os" + + "github.com/prometheus/procfs" +) + +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 +} diff --git a/staging/src/k8s.io/component-base/metrics/processstarttime_windows.go b/staging/src/k8s.io/component-base/metrics/processstarttime_windows.go new file mode 100644 index 00000000000..8fcdf273a22 --- /dev/null +++ b/staging/src/k8s.io/component-base/metrics/processstarttime_windows.go @@ -0,0 +1,33 @@ +// +build windows + +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package metrics + +import ( + "golang.org/x/sys/windows" +) + +func getProcessStart() (float64, error) { + processHandle := windows.CurrentProcess() + + var creationTime, exitTime, kernelTime, userTime windows.Filetime + if err := windows.GetProcessTimes(processHandle, &creationTime, &exitTime, &kernelTime, &userTime); err != nil { + return 0, err + } + return float64(creationTime.Nanoseconds() / 1e9), nil +} From 2c9e4406d66e4acfea4638de7bef9092c83fe12a Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Wed, 3 Mar 2021 13:48:34 -0800 Subject: [PATCH 2/2] generated: run hack/update-vendor.sh --- staging/src/k8s.io/component-base/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/staging/src/k8s.io/component-base/go.mod b/staging/src/k8s.io/component-base/go.mod index db9db562c7f..66ce03347db 100644 --- a/staging/src/k8s.io/component-base/go.mod +++ b/staging/src/k8s.io/component-base/go.mod @@ -20,7 +20,7 @@ require ( go.uber.org/atomic v1.4.0 // indirect go.uber.org/multierr v1.1.0 // indirect go.uber.org/zap v1.10.0 - golang.org/x/sys v0.0.0-20201112073958-5cba982894dd + golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073 k8s.io/apimachinery v0.0.0 k8s.io/client-go v0.0.0 k8s.io/klog/v2 v2.5.0