fix(coderd/metricscache): avoid logging error for no rows (#12988)

Fixes #12938
This commit is contained in:
Mathias Fredriksson 2024-04-17 20:43:13 +03:00 committed by GitHub
parent 6b4eb03192
commit 92190443ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 7 deletions

View File

@ -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) { 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) ticker := time.NewTicker(interval)
defer ticker.Stop() defer ticker.Stop()
@ -173,15 +174,13 @@ func (c *Cache) run(ctx context.Context, name string, interval time.Duration, re
if ctx.Err() != nil { if ctx.Err() != nil {
return 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 continue
} }
c.log.Debug( logger.Debug(ctx, "metrics refreshed", slog.F("took", time.Since(start)))
ctx,
name+" metrics refreshed",
slog.F("took", time.Since(start)),
slog.F("interval", interval),
)
break break
} }