Skip to content

Commit

Permalink
Add backup_active_total metric.
Browse files Browse the repository at this point in the history
This counts the number of backups currently in progress.

Signed-off-by: Matthew Arnold <[email protected]>

Better metrics function names.

Signed-off-by: Matthew Arnold <[email protected]>

Update copyright notice as per contribution guidelines.

Signed-off-by: Matthew Arnold <[email protected]>

Add changelog file.

Signed-off-by: Matthew Arnold <[email protected]>

Rework backup_active_total after rebase.

Signed-off-by: Matthew Arnold <[email protected]>
  • Loading branch information
mrnold committed Oct 15, 2024
1 parent 34d4f18 commit fd6f375
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelogs/unreleased/5703-mrnold
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add velero_backup_active_total metric
2 changes: 2 additions & 0 deletions pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,12 @@ func (b *backupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
original = request.Backup.DeepCopy()

b.backupTracker.Add(request.Namespace, request.Name)
b.metrics.IncrementActiveBackupTotal()
defer func() {
switch request.Status.Phase {
case velerov1api.BackupPhaseCompleted, velerov1api.BackupPhasePartiallyFailed, velerov1api.BackupPhaseFailed, velerov1api.BackupPhaseFailedValidation:
b.backupTracker.Delete(request.Namespace, request.Name)
b.metrics.DecrementActiveBackupTotal()
}
}()

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/backup_finalizer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (r *backupFinalizerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
velerov1api.BackupPhaseFailed,
velerov1api.BackupPhaseFailedValidation:
r.backupTracker.Delete(backup.Namespace, backup.Name)
r.metrics.DecrementActiveBackupTotal()
}
// Always attempt to Patch the backup object and status after each reconciliation.
//
Expand Down
24 changes: 23 additions & 1 deletion pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@ const (
//Velero metrics
backupTarballSizeBytesGauge = "backup_tarball_size_bytes"
backupTotal = "backup_total"
backupActiveTotal = "backup_active_total"
backupAttemptTotal = "backup_attempt_total"
backupSuccessTotal = "backup_success_total"
backupPartialFailureTotal = "backup_partial_failure_total"
Expand Down Expand Up @@ -113,6 +114,13 @@ func NewServerMetrics() *ServerMetrics {
Help: "Current number of existent backups",
},
),
backupActiveTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: backupActiveTotal,
Help: "Number of backups currently in progress",
},
),
backupAttemptTotal: prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Expand Down Expand Up @@ -706,6 +714,20 @@ func (m *ServerMetrics) SetBackupTotal(numberOfBackups int64) {
}
}

// IncrementActiveBackupTotal increments the number of in-progress backups
func (m *ServerMetrics) IncrementActiveBackupTotal() {
if g, ok := m.metrics[backupActiveTotal].(prometheus.Gauge); ok {
g.Inc()
}
}

// DecrementActiveBackupTotal decrements the number of in-progress backups
func (m *ServerMetrics) DecrementActiveBackupTotal() {
if g, ok := m.metrics[backupActiveTotal].(prometheus.Gauge); ok {
g.Dec()
}
}

// RegisterBackupAttempt records an backup attempt.
func (m *ServerMetrics) RegisterBackupAttempt(backupSchedule string) {
if c, ok := m.metrics[backupAttemptTotal].(*prometheus.CounterVec); ok {
Expand Down

0 comments on commit fd6f375

Please sign in to comment.