Skip to content

Commit 86bf8f2

Browse files
authored
Merge pull request #1971 from ryanrolds/rolds/bug_fix_pod_container_ready_time
Fixing emitting of ready time metrics when condition is false
2 parents c530a7b + 67ed488 commit 86bf8f2

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
@@ -1347,7 +1347,7 @@ func createPodStatusContainerReadyTimeFamilyGenerator() generator.FamilyGenerato
13471347
ms := []*metric.Metric{}
13481348

13491349
for _, c := range p.Status.Conditions {
1350-
if c.Type == v1.ContainersReady {
1350+
if c.Type == v1.ContainersReady && c.Status == v1.ConditionTrue {
13511351
ms = append(ms, &metric.Metric{
13521352
LabelKeys: []string{},
13531353
LabelValues: []string{},
@@ -1375,7 +1375,7 @@ func createPodStatusReadyTimeFamilyGenerator() generator.FamilyGenerator {
13751375
ms := []*metric.Metric{}
13761376

13771377
for _, c := range p.Status.Conditions {
1378-
if c.Type == v1.PodReady {
1378+
if c.Type == v1.PodReady && c.Status == v1.ConditionTrue {
13791379
ms = append(ms, &metric.Metric{
13801380
LabelKeys: []string{},
13811381
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)