From bed346338365e3df8ca4ad5479b158b2264af443 Mon Sep 17 00:00:00 2001 From: changhyuni Date: Sat, 18 Nov 2023 23:45:52 +0900 Subject: [PATCH] pods: update init_cotainer_info metric pods: update init_cotainer_info metric fix typo fix typo fix typo --- docs/pod-metrics.md | 2 +- internal/store/pod.go | 9 +++++++-- internal/store/pod_test.go | 3 ++- 3 files changed, 10 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 7fc866a9d6..1cbeb8a41b 100644 --- a/internal/store/pod.go +++ b/internal/store/pod.go @@ -677,16 +677,21 @@ func createPodInitContainerInfoFamilyGenerator() generator.FamilyGenerator { "", wrapPodFunc(func(p *v1.Pod) *metric.Family { ms := []*metric.Metric{} - labelKeys := []string{"container", "image_spec", "image", "image_id", "container_id"} + 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}, + 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 05e12ba7b0..2a539b1a00 100644 --- a/internal/store/pod_test.go +++ b/internal/store/pod_test.go @@ -89,6 +89,7 @@ func TestPodStore(t *testing.T) { { Name: "initContainer", Image: "k8s.gcr.io/initfoo_spec", + RestartPolicy: v1.ContainerRestartPolicyAlways, }, }, }, @@ -124,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"}, }, {