chore: fix TestServer/Prometheus/DBMetricsDisabled test flake (#13453)

See: https://github.com/coder/coder/actions/runs/9352137263/job/25739550487#step:5:368
This commit is contained in:
Colin Adler
2024-06-03 15:38:59 -05:00
committed by GitHub
parent 2806752c7d
commit 40390ecc30
2 changed files with 44 additions and 33 deletions

View File

@ -967,8 +967,9 @@ func TestServer(t *testing.T) {
assert.NoError(t, err)
// nolint:bodyclose
res, err = http.DefaultClient.Do(req)
return err == nil
}, testutil.WaitShort, testutil.IntervalFast)
if err != nil {
return false
}
defer res.Body.Close()
scanner := bufio.NewScanner(res.Body)
@ -985,8 +986,13 @@ func TestServer(t *testing.T) {
}
t.Logf("scanned %s", scanner.Text())
}
require.NoError(t, scanner.Err())
require.True(t, hasActiveUsers)
if scanner.Err() != nil {
t.Logf("scanner err: %s", scanner.Err().Error())
return false
}
return hasActiveUsers
}, testutil.WaitShort, testutil.IntervalFast, "didn't find coderd_api_active_users_duration_hour in time")
})
t.Run("DBMetricsEnabled", func(t *testing.T) {
@ -1017,8 +1023,9 @@ func TestServer(t *testing.T) {
assert.NoError(t, err)
// nolint:bodyclose
res, err = http.DefaultClient.Do(req)
return err == nil
}, testutil.WaitShort, testutil.IntervalFast)
if err != nil {
return false
}
defer res.Body.Close()
scanner := bufio.NewScanner(res.Body)
@ -1029,8 +1036,12 @@ func TestServer(t *testing.T) {
}
t.Logf("scanned %s", scanner.Text())
}
require.NoError(t, scanner.Err())
require.True(t, hasDBMetrics)
if scanner.Err() != nil {
t.Logf("scanner err: %s", scanner.Err().Error())
return false
}
return hasDBMetrics
}, testutil.WaitShort, testutil.IntervalFast, "didn't find coderd_db_query_latencies_seconds in time")
})
})
t.Run("GitHubOAuth", func(t *testing.T) {
@ -1347,7 +1358,7 @@ func TestServer(t *testing.T) {
}
return lastStat.Size() > 0
},
testutil.WaitShort,
dur, //nolint:gocritic
testutil.IntervalFast,
"file at %s should exist, last stat: %+v",
fiName, lastStat,

View File

@ -120,9 +120,9 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
if errors.Is(err, sql.ErrNoRows) {
// clear all series if there are no database entries
workspaceLatestBuildTotals.Reset()
}
} else {
logger.Warn(ctx, "failed to load latest workspace builds", slog.Error(err))
}
return
}
jobIDs := make([]uuid.UUID, 0, len(builds))