Unverified Commit 0b01b9ce authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #72470 from danielqsj/kl

Change kubelet metrics to conform metrics guidelines
parents cbcc2b26 79a3eb81
...@@ -284,7 +284,8 @@ func (m *cgroupManagerImpl) Exists(name CgroupName) bool { ...@@ -284,7 +284,8 @@ func (m *cgroupManagerImpl) Exists(name CgroupName) bool {
func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error { func (m *cgroupManagerImpl) Destroy(cgroupConfig *CgroupConfig) error {
start := time.Now() start := time.Now()
defer func() { defer func() {
metrics.CgroupManagerLatency.WithLabelValues("destroy").Observe(metrics.SinceInMicroseconds(start)) metrics.CgroupManagerDuration.WithLabelValues("destroy").Observe(metrics.SinceInSeconds(start))
metrics.DeprecatedCgroupManagerLatency.WithLabelValues("destroy").Observe(metrics.SinceInMicroseconds(start))
}() }()
cgroupPaths := m.buildCgroupPaths(cgroupConfig.Name) cgroupPaths := m.buildCgroupPaths(cgroupConfig.Name)
...@@ -411,7 +412,8 @@ func (m *cgroupManagerImpl) toResources(resourceConfig *ResourceConfig) *libcont ...@@ -411,7 +412,8 @@ func (m *cgroupManagerImpl) toResources(resourceConfig *ResourceConfig) *libcont
func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error { func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error {
start := time.Now() start := time.Now()
defer func() { defer func() {
metrics.CgroupManagerLatency.WithLabelValues("update").Observe(metrics.SinceInMicroseconds(start)) metrics.CgroupManagerDuration.WithLabelValues("update").Observe(metrics.SinceInSeconds(start))
metrics.DeprecatedCgroupManagerLatency.WithLabelValues("update").Observe(metrics.SinceInMicroseconds(start))
}() }()
// Extract the cgroup resource parameters // Extract the cgroup resource parameters
...@@ -446,7 +448,8 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error { ...@@ -446,7 +448,8 @@ func (m *cgroupManagerImpl) Update(cgroupConfig *CgroupConfig) error {
func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error { func (m *cgroupManagerImpl) Create(cgroupConfig *CgroupConfig) error {
start := time.Now() start := time.Now()
defer func() { defer func() {
metrics.CgroupManagerLatency.WithLabelValues("create").Observe(metrics.SinceInMicroseconds(start)) metrics.CgroupManagerDuration.WithLabelValues("create").Observe(metrics.SinceInSeconds(start))
metrics.DeprecatedCgroupManagerLatency.WithLabelValues("create").Observe(metrics.SinceInMicroseconds(start))
}() }()
resources := m.toResources(cgroupConfig.ResourceParameters) resources := m.toResources(cgroupConfig.ResourceParameters)
......
...@@ -354,6 +354,7 @@ func (m *ManagerImpl) Allocate(node *schedulernodeinfo.NodeInfo, attrs *lifecycl ...@@ -354,6 +354,7 @@ func (m *ManagerImpl) Allocate(node *schedulernodeinfo.NodeInfo, attrs *lifecycl
func (m *ManagerImpl) Register(ctx context.Context, r *pluginapi.RegisterRequest) (*pluginapi.Empty, error) { func (m *ManagerImpl) Register(ctx context.Context, r *pluginapi.RegisterRequest) (*pluginapi.Empty, error) {
klog.Infof("Got registration request from device plugin with resource name %q", r.ResourceName) klog.Infof("Got registration request from device plugin with resource name %q", r.ResourceName)
metrics.DevicePluginRegistrationCount.WithLabelValues(r.ResourceName).Inc() metrics.DevicePluginRegistrationCount.WithLabelValues(r.ResourceName).Inc()
metrics.DeprecatedDevicePluginRegistrationCount.WithLabelValues(r.ResourceName).Inc()
var versionCompatible bool var versionCompatible bool
for _, v := range pluginapi.SupportedVersions { for _, v := range pluginapi.SupportedVersions {
if r.Version == v { if r.Version == v {
...@@ -696,7 +697,8 @@ func (m *ManagerImpl) allocateContainerResources(pod *v1.Pod, container *v1.Cont ...@@ -696,7 +697,8 @@ func (m *ManagerImpl) allocateContainerResources(pod *v1.Pod, container *v1.Cont
// in a passed in AllocateRequest pointer, and issues a single Allocate call per pod. // in a passed in AllocateRequest pointer, and issues a single Allocate call per pod.
klog.V(3).Infof("Making allocation request for devices %v for device plugin %s", devs, resource) klog.V(3).Infof("Making allocation request for devices %v for device plugin %s", devs, resource)
resp, err := eI.e.allocate(devs) resp, err := eI.e.allocate(devs)
metrics.DevicePluginAllocationLatency.WithLabelValues(resource).Observe(metrics.SinceInMicroseconds(startRPCTime)) metrics.DevicePluginAllocationDuration.WithLabelValues(resource).Observe(metrics.SinceInSeconds(startRPCTime))
metrics.DeprecatedDevicePluginAllocationLatency.WithLabelValues(resource).Observe(metrics.SinceInMicroseconds(startRPCTime))
if err != nil { if err != nil {
// In case of allocation failure, we want to restore m.allocatedDevices // In case of allocation failure, we want to restore m.allocatedDevices
// to the actual allocated state from m.podDevices. // to the actual allocated state from m.podDevices.
......
...@@ -361,7 +361,8 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act ...@@ -361,7 +361,8 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act
for _, t := range thresholds { for _, t := range thresholds {
timeObserved := observations[t.Signal].time timeObserved := observations[t.Signal].time
if !timeObserved.IsZero() { if !timeObserved.IsZero() {
metrics.EvictionStatsAge.WithLabelValues(string(t.Signal)).Observe(metrics.SinceInMicroseconds(timeObserved.Time)) metrics.EvictionStatsAge.WithLabelValues(string(t.Signal)).Observe(metrics.SinceInSeconds(timeObserved.Time))
metrics.DeprecatedEvictionStatsAge.WithLabelValues(string(t.Signal)).Observe(metrics.SinceInMicroseconds(timeObserved.Time))
} }
} }
......
...@@ -1500,7 +1500,8 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error { ...@@ -1500,7 +1500,8 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {
if !firstSeenTime.IsZero() { if !firstSeenTime.IsZero() {
// This is the first time we are syncing the pod. Record the latency // This is the first time we are syncing the pod. Record the latency
// since kubelet first saw the pod if firstSeenTime is set. // since kubelet first saw the pod if firstSeenTime is set.
metrics.PodWorkerStartLatency.Observe(metrics.SinceInMicroseconds(firstSeenTime)) metrics.PodWorkerStartDuration.Observe(metrics.SinceInSeconds(firstSeenTime))
metrics.DeprecatedPodWorkerStartLatency.Observe(metrics.SinceInMicroseconds(firstSeenTime))
} else { } else {
klog.V(3).Infof("First seen time not recorded for pod %q", pod.UID) klog.V(3).Infof("First seen time not recorded for pod %q", pod.UID)
} }
...@@ -1517,7 +1518,8 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error { ...@@ -1517,7 +1518,8 @@ func (kl *Kubelet) syncPod(o syncPodOptions) error {
existingStatus, ok := kl.statusManager.GetPodStatus(pod.UID) existingStatus, ok := kl.statusManager.GetPodStatus(pod.UID)
if !ok || existingStatus.Phase == v1.PodPending && apiPodStatus.Phase == v1.PodRunning && if !ok || existingStatus.Phase == v1.PodPending && apiPodStatus.Phase == v1.PodRunning &&
!firstSeenTime.IsZero() { !firstSeenTime.IsZero() {
metrics.PodStartLatency.Observe(metrics.SinceInMicroseconds(firstSeenTime)) metrics.PodStartDuration.Observe(metrics.SinceInSeconds(firstSeenTime))
metrics.DeprecatedPodStartLatency.Observe(metrics.SinceInMicroseconds(firstSeenTime))
} }
runnable := kl.canRunPod(pod) runnable := kl.canRunPod(pod)
...@@ -1996,7 +1998,8 @@ func (kl *Kubelet) dispatchWork(pod *v1.Pod, syncType kubetypes.SyncPodType, mir ...@@ -1996,7 +1998,8 @@ func (kl *Kubelet) dispatchWork(pod *v1.Pod, syncType kubetypes.SyncPodType, mir
UpdateType: syncType, UpdateType: syncType,
OnCompleteFunc: func(err error) { OnCompleteFunc: func(err error) {
if err != nil { if err != nil {
metrics.PodWorkerLatency.WithLabelValues(syncType.String()).Observe(metrics.SinceInMicroseconds(start)) metrics.PodWorkerDuration.WithLabelValues(syncType.String()).Observe(metrics.SinceInSeconds(start))
metrics.DeprecatedPodWorkerLatency.WithLabelValues(syncType.String()).Observe(metrics.SinceInMicroseconds(start))
} }
}, },
}) })
......
...@@ -49,13 +49,16 @@ func newInstrumentedImageManagerService(service internalapi.ImageManagerService) ...@@ -49,13 +49,16 @@ func newInstrumentedImageManagerService(service internalapi.ImageManagerService)
// recordOperation records the duration of the operation. // recordOperation records the duration of the operation.
func recordOperation(operation string, start time.Time) { func recordOperation(operation string, start time.Time) {
metrics.RuntimeOperations.WithLabelValues(operation).Inc() metrics.RuntimeOperations.WithLabelValues(operation).Inc()
metrics.RuntimeOperationsLatency.WithLabelValues(operation).Observe(metrics.SinceInMicroseconds(start)) metrics.DeprecatedRuntimeOperations.WithLabelValues(operation).Inc()
metrics.RuntimeOperationsDuration.WithLabelValues(operation).Observe(metrics.SinceInSeconds(start))
metrics.DeprecatedRuntimeOperationsLatency.WithLabelValues(operation).Observe(metrics.SinceInMicroseconds(start))
} }
// recordError records error for metric if an error occurred. // recordError records error for metric if an error occurred.
func recordError(operation string, err error) { func recordError(operation string, err error) {
if err != nil { if err != nil {
metrics.RuntimeOperationsErrors.WithLabelValues(operation).Inc() metrics.RuntimeOperationsErrors.WithLabelValues(operation).Inc()
metrics.DeprecatedRuntimeOperationsErrors.WithLabelValues(operation).Inc()
} }
} }
......
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
func TestRecordOperation(t *testing.T) { func TestRecordOperation(t *testing.T) {
prometheus.MustRegister(metrics.RuntimeOperations) prometheus.MustRegister(metrics.RuntimeOperations)
prometheus.MustRegister(metrics.RuntimeOperationsLatency) prometheus.MustRegister(metrics.RuntimeOperationsDuration)
prometheus.MustRegister(metrics.RuntimeOperationsErrors) prometheus.MustRegister(metrics.RuntimeOperationsErrors)
temporalServer := "127.0.0.1:1234" temporalServer := "127.0.0.1:1234"
...@@ -50,8 +50,8 @@ func TestRecordOperation(t *testing.T) { ...@@ -50,8 +50,8 @@ func TestRecordOperation(t *testing.T) {
}() }()
recordOperation("create_container", time.Now()) recordOperation("create_container", time.Now())
runtimeOperationsCounterExpected := "kubelet_runtime_operations{operation_type=\"create_container\"} 1" runtimeOperationsCounterExpected := "kubelet_runtime_operations_total{operation_type=\"create_container\"} 1"
runtimeOperationsLatencyExpected := "kubelet_runtime_operations_latency_microseconds_count{operation_type=\"create_container\"} 1" runtimeOperationsDurationExpected := "kubelet_runtime_operations_duration_seconds_count{operation_type=\"create_container\"} 1"
assert.HTTPBodyContains(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.HTTPBodyContains(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mux.ServeHTTP(w, r) mux.ServeHTTP(w, r)
...@@ -59,7 +59,7 @@ func TestRecordOperation(t *testing.T) { ...@@ -59,7 +59,7 @@ func TestRecordOperation(t *testing.T) {
assert.HTTPBodyContains(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.HTTPBodyContains(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mux.ServeHTTP(w, r) mux.ServeHTTP(w, r)
}), "GET", prometheusURL, nil, runtimeOperationsLatencyExpected) }), "GET", prometheusURL, nil, runtimeOperationsDurationExpected)
} }
func TestInstrumentedVersion(t *testing.T) { func TestInstrumentedVersion(t *testing.T) {
......
...@@ -189,12 +189,14 @@ func (g *GenericPLEG) relist() { ...@@ -189,12 +189,14 @@ func (g *GenericPLEG) relist() {
klog.V(5).Infof("GenericPLEG: Relisting") klog.V(5).Infof("GenericPLEG: Relisting")
if lastRelistTime := g.getRelistTime(); !lastRelistTime.IsZero() { if lastRelistTime := g.getRelistTime(); !lastRelistTime.IsZero() {
metrics.PLEGRelistInterval.Observe(metrics.SinceInMicroseconds(lastRelistTime)) metrics.PLEGRelistInterval.Observe(metrics.SinceInSeconds(lastRelistTime))
metrics.DeprecatedPLEGRelistInterval.Observe(metrics.SinceInMicroseconds(lastRelistTime))
} }
timestamp := g.clock.Now() timestamp := g.clock.Now()
defer func() { defer func() {
metrics.PLEGRelistLatency.Observe(metrics.SinceInMicroseconds(timestamp)) metrics.PLEGRelistDuration.Observe(metrics.SinceInSeconds(timestamp))
metrics.DeprecatedPLEGRelistLatency.Observe(metrics.SinceInMicroseconds(timestamp))
}() }()
// Get all the pods. // Get all the pods.
......
...@@ -102,13 +102,13 @@ func getKubeletMetrics(c clientset.Interface, nodeName string) (metrics.KubeletM ...@@ -102,13 +102,13 @@ func getKubeletMetrics(c clientset.Interface, nodeName string) (metrics.KubeletM
// Note that the KubeletMetrics passed in should not contain subsystem prefix. // Note that the KubeletMetrics passed in should not contain subsystem prefix.
func GetDefaultKubeletLatencyMetrics(ms metrics.KubeletMetrics) KubeletLatencyMetrics { func GetDefaultKubeletLatencyMetrics(ms metrics.KubeletMetrics) KubeletLatencyMetrics {
latencyMetricNames := sets.NewString( latencyMetricNames := sets.NewString(
kubeletmetrics.PodWorkerLatencyKey, kubeletmetrics.PodWorkerDurationKey,
kubeletmetrics.PodWorkerStartLatencyKey, kubeletmetrics.PodWorkerStartDurationKey,
kubeletmetrics.PodStartLatencyKey, kubeletmetrics.PodStartDurationKey,
kubeletmetrics.CgroupManagerOperationsKey, kubeletmetrics.CgroupManagerOperationsKey,
dockermetrics.DockerOperationsLatencyKey, dockermetrics.DockerOperationsLatencyKey,
kubeletmetrics.PodWorkerStartLatencyKey, kubeletmetrics.PodWorkerStartDurationKey,
kubeletmetrics.PLEGRelistLatencyKey, kubeletmetrics.PLEGRelistDurationKey,
) )
return GetKubeletLatencyMetrics(ms, latencyMetricNames) return GetKubeletLatencyMetrics(ms, latencyMetricNames)
} }
......
...@@ -168,9 +168,9 @@ var InterestingKubeletMetrics = []string{ ...@@ -168,9 +168,9 @@ var InterestingKubeletMetrics = []string{
"kubelet_docker_errors", "kubelet_docker_errors",
"kubelet_docker_operations_latency_seconds", "kubelet_docker_operations_latency_seconds",
"kubelet_generate_pod_status_latency_microseconds", "kubelet_generate_pod_status_latency_microseconds",
"kubelet_pod_start_latency_microseconds", "kubelet_pod_start_duration_seconds",
"kubelet_pod_worker_latency_microseconds", "kubelet_pod_worker_duration_seconds",
"kubelet_pod_worker_start_latency_microseconds", "kubelet_pod_worker_start_duration_seconds",
"kubelet_sync_pods_latency_microseconds", "kubelet_sync_pods_latency_microseconds",
} }
......
...@@ -459,12 +459,12 @@ func getPodStartLatency(node string) (framework.KubeletLatencyMetrics, error) { ...@@ -459,12 +459,12 @@ func getPodStartLatency(node string) (framework.KubeletLatencyMetrics, error) {
for _, samples := range ms { for _, samples := range ms {
for _, sample := range samples { for _, sample := range samples {
if sample.Metric["__name__"] == kubemetrics.KubeletSubsystem+"_"+kubemetrics.PodStartLatencyKey { if sample.Metric["__name__"] == kubemetrics.KubeletSubsystem+"_"+kubemetrics.PodStartDurationKey {
quantile, _ := strconv.ParseFloat(string(sample.Metric["quantile"]), 64) quantile, _ := strconv.ParseFloat(string(sample.Metric["quantile"]), 64)
latencyMetrics = append(latencyMetrics, latencyMetrics = append(latencyMetrics,
framework.KubeletLatencyMetric{ framework.KubeletLatencyMetric{
Quantile: quantile, Quantile: quantile,
Method: kubemetrics.PodStartLatencyKey, Method: kubemetrics.PodStartDurationKey,
Latency: time.Duration(int(sample.Value)) * time.Microsecond}) Latency: time.Duration(int(sample.Value)) * time.Microsecond})
} }
} }
......
...@@ -156,7 +156,7 @@ func logDevicePluginMetrics() { ...@@ -156,7 +156,7 @@ func logDevicePluginMetrics() {
framework.ExpectNoError(err) framework.ExpectNoError(err)
for msKey, samples := range ms { for msKey, samples := range ms {
switch msKey { switch msKey {
case kubeletmetrics.KubeletSubsystem + "_" + kubeletmetrics.DevicePluginAllocationLatencyKey: case kubeletmetrics.KubeletSubsystem + "_" + kubeletmetrics.DevicePluginAllocationDurationKey:
for _, sample := range samples { for _, sample := range samples {
latency := sample.Value latency := sample.Value
resource := string(sample.Metric["resource_name"]) resource := string(sample.Metric["resource_name"])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment