Skip to content

Commit

Permalink
Merge pull request #6715 from nilesh-akhade/metric
Browse files Browse the repository at this point in the history
Remove schedule-related metrics on schedule delete
  • Loading branch information
shubham-pampattiwar authored Sep 25, 2023
2 parents 4bf87c0 + c7c4413 commit c3ec7b7
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/6715-nilesh-akhade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove schedule-related metrics on schedule delete
1 change: 1 addition & 0 deletions pkg/controller/schedule_controller.go
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@ func (c *scheduleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
if err := c.Get(ctx, req.NamespacedName, schedule); err != nil {
if apierrors.IsNotFound(err) {
log.WithError(err).Error("schedule not found")
c.metrics.RemoveSchedule(req.Name)
return ctrl.Result{}, nil
}
return ctrl.Result{}, errors.Wrapf(err, "error getting schedule %s", req.String())
82 changes: 82 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -505,6 +505,88 @@ func (m *ServerMetrics) InitSchedule(scheduleName string) {
}
}

// RemoveSchedule removes metrics associated with a specified schedule.
func (m *ServerMetrics) RemoveSchedule(scheduleName string) {
if g, ok := m.metrics[backupTarballSizeBytesGauge].(*prometheus.GaugeVec); ok {
g.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupAttemptTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupSuccessTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupPartialFailureTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupFailureTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupValidationFailureTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if h, ok := m.metrics[backupDurationSeconds].(*prometheus.HistogramVec); ok {
h.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupDeletionAttemptTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupDeletionSuccessTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupDeletionFailureTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if g, ok := m.metrics[backupLastSuccessfulTimestamp].(*prometheus.GaugeVec); ok {
g.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupItemsTotalGauge].(*prometheus.GaugeVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupItemsErrorsGauge].(*prometheus.GaugeVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupWarningTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[backupLastStatus].(*prometheus.GaugeVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[restoreAttemptTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[restorePartialFailureTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[restoreFailedTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[restoreSuccessTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[restoreValidationFailedTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[volumeSnapshotSuccessTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[volumeSnapshotAttemptTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[volumeSnapshotFailureTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName)
}
if c, ok := m.metrics[csiSnapshotAttemptTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName, "")
}
if c, ok := m.metrics[csiSnapshotSuccessTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName, "")
}
if c, ok := m.metrics[csiSnapshotFailureTotal].(*prometheus.CounterVec); ok {
c.DeleteLabelValues(scheduleName, "")
}
}

// InitSchedule initializes counter metrics for a node.
func (m *ServerMetrics) InitMetricsForNode(node string) {
if c, ok := m.metrics[podVolumeBackupEnqueueTotal].(*prometheus.CounterVec); ok {

0 comments on commit c3ec7b7

Please sign in to comment.