Skip to content

Commit 76ef241

Browse files
authored
Merge pull request #2485 from richabanker/no-job-conditions-fix
fix: set kube_job_status_failed metric even when there are no job.Status.Conditions present
2 parents aebbb39 + 643739d commit 76ef241

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

internal/store/job.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ func jobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
219219
}
220220
}
221221

222+
reasonKnown := false
222223
for _, c := range j.Status.Conditions {
223224
condition := c
224225
if condition.Type == v1batch.JobFailed {
225-
reasonKnown := false
226226
for _, reason := range jobFailureReasons {
227227
reasonKnown = reasonKnown || failureReason(&condition, reason)
228228

@@ -233,16 +233,16 @@ func jobMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
233233
Value: boolFloat64(failureReason(&condition, reason)),
234234
})
235235
}
236-
// for unknown reasons
237-
if !reasonKnown {
238-
ms = append(ms, &metric.Metric{
239-
LabelKeys: []string{"reason"},
240-
LabelValues: []string{""},
241-
Value: float64(j.Status.Failed),
242-
})
243-
}
244236
}
245237
}
238+
// for unknown reasons
239+
if !reasonKnown {
240+
ms = append(ms, &metric.Metric{
241+
LabelKeys: []string{"reason"},
242+
LabelValues: []string{""},
243+
Value: float64(j.Status.Failed),
244+
})
245+
}
246246

247247
return &metric.Family{
248248
Metrics: ms,

internal/store/job_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,28 @@ func TestJobStore(t *testing.T) {
208208
kube_job_status_failed{job_name="FailedJob1",namespace="ns1",reason="Evicted"} 0
209209
kube_job_status_start_time{job_name="FailedJob1",namespace="ns1"} 1.495807207e+09
210210
kube_job_status_succeeded{job_name="FailedJob1",namespace="ns1"} 0
211+
`,
212+
},
213+
{
214+
Obj: &v1batch.Job{
215+
ObjectMeta: metav1.ObjectMeta{
216+
Name: "FailedJobWithNoConditions",
217+
Namespace: "ns1",
218+
},
219+
Status: v1batch.JobStatus{
220+
Failed: 1,
221+
},
222+
Spec: v1batch.JobSpec{
223+
ActiveDeadlineSeconds: &ActiveDeadlineSeconds900,
224+
},
225+
},
226+
Want: metadata + `
227+
kube_job_owner{job_name="FailedJobWithNoConditions",namespace="ns1",owner_is_controller="",owner_kind="",owner_name=""} 1
228+
kube_job_info{job_name="FailedJobWithNoConditions",namespace="ns1"} 1
229+
kube_job_spec_active_deadline_seconds{job_name="FailedJobWithNoConditions",namespace="ns1"} 900
230+
kube_job_status_active{job_name="FailedJobWithNoConditions",namespace="ns1"} 0
231+
kube_job_status_failed{job_name="FailedJobWithNoConditions",namespace="ns1",reason=""} 1
232+
kube_job_status_succeeded{job_name="FailedJobWithNoConditions",namespace="ns1"} 0
211233
`,
212234
},
213235
{

0 commit comments

Comments
 (0)