diff --git a/internal/store/job.go b/internal/store/job.go index 6e0e97b218..8dd53b0a19 100644 --- a/internal/store/job.go +++ b/internal/store/job.go @@ -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) @@ -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, diff --git a/internal/store/job_test.go b/internal/store/job_test.go index b45ac1ab15..b808c321b5 100644 --- a/internal/store/job_test.go +++ b/internal/store/job_test.go @@ -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 `, }, {