Skip to content

Commit

Permalink
Merge pull request #1971 from ryanrolds/rolds/bug_fix_pod_container_r…
Browse files Browse the repository at this point in the history
…eady_time

Fixing emitting of ready time metrics when condition is false
  • Loading branch information
k8s-ci-robot committed Feb 6, 2023
2 parents c530a7b + 67ed488 commit 86bf8f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/store/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -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{},
Expand Down
26 changes: 25 additions & 1 deletion internal/store/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 86bf8f2

Please sign in to comment.