From 644d1718f727eccb12a3e7690ca9e53ebc31c67e Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Fri, 13 Dec 2024 16:08:19 -0500 Subject: [PATCH] Tweak metrics cron so that instead of sleeping there is an offset added to the next time --- core/tasks/metrics/cron.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/core/tasks/metrics/cron.go b/core/tasks/metrics/cron.go index 02c84e79a..daace2a9d 100644 --- a/core/tasks/metrics/cron.go +++ b/core/tasks/metrics/cron.go @@ -23,7 +23,9 @@ type metricsCron struct { } func (c *metricsCron) Next(last time.Time) time.Time { - return tasks.CronNext(last, time.Minute) + // We offset 30 seconds from the top of the minute so that metrics related to queue sizes don't see the spikes that + // typically occur every minute by tasks such as expirations, timeouts etc. + return tasks.CronNext(last, time.Minute).Add(time.Second * 30) } func (c *metricsCron) AllInstances() bool { @@ -31,13 +33,6 @@ func (c *metricsCron) AllInstances() bool { } func (c *metricsCron) Run(ctx context.Context, rt *runtime.Runtime) (map[string]any, error) { - // TODO replace with offset passed to tasks.CronNext - // We wait 15 seconds since we fire at the top of the minute, the same as expirations. - // That way any metrics related to the size of our queue are a bit more accurate (all expirations can - // usually be handled in 15 seconds). Something more complicated would take into account the age of - // the items in our queues. - time.Sleep(time.Second * 15) - handlerSize, batchSize, throttledSize := getQueueSizes(rt) // get our DB and redis stats