Update according to comments. Remove csiVolumeSnapshotsStorageTotal related code.

Signed-off-by: Xun Jiang <jxun@vmware.com>
This commit is contained in:
Xun Jiang
2022-04-15 08:05:56 +00:00
parent 4daeec7ab9
commit 9aa4e9e860
7 changed files with 20 additions and 81 deletions
+4 -9
View File
@@ -311,20 +311,15 @@ type BackupStatus struct {
// +nullable
Progress *BackupProgress `json:"progress,omitempty"`
// CsiVolumeSnapshotsAttempted is the total number of attempted
// CSIVolumeSnapshotsAttempted is the total number of attempted
// CSI VolumeSnapshots for this backup.
// +optional
CsiVolumeSnapshotsAttempted int `json:"csiVolumeSnapshotsAttempted,omitempty"`
CSIVolumeSnapshotsAttempted int `json:"csiVolumeSnapshotsAttempted,omitempty"`
// CsiVolumeSnapshotsCompleted is the total number of successfully
// CSIVolumeSnapshotsCompleted is the total number of successfully
// completed CSI VolumeSnapshots for this backup.
// +optional
CsiVolumeSnapshotsCompleted int `json:"csiVolumeSnapshotsCompleted,omitempty"`
// CsiVolumeSnapshotsStorageTotal is the total storage size of created
// snapshots for this backup.
// +optional
CsiVolumeSnapshotsStorageTotal int64 `json:"csiVolumeSnapshotsStorageTotal,omitempty"`
CSIVolumeSnapshotsCompleted int `json:"csiVolumeSnapshotsCompleted,omitempty"`
}
// BackupProgress stores information about the progress of a Backup's execution.
+1 -1
View File
@@ -50,7 +50,7 @@ type Request struct {
VolumeSnapshots []*volume.Snapshot
PodVolumeBackups []*velerov1api.PodVolumeBackup
BackedUpItems map[itemKey]struct{}
CsiSnapshots []*snapshotv1api.VolumeSnapshot
CSISnapshots []*snapshotv1api.VolumeSnapshot
}
// BackupResourceList returns the list of backed up resources grouped by the API
+6 -13
View File
@@ -636,16 +636,10 @@ func (c *backupController) runBackup(backup *pkgbackup.Request) error {
}
}
backup.Status.CsiVolumeSnapshotsAttempted = len(backup.CsiSnapshots)
for _, vs := range backup.CsiSnapshots {
backup.Status.CSIVolumeSnapshotsAttempted = len(backup.CSISnapshots)
for _, vs := range backup.CSISnapshots {
if *vs.Status.ReadyToUse {
backup.Status.CsiVolumeSnapshotsCompleted++
storageSize, ret := vs.Status.RestoreSize.AsInt64()
if !ret {
backupLog.WithError(fmt.Errorf("fail to convert CSI snapshot size: %v to int64", backup.Status.CsiVolumeSnapshotsStorageTotal))
storageSize = 0
}
backup.Status.CsiVolumeSnapshotsStorageTotal += storageSize
backup.Status.CSIVolumeSnapshotsCompleted++
}
}
@@ -709,10 +703,9 @@ func recordBackupMetrics(log logrus.FieldLogger, backup *velerov1api.Backup, bac
serverMetrics.RegisterVolumeSnapshotFailures(backupScheduleName, backup.Status.VolumeSnapshotsAttempted-backup.Status.VolumeSnapshotsCompleted)
if features.IsEnabled(velerov1api.CSIFeatureFlag) {
serverMetrics.RegisterCsiSnapshotAttempts(backupScheduleName, backup.Name, backup.Status.CsiVolumeSnapshotsAttempted)
serverMetrics.RegisterCsiSnapshotSuccesses(backupScheduleName, backup.Name, backup.Status.CsiVolumeSnapshotsCompleted)
serverMetrics.RegisterCsiSnapshotFailures(backupScheduleName, backup.Name, backup.Status.CsiVolumeSnapshotsAttempted-backup.Status.CsiVolumeSnapshotsCompleted)
serverMetrics.RegisterCsiStorageSizeAdd(backupScheduleName, backup.Name, backup.Status.CsiVolumeSnapshotsStorageTotal)
serverMetrics.RegisterCSISnapshotAttempts(backupScheduleName, backup.Name, backup.Status.CSIVolumeSnapshotsAttempted)
serverMetrics.RegisterCSISnapshotSuccesses(backupScheduleName, backup.Name, backup.Status.CSIVolumeSnapshotsCompleted)
serverMetrics.RegisterCSISnapshotFailures(backupScheduleName, backup.Name, backup.Status.CSIVolumeSnapshotsAttempted-backup.Status.CSIVolumeSnapshotsCompleted)
}
if backup.Status.Progress != nil {
@@ -28,7 +28,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
@@ -40,7 +39,6 @@ import (
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
pkgbackup "github.com/vmware-tanzu/velero/pkg/backup"
"github.com/vmware-tanzu/velero/pkg/discovery"
"github.com/vmware-tanzu/velero/pkg/features"
velerov1client "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
velerov1informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions/velero/v1"
velerov1listers "github.com/vmware-tanzu/velero/pkg/generated/listers/velero/v1"
@@ -409,25 +407,6 @@ func (c *backupDeletionController) processRequest(req *velerov1api.DeleteBackupR
c.metrics.RegisterBackupDeletionFailed(backupScheduleName)
}
if features.IsEnabled(velerov1api.CSIFeatureFlag) {
vss, err := backupStore.GetCSIVolumeSnapshots(backup.Name)
if err != nil {
errs = append(errs, err.Error())
}
var restoreSizeTotal resource.Quantity
for _, vs := range vss {
restoreSizeTotal.Add(*vs.Status.RestoreSize)
}
storageSize, ret := restoreSizeTotal.AsInt64()
if !ret {
log.WithError(fmt.Errorf("fail to convert CSI snapshot size: %v to int64", backup.Status.CsiVolumeSnapshotsStorageTotal))
storageSize = 0
}
c.metrics.RegisterCsiStorageSizeSub(backupScheduleName, backup.Name, storageSize)
}
// Update status to processed and record errors
req, err = c.patchDeleteBackupRequest(req, func(r *velerov1api.DeleteBackupRequest) {
r.Status.Phase = velerov1api.DeleteBackupRequestPhaseProcessed
+6 -29
View File
@@ -57,7 +57,6 @@ const (
csiSnapshotAttemptTotal = "csi_snapshot_attempt_total"
csiSnapshotSuccessTotal = "csi_snapshot_success_total"
csiSnapshotFailureTotal = "csi_snapshot_failure_total"
csiSnapshotStorageTotal = "csi_snapshot_storage_total"
// Restic metrics
podVolumeBackupEnqueueTotal = "pod_volume_backup_enqueue_count"
@@ -294,14 +293,6 @@ func NewServerMetrics() *ServerMetrics {
},
[]string{scheduleLabel, backupNameLabel},
),
csiSnapshotStorageTotal: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: csiSnapshotStorageTotal,
Help: "Total size of CSI volume snapshots storage size",
},
[]string{scheduleLabel, backupNameLabel},
),
},
}
}
@@ -628,37 +619,23 @@ func (m *ServerMetrics) RegisterVolumeSnapshotFailures(backupSchedule string, vo
}
}
// RegisterCsiSnapshotAttempts records an attempt to snapshot a volume by CSI plugin.
func (m *ServerMetrics) RegisterCsiSnapshotAttempts(backupSchedule, backupName string, csiSnapshotsAttempted int) {
// RegisterCSISnapshotAttempts records an attempt to snapshot a volume by CSI plugin.
func (m *ServerMetrics) RegisterCSISnapshotAttempts(backupSchedule, backupName string, csiSnapshotsAttempted int) {
if c, ok := m.metrics[csiSnapshotAttemptTotal].(*prometheus.CounterVec); ok {
c.WithLabelValues(backupSchedule, backupName).Add(float64(csiSnapshotsAttempted))
}
}
// RegisterCsiSnapshotSuccesses records a completed volume snapshot by CSI plugin.
func (m *ServerMetrics) RegisterCsiSnapshotSuccesses(backupSchedule, backupName string, csiSnapshotCompleted int) {
// RegisterCSISnapshotSuccesses records a completed volume snapshot by CSI plugin.
func (m *ServerMetrics) RegisterCSISnapshotSuccesses(backupSchedule, backupName string, csiSnapshotCompleted int) {
if c, ok := m.metrics[csiSnapshotSuccessTotal].(*prometheus.CounterVec); ok {
c.WithLabelValues(backupSchedule, backupName).Add(float64(csiSnapshotCompleted))
}
}
// RegisterCsiSnapshotFailures records a failed volume snapshot by CSI plugin.
func (m *ServerMetrics) RegisterCsiSnapshotFailures(backupSchedule, backupName string, csiSnapshotsFailed int) {
// RegisterCSISnapshotFailures records a failed volume snapshot by CSI plugin.
func (m *ServerMetrics) RegisterCSISnapshotFailures(backupSchedule, backupName string, csiSnapshotsFailed int) {
if c, ok := m.metrics[csiSnapshotFailureTotal].(*prometheus.CounterVec); ok {
c.WithLabelValues(backupSchedule, backupName).Add(float64(csiSnapshotsFailed))
}
}
// RegisterCsiStorageSizeAdd records volume snapshot's storage size increase created by CSI plugin.
func (m *ServerMetrics) RegisterCsiStorageSizeAdd(backupSchedule, backupName string, csiStorageSize int64) {
if g, ok := m.metrics[csiSnapshotStorageTotal].(*prometheus.GaugeVec); ok {
g.WithLabelValues(backupSchedule, backupName).Add(float64(csiStorageSize))
}
}
// RegisterCsiStorageSizeSub records volume snapshot's storage size decrease created by CSI plugin.
func (m *ServerMetrics) RegisterCsiStorageSizeSub(backupSchedule, backupName string, csiStorageSize int64) {
if g, ok := m.metrics[csiSnapshotStorageTotal].(*prometheus.GaugeVec); ok {
g.WithLabelValues(backupSchedule, backupName).Sub(float64(csiStorageSize))
}
}