Skip to content

Commit

Permalink
Merge pull request #2485 from richabanker/no-job-conditions-fix
Browse files Browse the repository at this point in the history
fix: set kube_job_status_failed metric even when there are no job.Status.Conditions present
  • Loading branch information
k8s-ci-robot authored Sep 12, 2024
2 parents aebbb39 + 643739d commit 76ef241
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/store/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ func jobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}
}

reasonKnown := false
for _, c := range j.Status.Conditions {
condition := c
if condition.Type == v1batch.JobFailed {
reasonKnown := false
for _, reason := range jobFailureReasons {
reasonKnown = reasonKnown || failureReason(&condition, reason)

Expand All @@ -233,16 +233,16 @@ func jobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
Value: boolFloat64(failureReason(&condition, reason)),
})
}
// for unknown reasons
if !reasonKnown {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"reason"},
LabelValues: []string{""},
Value: float64(j.Status.Failed),
})
}
}
}
// for unknown reasons
if !reasonKnown {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"reason"},
LabelValues: []string{""},
Value: float64(j.Status.Failed),
})
}

return &metric.Family{
Metrics: ms,
Expand Down
22 changes: 22 additions & 0 deletions internal/store/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,28 @@ func TestJobStore(t *testing.T) {
kube_job_status_failed{job_name="FailedJob1",namespace="ns1",reason="Evicted"} 0
kube_job_status_start_time{job_name="FailedJob1",namespace="ns1"} 1.495807207e+09
kube_job_status_succeeded{job_name="FailedJob1",namespace="ns1"} 0
`,
},
{
Obj: &v1batch.Job{
ObjectMeta: metav1.ObjectMeta{
Name: "FailedJobWithNoConditions",
Namespace: "ns1",
},
Status: v1batch.JobStatus{
Failed: 1,
},
Spec: v1batch.JobSpec{
ActiveDeadlineSeconds: &ActiveDeadlineSeconds900,
},
},
Want: metadata + `
kube_job_owner{job_name="FailedJobWithNoConditions",namespace="ns1",owner_is_controller="",owner_kind="",owner_name=""} 1
kube_job_info{job_name="FailedJobWithNoConditions",namespace="ns1"} 1
kube_job_spec_active_deadline_seconds{job_name="FailedJobWithNoConditions",namespace="ns1"} 900
kube_job_status_active{job_name="FailedJobWithNoConditions",namespace="ns1"} 0
kube_job_status_failed{job_name="FailedJobWithNoConditions",namespace="ns1",reason=""} 1
kube_job_status_succeeded{job_name="FailedJobWithNoConditions",namespace="ns1"} 0
`,
},
{
Expand Down

0 comments on commit 76ef241

Please sign in to comment.