Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8f11eb

Browse files
committed
Fixes
1 parent 1cbe59b commit f8f11eb

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

coderd/prometheusmetrics/prometheusmetrics.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ func Agents(ctx context.Context, logger slog.Logger, registerer prometheus.Regis
191191
return nil, err
192192
}
193193

194+
ctx, cancelFunc := context.WithCancel(ctx)
194195
// nolint:gocritic // Prometheus must collect metrics for all Coder users.
195-
ctx, cancelFunc := context.WithCancel(dbauthz.AsSystemRestricted(ctx))
196+
ctx = dbauthz.AsSystemRestricted(ctx)
196197
done := make(chan struct{})
197198

198199
ticker := time.NewTicker(duration)

coderd/prometheusmetrics/prometheusmetrics_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,11 @@ func TestAgents(t *testing.T) {
305305
agentInactiveDisconnectTimeout := 1 * time.Hour // don't need to focus on this value in tests
306306
registry := prometheus.NewRegistry()
307307

308+
ctx, cancelFunc := context.WithCancel(context.Background())
309+
defer cancelFunc()
310+
308311
// when
309-
closeFunc, err := prometheusmetrics.Agents(context.Background(), slogtest.Make(t, nil), registry, db, &coordinatorPtr, derpMap, agentInactiveDisconnectTimeout, time.Millisecond)
312+
closeFunc, err := prometheusmetrics.Agents(ctx, slogtest.Make(t, nil), registry, db, &coordinatorPtr, derpMap, agentInactiveDisconnectTimeout, 50*time.Millisecond)
310313
require.NoError(t, err)
311314
t.Cleanup(closeFunc)
312315

0 commit comments

Comments
 (0)