From 6ed3c5051c88d1ca030c33a37b62407065171ddc Mon Sep 17 00:00:00 2001 From: changhyuni Date: Sun, 19 Nov 2023 01:02:55 +0900 Subject: [PATCH] pods: update init_cotainer_info metric fix typo fix typo fix typo --- docs/pod-metrics.md | 2 +- internal/store/pod.go | 7 ++++++- internal/store/pod_test.go | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/pod-metrics.md b/docs/pod-metrics.md index 224bb7bcb1..1fa6f4dfb3 100644 --- a/docs/pod-metrics.md +++ b/docs/pod-metrics.md @@ -36,7 +36,7 @@ | kube_pod_created | Gauge | Unix creation timestamp | seconds | `pod`=<pod-name>
`namespace`=<pod-namespace>
`uid`=<pod-uid> | STABLE | - | | kube_pod_deletion_timestamp | Gauge | Unix deletion timestamp | seconds | `pod`=<pod-name>
`namespace`=<pod-namespace>
`uid`=<pod-uid> | EXPERIMENTAL | - | | kube_pod_restart_policy | Gauge | Describes the restart policy in use by this pod | | `pod`=<pod-name>
`namespace`=<pod-namespace>
`type`=<Always\|Never\|OnFailure>
`uid`=<pod-uid> | STABLE | - | -| kube_pod_init_container_info | Gauge | Information about an init container in a pod | | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`image`=<image-name>
`image_id`=<image-id>
`image_spec`=<image-spec>
`container_id`=<containerid>
`uid`=<pod-uid> | STABLE | - | +| kube_pod_init_container_info | Gauge | Information about an init container in a pod | | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`image`=<image-name>
`image_id`=<image-id>
`image_spec`=<image-spec>
`container_id`=<containerid>
`uid`=<pod-uid>
`type`=<Always> | STABLE | - | | kube_pod_init_container_status_waiting | Gauge | Describes whether the init container is currently in waiting state | | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`uid`=<pod-uid> | STABLE | - | | kube_pod_init_container_status_waiting_reason | Gauge | Describes the reason the init container is currently in waiting state | | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`reason`=<container-waiting-reason>
`uid`=<pod-uid> | EXPERIMENTAL | - | | kube_pod_init_container_status_running | Gauge | Describes whether the init container is currently in running state | | `container`=<container-name>
`pod`=<pod-name>
`namespace`=<pod-namespace>
`uid`=<pod-uid> | STABLE | - | diff --git a/internal/store/pod.go b/internal/store/pod.go index 3330f65352..1cbeb8a41b 100644 --- a/internal/store/pod.go +++ b/internal/store/pod.go @@ -680,13 +680,18 @@ func createPodInitContainerInfoFamilyGenerator() generator.FamilyGenerator { labelKeys := []string{"container", "image_spec", "image", "image_id", "container_id", "type"} for _, c := range p.Spec.InitContainers { + restartPolicy := "" + if c.RestartPolicy != nil { + restartPolicy = c.RestartPolicy + } + for _, cs := range p.Status.InitContainerStatuses { if cs.Name != c.Name { continue } ms = append(ms, &metric.Metric{ LabelKeys: labelKeys, - LabelValues: []string{cs.Name, c.Image, cs.Image, cs.ImageID, cs.ContainerID, c.RestartPolicy}, + LabelValues: []string{cs.Name, c.Image, cs.Image, cs.ImageID, cs.ContainerID, restartPolicy}, Value: 1, }) } diff --git a/internal/store/pod_test.go b/internal/store/pod_test.go index 79135b51e5..2a539b1a00 100644 --- a/internal/store/pod_test.go +++ b/internal/store/pod_test.go @@ -89,7 +89,7 @@ func TestPodStore(t *testing.T) { { Name: "initContainer", Image: "k8s.gcr.io/initfoo_spec", - RestartPolicy: v1.RestartPolicyAlways + RestartPolicy: v1.ContainerRestartPolicyAlways, }, }, }, @@ -125,7 +125,7 @@ func TestPodStore(t *testing.T) { # TYPE kube_pod_init_container_info gauge kube_pod_container_info{container="container2",container_id="docker://cd456",image_spec="k8s.gcr.io/hyperkube2_spec",image="k8s.gcr.io/hyperkube2",image_id="docker://sha256:bbb",namespace="ns2",pod="pod2",uid="uid2"} 1 kube_pod_container_info{container="container3",container_id="docker://ef789",image_spec="k8s.gcr.io/hyperkube3_spec",image="k8s.gcr.io/hyperkube3",image_id="docker://sha256:ccc",namespace="ns2",pod="pod2",uid="uid2"} 1 - kube_pod_init_container_info{container="initContainer",container_id="docker://ef123",image_spec="k8s.gcr.io/initfoo_spec",image="k8s.gcr.io/initfoo",image_id="docker://sha256:wxyz",namespace="ns2",pod="pod2",uid="uid2"} 1`, + kube_pod_init_container_info{container="initContainer",container_id="docker://ef123",image_spec="k8s.gcr.io/initfoo_spec",image="k8s.gcr.io/initfoo",image_id="docker://sha256:wxyz",namespace="ns2",pod="pod2",uid="uid2", type="Always"} 1`, MetricNames: []string{"kube_pod_container_info", "kube_pod_init_container_info"}, }, {