Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions coderd/prometheusmetrics/prometheusmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,15 @@ func TestAgentStats(t *testing.T) {
t.Cleanup(cancelFunc)

db, pubsub := dbtestutil.NewDB(t)
log := slogtest.Make(t, nil)
log := slogtest.Make(t, nil).Leveled(slog.LevelDebug)

batcher, closeBatcher, err := batchstats.New(ctx,
// We had previously set the batch size to 1 here, but that caused
// intermittent test flakes due to a race between the batcher completing
// its flush and the test asserting that the metrics were collected.
// Instead, we close the batcher after all stats have been posted, which
// forces a flush.
batchstats.WithStore(db),
// We want our stats, and we want them NOW.
batchstats.WithBatchSize(1),
batchstats.WithInterval(time.Hour),
batchstats.WithLogger(log),
)
require.NoError(t, err, "create stats batcher failed")
Expand Down Expand Up @@ -435,6 +437,11 @@ func TestAgentStats(t *testing.T) {
require.NoError(t, err)
}

// Ensure that all stats are flushed to the database
// before we query them. We do not expect any more stats
// to be posted after this.
closeBatcher()

// when
//
// Set initialCreateAfter to some time in the past, so that AgentStats would include all above PostStats,
Expand Down