diff --git a/controllers/backup_integration_test.go b/controllers/backup_integration_test.go index eb958ff2e..0ed1e3151 100644 --- a/controllers/backup_integration_test.go +++ b/controllers/backup_integration_test.go @@ -93,7 +93,7 @@ func (ts *BackupTestSuite) Test_GivenFinishedPreBackupDeployment_WhenReconciling ts.expectABackupJobEventually() ts.markBackupAsFinished(ts.BackupResource) - suceeded := observer.Suceeded + suceeded := observer.Succeeded ts.notifyObserverOfBackupJobStatusChange(suceeded) ts.assertDeploymentIsDeleted(ts.newPreBackupDeployment()) diff --git a/controllers/check_integration_test.go b/controllers/check_integration_test.go index dad51f420..543290daa 100644 --- a/controllers/check_integration_test.go +++ b/controllers/check_integration_test.go @@ -107,7 +107,7 @@ func (ts *CheckTestSuite) whenJobCallbackIsInvoked(checkName string) { o := observer.GetObserver() observableJob := o.GetJobByName(checkNSName.String()) - observableJob.Event = observer.Suceeded + observableJob.Event = observer.Succeeded observableJob.Job = check eventChannel := o.GetUpdateChannel() diff --git a/executor/generic.go b/executor/generic.go index fe0bbaad0..23baf6f36 100644 --- a/executor/generic.go +++ b/executor/generic.go @@ -131,7 +131,7 @@ func (g *generic) RegisterJobSucceededConditionCallback() { name := g.GetJobNamespacedName() observer.GetObserver().RegisterCallback(name.String(), func(event observer.ObservableJob) { switch event.Event { - case observer.Suceeded: + case observer.Succeeded: g.SetFinished(event.Job.Namespace, event.Job.Name) g.SetConditionTrueWithMessage(k8upv1alpha1.ConditionCompleted, k8upv1alpha1.ReasonSucceeded, diff --git a/handler/job.go b/handler/job.go index 01b2ef90c..b03348647 100644 --- a/handler/job.go +++ b/handler/job.go @@ -55,7 +55,7 @@ func (j *JobHandler) Handle() error { } if j.job.Status.Succeeded > 0 { - jobEvent = observer.Suceeded + jobEvent = observer.Succeeded } if j.job.Status.Failed > 0 { @@ -69,14 +69,14 @@ func (j *JobHandler) Handle() error { exclusive = false } - jobType := v1alpha1.ScheduleType - if j.Config.Obj != nil { - jobType = j.Config.Obj.GetType() + jobType, exists := j.job.GetLabels()[v1alpha1.LabelK8upType] + if !exists { + jobType = v1alpha1.ScheduleType.String() } oj := observer.ObservableJob{ Job: j.job, - JobType: jobType, + JobType: v1alpha1.JobType(jobType), Exclusive: exclusive, Event: jobEvent, } diff --git a/observer/observer.go b/observer/observer.go index cd5f0473e..6361968d3 100644 --- a/observer/observer.go +++ b/observer/observer.go @@ -17,12 +17,12 @@ import ( ) const ( - Update EventType = "update" - Delete EventType = "delete" - Create EventType = "create" - Failed EventType = "failed" - Suceeded EventType = "suceeded" - Running EventType = "running" + Update EventType = "update" + Delete EventType = "delete" + Create EventType = "create" + Failed EventType = "failed" + Succeeded EventType = "succeeded" + Running EventType = "running" ) var ( @@ -30,16 +30,17 @@ var ( promLabels = []string{ "namespace", + "jobType", } metricsFailureCounter = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "k8up_jobs_failed_counter", - Help: "The total number of backups that failed", + Help: "The total number of jobs that failed", }, promLabels) metricsSuccessCounter = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "k8up_jobs_successful_counter", - Help: "The total number of backups that went through cleanly", + Help: "The total number of jobs that went through cleanly", }, promLabels) metricsTotalCounter = promauto.NewCounterVec(prometheus.CounterOpts{ @@ -120,15 +121,15 @@ func (o *Observer) handleEvent(event ObservableJob) { switch event.Event { case Failed: - incFailureCounters(event.Job.Namespace) + incFailureCounters(event.Job.Namespace, event.JobType) invokeCallbacks(event) - case Suceeded: + case Succeeded: // Only report succeeded jobs we've already seen to prevent // reporting succeeded jobs on operator restart if exists { o.log.Info("job succeeded", "jobName", jobName) o.observedJobs[jobName] = event - incSuccessCounters(event.Job.Namespace) + incSuccessCounters(event.Job.Namespace, event.JobType) invokeCallbacks(event) } case Delete: @@ -254,12 +255,12 @@ func (o *Observer) RegisterCallback(name string, callback ObservableJobCallback) } } -func incFailureCounters(namespace string) { - metricsFailureCounter.WithLabelValues(namespace).Inc() - metricsTotalCounter.WithLabelValues(namespace).Inc() +func incFailureCounters(namespace string, jobType v1alpha1.JobType) { + metricsFailureCounter.WithLabelValues(namespace, jobType.String()).Inc() + metricsTotalCounter.WithLabelValues(namespace, jobType.String()).Inc() } -func incSuccessCounters(namespace string) { - metricsSuccessCounter.WithLabelValues(namespace).Inc() - metricsTotalCounter.WithLabelValues(namespace).Inc() +func incSuccessCounters(namespace string, jobType v1alpha1.JobType) { + metricsSuccessCounter.WithLabelValues(namespace, jobType.String()).Inc() + metricsTotalCounter.WithLabelValues(namespace, jobType.String()).Inc() } diff --git a/observer/observer_test.go b/observer/observer_test.go index 5a96082fc..d900da968 100644 --- a/observer/observer_test.go +++ b/observer/observer_test.go @@ -78,7 +78,7 @@ func TestObserver_AreAllCallbacksInvoked(t *testing.T) { }, }, JobType: v1alpha1.BackupType, - Event: Suceeded, + Event: Succeeded, Exclusive: true, Repository: "some-repo", callbacks: callbacks, @@ -110,7 +110,7 @@ func TestObserver_AreOnlyExpectedCallbacksInvoked(t *testing.T) { expectInvocation bool }{ "GivenStatusSucceeded_WhenHandleEvent_ThenExpectInvocation": { - givenEventType: Suceeded, + givenEventType: Succeeded, expectInvocation: true, }, "GivenStatusFailed_WhenHandleEvent_ThenExpectInvocation": {