recompute backup_last_successful_timestamp metric during resync
Signed-off-by: Steve Kriss <krisss@vmware.com>pull/2196/head
parent
b2acd3b683
commit
9fa302aa8b
|
@ -148,12 +148,36 @@ func NewBackupController(
|
|||
}
|
||||
|
||||
func (c *backupController) resync() {
|
||||
// recompute backup_total metric
|
||||
backups, err := c.lister.List(labels.Everything())
|
||||
if err != nil {
|
||||
c.logger.Error(err, "Error computing backup_total metric")
|
||||
} else {
|
||||
c.metrics.SetBackupTotal(int64(len(backups)))
|
||||
}
|
||||
|
||||
// recompute backup_last_successful_timestamp metric for each
|
||||
// schedule (including the empty schedule, i.e. ad-hoc backups)
|
||||
lastSuccessBySchedule := map[string]time.Time{}
|
||||
for _, backup := range backups {
|
||||
if backup.Status.Phase != velerov1api.BackupPhaseCompleted {
|
||||
continue
|
||||
}
|
||||
if backup.Status.CompletionTimestamp == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
schedule := backup.Labels[velerov1api.ScheduleNameLabel]
|
||||
timestamp := backup.Status.CompletionTimestamp.Time
|
||||
|
||||
if timestamp.After(lastSuccessBySchedule[schedule]) {
|
||||
lastSuccessBySchedule[schedule] = timestamp
|
||||
}
|
||||
}
|
||||
|
||||
for schedule, timestamp := range lastSuccessBySchedule {
|
||||
c.metrics.SetBackupLastSuccessfulTimestamp(schedule, timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *backupController) processBackup(key string) error {
|
||||
|
|
|
@ -297,9 +297,9 @@ func (m *ServerMetrics) SetBackupTarballSizeBytesGauge(backupSchedule string, si
|
|||
}
|
||||
|
||||
// SetBackupLastSuccessfulTimestamp records the last time a backup ran successfully, Unix timestamp in seconds
|
||||
func (m *ServerMetrics) SetBackupLastSuccessfulTimestamp(backupSchedule string) {
|
||||
func (m *ServerMetrics) SetBackupLastSuccessfulTimestamp(backupSchedule string, time time.Time) {
|
||||
if g, ok := m.metrics[backupLastSuccessfulTimestamp].(*prometheus.GaugeVec); ok {
|
||||
g.WithLabelValues(backupSchedule).Set(float64(time.Now().Unix()))
|
||||
g.WithLabelValues(backupSchedule).Set(float64(time.Unix()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ func (m *ServerMetrics) RegisterBackupSuccess(backupSchedule string) {
|
|||
if c, ok := m.metrics[backupSuccessTotal].(*prometheus.CounterVec); ok {
|
||||
c.WithLabelValues(backupSchedule).Inc()
|
||||
}
|
||||
m.SetBackupLastSuccessfulTimestamp(backupSchedule)
|
||||
m.SetBackupLastSuccessfulTimestamp(backupSchedule, time.Now())
|
||||
}
|
||||
|
||||
// RegisterBackupPartialFailure records a partially failed backup.
|
||||
|
|
Loading…
Reference in New Issue