diff --git a/docs/pod-metrics.md b/docs/pod-metrics.md index 224bb7bcb1..ee30c7f668 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>
`restart_policy`=<restart-policy> | 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..09a83d171b 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", "restart_policy"} for _, c := range p.Spec.InitContainers { + restartPolicy := "" + if c.RestartPolicy != nil { + restartPolicy = string(*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..84f63cadb4 100644 --- a/internal/store/pod_test.go +++ b/internal/store/pod_test.go @@ -33,6 +33,7 @@ func TestPodStore(t *testing.T) { runtimeclass := "foo" startTime := 1501569018 metav1StartTime := metav1.Unix(int64(startTime), 0) + restartPolicyAlways := v1.ContainerRestartPolicyAlways cases := []generateMetricsTestCase{ { @@ -87,8 +88,9 @@ func TestPodStore(t *testing.T) { }, InitContainers: []v1.Container{ { - Name: "initContainer", - Image: "k8s.gcr.io/initfoo_spec", + Name: "initContainer", + Image: "k8s.gcr.io/initfoo_spec", + RestartPolicy: &restartPolicyAlways, }, }, }, @@ -124,7 +126,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",restart_policy="Always"} 1`, MetricNames: []string{"kube_pod_container_info", "kube_pod_init_container_info"}, }, {