From 92190443ff94b762e3efe16783cb97632244d74e Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Wed, 17 Apr 2024 20:43:13 +0300 Subject: [PATCH] fix(coderd/metricscache): avoid logging error for no rows (#12988) Fixes #12938 --- coderd/metricscache/metricscache.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/coderd/metricscache/metricscache.go b/coderd/metricscache/metricscache.go index f1f06fcacd..13b2e1bb68 100644 --- a/coderd/metricscache/metricscache.go +++ b/coderd/metricscache/metricscache.go @@ -162,6 +162,7 @@ func (c *Cache) refreshDeploymentStats(ctx context.Context) error { } func (c *Cache) run(ctx context.Context, name string, interval time.Duration, refresh func(context.Context) error) { + logger := c.log.With(slog.F("name", name), slog.F("interval", interval)) ticker := time.NewTicker(interval) defer ticker.Stop() @@ -173,15 +174,13 @@ func (c *Cache) run(ctx context.Context, name string, interval time.Duration, re if ctx.Err() != nil { return } - c.log.Error(ctx, "refresh", slog.Error(err)) + if xerrors.Is(err, sql.ErrNoRows) { + break + } + logger.Error(ctx, "refresh metrics failed", slog.Error(err)) continue } - c.log.Debug( - ctx, - name+" metrics refreshed", - slog.F("took", time.Since(start)), - slog.F("interval", interval), - ) + logger.Debug(ctx, "metrics refreshed", slog.F("took", time.Since(start))) break }