diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 00fb4348..ac8dcc0f 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -210,10 +210,18 @@ func (s *MetricsRegistryImpl) IncScheduleCounters(schedule *types.BackupSchedule } if schedule.RecoveryPoint != nil { s.scheduleLastBackupTimestamp.WithLabelValues(schedule.ContainerID, schedule.DatabaseName, schedule.ID).Set(float64(schedule.RecoveryPoint.Unix())) + } else if schedule.Audit != nil && schedule.Audit.CreatedAt != nil { + // Report schedule creation time as last backup time if no backups were made + s.scheduleLastBackupTimestamp.WithLabelValues(schedule.ContainerID, schedule.DatabaseName, schedule.ID).Set(float64(schedule.Audit.CreatedAt.AsTime().Unix())) } info := schedule.GetBackupInfo(s.clock) if info != nil { s.scheduleRPOMarginRatio.WithLabelValues(schedule.ContainerID, schedule.DatabaseName, schedule.ID).Set(info.LastBackupRpoMarginRatio) + } else if schedule.Audit != nil && schedule.Audit.CreatedAt != nil && schedule.ScheduleSettings.RecoveryPointObjective != nil { + // Report fake LastBackupRpoMarginRatio based on schedule creation time if no backups were made + fakeRpoMargin := s.clock.Since(schedule.Audit.CreatedAt.AsTime()) + fakeLastBackupRpoMarginRatio := fakeRpoMargin.Seconds() / float64(schedule.ScheduleSettings.RecoveryPointObjective.Seconds) + s.scheduleRPOMarginRatio.WithLabelValues(schedule.ContainerID, schedule.DatabaseName, schedule.ID).Set(fakeLastBackupRpoMarginRatio) } } diff --git a/internal/watchers/schedule_watcher/schedule_watcher.go b/internal/watchers/schedule_watcher/schedule_watcher.go index a6f49c39..5013eaf9 100644 --- a/internal/watchers/schedule_watcher/schedule_watcher.go +++ b/internal/watchers/schedule_watcher/schedule_watcher.go @@ -46,7 +46,6 @@ func ScheduleWatcherAction( ctx, cancel := context.WithTimeout(baseCtx, period) defer cancel() - //TODO: add pagination or switch to Query.Client() schedules, err := db.SelectBackupSchedulesWithRPOInfo( ctx, queries.NewReadTableQuery( queries.WithRawQuery(queries.ListSchedulesQuery),