From 4e7d672d1743a493de0ab295e4124d628904ac19 Mon Sep 17 00:00:00 2001 From: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com> Date: Mon, 2 Jan 2023 10:13:48 -0500 Subject: [PATCH] chore(anchor): remove not started alerts --- cd/manager/env/.env.prod | 1 - cd/manager/env/.env.qa | 1 - cd/manager/env/.env.tnet | 1 - cd/manager/jobmanager/jobManager.go | 18 ---------------- cd/manager/notifs/anchorInterval.go | 33 ----------------------------- 5 files changed, 54 deletions(-) delete mode 100644 cd/manager/notifs/anchorInterval.go diff --git a/cd/manager/env/.env.prod b/cd/manager/env/.env.prod index cf2c843..0526efe 100644 --- a/cd/manager/env/.env.prod +++ b/cd/manager/env/.env.prod @@ -1,3 +1,2 @@ SMOKE_TEST_INTERVAL=6h -CAS_MAX_ANCHOR_INTERVAL=6h ENV=prod diff --git a/cd/manager/env/.env.qa b/cd/manager/env/.env.qa index cd12cdf..4e6f1ec 100644 --- a/cd/manager/env/.env.qa +++ b/cd/manager/env/.env.qa @@ -1,4 +1,3 @@ SMOKE_TEST_INTERVAL=6h E2E_TEST_INTERVAL=8h -CAS_MAX_ANCHOR_INTERVAL=6h ENV=qa diff --git a/cd/manager/env/.env.tnet b/cd/manager/env/.env.tnet index d9a4c6b..81ad3fe 100644 --- a/cd/manager/env/.env.tnet +++ b/cd/manager/env/.env.tnet @@ -1,3 +1,2 @@ SMOKE_TEST_INTERVAL=6h -CAS_MAX_ANCHOR_INTERVAL=6h ENV=tnet diff --git a/cd/manager/jobmanager/jobManager.go b/cd/manager/jobmanager/jobManager.go index 5069eca..78e3575 100644 --- a/cd/manager/jobmanager/jobManager.go +++ b/cd/manager/jobmanager/jobManager.go @@ -13,7 +13,6 @@ import ( "github.com/3box/pipeline-tools/cd/manager" "github.com/3box/pipeline-tools/cd/manager/jobs" - "github.com/3box/pipeline-tools/cd/manager/notifs" ) var _ manager.Manager = &JobManager{} @@ -140,9 +139,6 @@ func (m *JobManager) processJobs() { if err := m.scheduleTests(); err != nil { log.Printf("processJobs: error scheduling tests: %v", err) } - if err := m.checkAnchorInterval(); err != nil { - log.Printf("processJobs: error checking anchor job interval: %v", err) - } // Don't start any new jobs if the job manager is paused. Existing jobs will continue to be advanced. if !m.paused { // Always check if we have anchor jobs, even if none were dequeued. This is because we might have a minimum @@ -231,20 +227,6 @@ func (m *JobManager) scheduleTests() error { return nil } -func (m *JobManager) checkAnchorInterval() error { - // Check time since the last anchor job was completed, if there isn't an anchor job already running. - activeAnchors := m.cache.JobsByMatcher(func(js manager.JobState) bool { - return manager.IsActiveJob(js) && (js.Type == manager.JobType_Anchor) - }) - if len(activeAnchors) == 0 { - return m.checkJobInterval(manager.JobType_Anchor, manager.JobStage_Completed, "CAS_MAX_ANCHOR_INTERVAL", func(ts time.Time) error { - notifs.NewAnchorIntervalNotif(m.notifs).SendAlert(ts) - return nil - }) - } - return nil -} - func (m *JobManager) checkJobInterval(jobType manager.JobType, jobStage manager.JobStage, intervalEnv string, processFn func(time.Time) error) error { if interval, found := os.LookupEnv(intervalEnv); found { if parsedInterval, err := time.ParseDuration(interval); err != nil { diff --git a/cd/manager/notifs/anchorInterval.go b/cd/manager/notifs/anchorInterval.go deleted file mode 100644 index 6ef75c2..0000000 --- a/cd/manager/notifs/anchorInterval.go +++ /dev/null @@ -1,33 +0,0 @@ -package notifs - -import ( - "fmt" - "time" - - "github.com/3box/pipeline-tools/cd/manager" -) - -const NotifPacing = 12 * time.Hour - -// lastNotifTime is the time at which the last notification was sent indicating that an anchor job was not started in a -// timely manner. -var lastNotifTime = time.UnixMilli(0) - -type anchorIntervalNotif struct { - n manager.Notifs -} - -type AnchorIntervalNotif = *anchorIntervalNotif - -func NewAnchorIntervalNotif(n manager.Notifs) AnchorIntervalNotif { - return &anchorIntervalNotif{n} -} - -func (a AnchorIntervalNotif) SendAlert(ts time.Time) { - now := time.Now() - // Don't send alerts too frequently - if now.Add(-NotifPacing).After(lastNotifTime) { - a.n.SendAlert("CAS anchor task not started", fmt.Sprintf("Since %s", ts.Format(time.RFC1123))) - lastNotifTime = now - } -}