Skip to content

Commit

Permalink
feat(metrics): report schedule creation time as last backup time if n…
Browse files Browse the repository at this point in the history
…o backups were made
  • Loading branch information
ulya-sidorina committed Jan 13, 2025
1 parent 6392765 commit 586e3ae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 8 additions & 0 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
1 change: 0 additions & 1 deletion internal/watchers/schedule_watcher/schedule_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 586e3ae

Please sign in to comment.