From 7c825c45bc35effcc381cbc2545df2418f8e5189 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 23 Oct 2020 11:57:26 -0700 Subject: [PATCH] pod: add gauge for runtimeclass handler Add a metric gauge to provide observability for the runtimeclass used for running a pod. Signed-off-by: Eric Ernst --- docs/pod-metrics.md | 1 + internal/store/pod.go | 21 +++++++++++++++++++++ internal/store/pod_test.go | 2 +- main_test.go | 2 ++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/pod-metrics.md b/docs/pod-metrics.md index 1127e381de..3f28a09c5a 100644 --- a/docs/pod-metrics.md +++ b/docs/pod-metrics.md @@ -32,6 +32,7 @@ | kube_pod_container_resource_limits_ephemeral_storage_bytes | Gauge | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace> | EXPERIMENTAL | | kube_pod_overhead_cpu_cores | Gauge | `pod`=<pod-name>
`namespace`=<pod-namespace> | EXPERIMENTAL | | kube_pod_overhead_memory_bytes | Gauge | `pod`=<pod-name>
`namespace`=<pod-namespace> | EXPERIMENTAL | +| kube_pod_runtimeclass_handler | Gauge | `pod`=<pod-name>
`namespace`=<pod-namespace> | EXPERIMENTAL | | kube_pod_created | Gauge | `pod`=<pod-name>
`namespace`=<pod-namespace> | STABLE | | kube_pod_deletion_timestamp | Gauge | `pod`=<pod-name>
`namespace`=<pod-namespace> | EXPERIMENTAL | | kube_pod_restart_policy | Gauge | `pod`=<pod-name>
`namespace`=<pod-namespace>
`type`=<Always|Never|OnFailure> | STABLE | diff --git a/internal/store/pod.go b/internal/store/pod.go index 0a0a744d12..639e94bdcb 100644 --- a/internal/store/pod.go +++ b/internal/store/pod.go @@ -1511,6 +1511,27 @@ var ( } } + return &metric.Family{ + Metrics: ms, + } + }), + ), + *generator.NewFamilyGenerator( + "kube_pod_runtimeclass_handler", + "The runtimeclass handler associated with the pod.", + metric.Gauge, + "", + wrapPodFunc(func(p *v1.Pod) *metric.Family { + ms := []*metric.Metric{} + + if p.Spec.RuntimeClassName != nil { + ms = append(ms, &metric.Metric{ + LabelKeys: []string{"runtimeclass_handler"}, + LabelValues: []string{*p.Spec.RuntimeClassName}, + Value: 1, + }) + } + return &metric.Family{ Metrics: ms, } diff --git a/internal/store/pod_test.go b/internal/store/pod_test.go index 1b7d2183f6..c1b5eeb499 100644 --- a/internal/store/pod_test.go +++ b/internal/store/pod_test.go @@ -1695,7 +1695,7 @@ func BenchmarkPodStore(b *testing.B) { }, } - expectedFamilies := 57 + expectedFamilies := 58 for n := 0; n < b.N; n++ { families := f(pod) if len(families) != expectedFamilies { diff --git a/main_test.go b/main_test.go index 719bd7ad0d..764ab48bea 100644 --- a/main_test.go +++ b/main_test.go @@ -354,6 +354,8 @@ kube_pod_container_resource_limits{namespace="default",pod="pod0",container="pod # TYPE kube_pod_overhead_cpu_cores gauge # HELP kube_pod_overhead_memory_bytes The pod overhead in regards to memory associated with running a pod. # TYPE kube_pod_overhead_memory_bytes gauge +# HELP kube_pod_runtimeclass_handler The runtimeclass handler associated with the pod. +# TYPE kube_pod_runtimeclass_handler gauge ` expectedSplit := strings.Split(strings.TrimSpace(expected), "\n")