Merge pull request #1971 from ryanrolds/rolds/bug_fix_pod_container_ready_time

Fixing emitting of ready time metrics when condition is false
This commit is contained in:
Kubernetes Prow Robot 2023-02-06 09:31:00 -08:00 committed by GitHub
commit 86bf8f2803
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 3 deletions

View File

@ -1347,7 +1347,7 @@ func createPodStatusContainerReadyTimeFamilyGenerator() generator.FamilyGenerato
ms := []*metric.Metric{}
for _, c := range p.Status.Conditions {
if c.Type == v1.ContainersReady {
if c.Type == v1.ContainersReady && c.Status == v1.ConditionTrue {
ms = append(ms, &metric.Metric{
LabelKeys: []string{},
LabelValues: []string{},
@ -1375,7 +1375,7 @@ func createPodStatusReadyTimeFamilyGenerator() generator.FamilyGenerator {
ms := []*metric.Metric{}
for _, c := range p.Status.Conditions {
if c.Type == v1.PodReady {
if c.Type == v1.PodReady && c.Status == v1.ConditionTrue {
ms = append(ms, &metric.Metric{
LabelKeys: []string{},
LabelValues: []string{},

View File

@ -1460,6 +1460,31 @@ func TestPodStore(t *testing.T) {
`,
MetricNames: []string{"kube_pod_status_container_ready_time"},
},
{
Obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pod1",
Namespace: "ns1",
UID: "uid1",
},
Status: v1.PodStatus{
Conditions: []v1.PodCondition{
{
Type: v1.ContainersReady,
Status: v1.ConditionFalse,
LastTransitionTime: metav1.Time{
Time: time.Unix(1501666018, 0),
},
},
},
},
},
Want: `
# HELP kube_pod_status_container_ready_time Readiness achieved time in unix timestamp for a pod containers.
# TYPE kube_pod_status_container_ready_time gauge
`,
MetricNames: []string{"kube_pod_status_container_ready_time"},
},
{
Obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
@ -1515,7 +1540,6 @@ func TestPodStore(t *testing.T) {
# HELP kube_pod_status_ready_time Readiness achieved time in unix timestamp for a pod.
# TYPE kube_pod_status_ready gauge
# TYPE kube_pod_status_ready_time gauge
kube_pod_status_ready_time{namespace="ns2",pod="pod2",uid="uid2"} 1.501666018e+09
kube_pod_status_ready{condition="false",namespace="ns2",pod="pod2",uid="uid2"} 1
kube_pod_status_ready{condition="true",namespace="ns2",pod="pod2",uid="uid2"} 0
kube_pod_status_ready{condition="unknown",namespace="ns2",pod="pod2",uid="uid2"} 0