Skip to content

Commit 67ed488

Browse files
author
Ryan R. Olds
committed
Fixing emitting of ready time metrics when condition is false
1 parent 90f58ce commit 67ed488

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

internal/store/pod.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ func createPodStatusContainerReadyTimeFamilyGenerator() generator.FamilyGenerato
13311331
ms := []*metric.Metric{}
13321332

13331333
for _, c := range p.Status.Conditions {
1334-
if c.Type == v1.ContainersReady {
1334+
if c.Type == v1.ContainersReady && c.Status == v1.ConditionTrue {
13351335
ms = append(ms, &metric.Metric{
13361336
LabelKeys: []string{},
13371337
LabelValues: []string{},
@@ -1358,7 +1358,7 @@ func createPodStatusReadyTimeFamilyGenerator() generator.FamilyGenerator {
13581358
ms := []*metric.Metric{}
13591359

13601360
for _, c := range p.Status.Conditions {
1361-
if c.Type == v1.PodReady {
1361+
if c.Type == v1.PodReady && c.Status == v1.ConditionTrue {
13621362
ms = append(ms, &metric.Metric{
13631363
LabelKeys: []string{},
13641364
LabelValues: []string{},

internal/store/pod_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,31 @@ func TestPodStore(t *testing.T) {
14601460
`,
14611461
MetricNames: []string{"kube_pod_status_container_ready_time"},
14621462
},
1463+
{
1464+
Obj: &v1.Pod{
1465+
ObjectMeta: metav1.ObjectMeta{
1466+
Name: "pod1",
1467+
Namespace: "ns1",
1468+
UID: "uid1",
1469+
},
1470+
Status: v1.PodStatus{
1471+
Conditions: []v1.PodCondition{
1472+
{
1473+
Type: v1.ContainersReady,
1474+
Status: v1.ConditionFalse,
1475+
LastTransitionTime: metav1.Time{
1476+
Time: time.Unix(1501666018, 0),
1477+
},
1478+
},
1479+
},
1480+
},
1481+
},
1482+
Want: `
1483+
# HELP kube_pod_status_container_ready_time Readiness achieved time in unix timestamp for a pod containers.
1484+
# TYPE kube_pod_status_container_ready_time gauge
1485+
`,
1486+
MetricNames: []string{"kube_pod_status_container_ready_time"},
1487+
},
14631488
{
14641489
Obj: &v1.Pod{
14651490
ObjectMeta: metav1.ObjectMeta{
@@ -1515,7 +1540,6 @@ func TestPodStore(t *testing.T) {
15151540
# HELP kube_pod_status_ready_time Readiness achieved time in unix timestamp for a pod.
15161541
# TYPE kube_pod_status_ready gauge
15171542
# TYPE kube_pod_status_ready_time gauge
1518-
kube_pod_status_ready_time{namespace="ns2",pod="pod2",uid="uid2"} 1.501666018e+09
15191543
kube_pod_status_ready{condition="false",namespace="ns2",pod="pod2",uid="uid2"} 1
15201544
kube_pod_status_ready{condition="true",namespace="ns2",pod="pod2",uid="uid2"} 0
15211545
kube_pod_status_ready{condition="unknown",namespace="ns2",pod="pod2",uid="uid2"} 0

0 commit comments

Comments
 (0)