Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/9059-reasonerjt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Gauge metric for BSL availability
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/vmware-tanzu/velero

go 1.23.0

toolchain go1.23.6

require (
cloud.google.com/go/storage v1.54.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.18.0
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@
},
newPluginManager,
backupStoreGetter,
s.metrics,

Check warning on line 593 in pkg/cmd/server/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/server/server.go#L593

Added line #L593 was not covered by tests
s.logger,
)
if err := bslr.SetupWithManager(s.mgr); err != nil {
Expand Down
10 changes: 8 additions & 2 deletions pkg/controller/backup_storage_location_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"strings"
"time"

"github.com/vmware-tanzu/velero/pkg/metrics"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -53,8 +55,8 @@
// replaced with fakes for testing.
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager
backupStoreGetter persistence.ObjectBackupStoreGetter

log logrus.FieldLogger
metrics *metrics.ServerMetrics
log logrus.FieldLogger
}

// NewBackupStorageLocationReconciler initialize and return a backupStorageLocationReconciler struct
Expand All @@ -64,13 +66,15 @@
defaultBackupLocationInfo storage.DefaultBackupLocationInfo,
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
backupStoreGetter persistence.ObjectBackupStoreGetter,
metrics *metrics.ServerMetrics,
log logrus.FieldLogger) *backupStorageLocationReconciler {
return &backupStorageLocationReconciler{
ctx: ctx,
client: client,
defaultBackupLocationInfo: defaultBackupLocationInfo,
newPluginManager: newPluginManager,
backupStoreGetter: backupStoreGetter,
metrics: metrics,

Check warning on line 77 in pkg/controller/backup_storage_location_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_storage_location_controller.go#L77

Added line #L77 was not covered by tests
log: log,
}
}
Expand Down Expand Up @@ -164,8 +168,10 @@
switch phase {
case velerov1api.BackupStorageLocationPhaseAvailable:
availableBSLs = append(availableBSLs, &locationList.Items[i])
r.metrics.RegisterBackupLocationAvailable(locationList.Items[i].Name)
case velerov1api.BackupStorageLocationPhaseUnavailable:
unAvailableBSLs = append(unAvailableBSLs, &locationList.Items[i])
r.metrics.RegisterBackupLocationUnavailable(locationList.Items[i].Name)

Check warning on line 174 in pkg/controller/backup_storage_location_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_storage_location_controller.go#L174

Added line #L174 was not covered by tests
default:
unknownBSLs = append(unknownBSLs, &locationList.Items[i])
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/backup_storage_location_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"testing"
"time"

"github.com/vmware-tanzu/velero/pkg/metrics"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
Expand Down Expand Up @@ -92,6 +94,7 @@ var _ = Describe("Backup Storage Location Reconciler", func() {
},
newPluginManager: func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
backupStoreGetter: NewFakeObjectBackupStoreGetter(backupStores),
metrics: metrics.NewServerMetrics(),
log: velerotest.NewLogger(),
}

Expand Down Expand Up @@ -157,6 +160,7 @@ var _ = Describe("Backup Storage Location Reconciler", func() {
},
newPluginManager: func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
backupStoreGetter: NewFakeObjectBackupStoreGetter(backupStores),
metrics: metrics.NewServerMetrics(),
log: velerotest.NewLogger(),
}

Expand Down Expand Up @@ -245,6 +249,7 @@ func TestEnsureSingleDefaultBSL(t *testing.T) {
ctx: context.Background(),
client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(&test.locations).Build(),
defaultBackupLocationInfo: test.defaultBackupInfo,
metrics: metrics.NewServerMetrics(),
log: velerotest.NewLogger(),
}
defaultFound, err := r.ensureSingleDefaultBSL(test.locations)
Expand Down Expand Up @@ -289,6 +294,7 @@ func TestBSLReconcile(t *testing.T) {
ctx: context.Background(),
client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(&test.locationList).Build(),
newPluginManager: func(logrus.FieldLogger) clientmgmt.Manager { return pluginManager },
metrics: metrics.NewServerMetrics(),
log: velerotest.NewLogger(),
}

Expand Down
24 changes: 24 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
backupItemsErrorsGauge = "backup_items_errors"
backupWarningTotal = "backup_warning_total"
backupLastStatus = "backup_last_status"
backupLocationStatus = "backup_location_status_gauge"
restoreTotal = "restore_total"
restoreAttemptTotal = "restore_attempt_total"
restoreValidationFailedTotal = "restore_validation_failed_total"
Expand Down Expand Up @@ -77,6 +78,7 @@
// Labels
nodeMetricLabel = "node"
podVolumeOperationLabel = "operation"
bslNameLabel = "backup_location_name"
pvbNameLabel = "pod_volume_backup"
scheduleLabel = "schedule"
backupNameLabel = "backupName"
Expand Down Expand Up @@ -228,6 +230,14 @@
},
[]string{scheduleLabel},
),
backupLocationStatus: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: backupLocationStatus,
Help: "The status of backup location. A value of 1 is available, 0 is unavailable",
},
[]string{bslNameLabel},
),
restoreTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Expand Down Expand Up @@ -888,3 +898,17 @@
c.WithLabelValues(backupSchedule, backupName).Add(float64(csiSnapshotsFailed))
}
}

// RegisterBackupLocationAvailable records the availability of a backup location.
func (m *ServerMetrics) RegisterBackupLocationAvailable(backupLocationName string) {
if g, ok := m.metrics[backupLocationStatus].(*prometheus.GaugeVec); ok {
g.WithLabelValues(backupLocationName).Set(float64(1))
}
}

// RegisterBackupLocationUnavailable records the availability of a backup location.
func (m *ServerMetrics) RegisterBackupLocationUnavailable(backupLocationName string) {
if g, ok := m.metrics[backupLocationStatus].(*prometheus.GaugeVec); ok {
g.WithLabelValues(backupLocationName).Set(float64(0))
}

Check warning on line 913 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L910-L913

Added lines #L910 - L913 were not covered by tests
}
Loading