From 44788947486799ff50ed90180553c3eabe678f2e Mon Sep 17 00:00:00 2001 From: Ishan Tyagi Date: Fri, 10 Feb 2023 17:44:52 +0530 Subject: [PATCH] Address review comments. --- pkg/snapshot/snapshotter/snapshotter.go | 7 ++++++- pkg/snapshot/snapshotter/snapshotter_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/snapshot/snapshotter/snapshotter.go b/pkg/snapshot/snapshotter/snapshotter.go index 2137e4352..8a2846749 100644 --- a/pkg/snapshot/snapshotter/snapshotter.go +++ b/pkg/snapshot/snapshotter/snapshotter.go @@ -22,6 +22,7 @@ import ( "fmt" "io" "path" + "strconv" "strings" "sync" "time" @@ -792,10 +793,14 @@ func (ssr *Snapshotter) GetFullSnapshotMaxTimeWindow(fullSnapScheduleSpec string return defaultFullSnapMaxTimeWindow } - if schedule[dayOfMonth] == "*" && schedule[dayOfWeek] == "*" { + if schedule[dayOfMonth] == "*" && schedule[dayOfWeek] == "*" && !strings.Contains(schedule[hour], "/") { return defaultFullSnapMaxTimeWindow } else if schedule[dayOfWeek] != "*" { return defaultFullSnapMaxTimeWindow * 7 + } else if schedule[dayOfMonth] == "*" && schedule[dayOfWeek] == "*" && strings.Contains(schedule[hour], "/") { + if timeWindow, err := strconv.ParseFloat(schedule[hour][strings.Index(schedule[hour], "/")+1:], 64); err == nil { + return timeWindow + } } return defaultFullSnapMaxTimeWindow diff --git a/pkg/snapshot/snapshotter/snapshotter_test.go b/pkg/snapshot/snapshotter/snapshotter_test.go index ca68e48ce..2c3aa771d 100644 --- a/pkg/snapshot/snapshotter/snapshotter_test.go +++ b/pkg/snapshot/snapshotter/snapshotter_test.go @@ -738,6 +738,22 @@ var _ = Describe("Snapshotter", func() { Expect(timeWindow).Should(Equal(fullSnapshotTimeWindow * 7)) }) }) + + Context("Full snapshot schedule for every 4 hours", func() { + It("should return 4 hours of timeWindow", func() { + // every 4 hour + scheduleHour := 4 + snapshotterConfig := &brtypes.SnapshotterConfig{ + FullSnapshotSchedule: fmt.Sprintf("%d */%d * * *", 0, scheduleHour), + } + + ssr, err = NewSnapshotter(logger, snapshotterConfig, store, etcdConnectionConfig, compressionConfig, healthConfig, snapstoreConfig) + Expect(err).ShouldNot(HaveOccurred()) + + timeWindow := ssr.GetFullSnapshotMaxTimeWindow(snapshotterConfig.FullSnapshotSchedule) + Expect(timeWindow).Should(Equal(float64(scheduleHour))) + }) + }) }) })