File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ require (
23
23
github.com/modern-go/reflect2 v1.0.2 // indirect
24
24
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
25
25
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
26
+ go.uber.org/goleak v1.2.0 // indirect
26
27
golang.org/x/net v0.35.0 // indirect
27
28
golang.org/x/oauth2 v0.25.0 // indirect
28
29
golang.org/x/text v0.22.0 // indirect
Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
46
46
github.com/stretchr/testify v1.3.0 /go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI =
47
47
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA =
48
48
github.com/stretchr/testify v1.10.0 /go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY =
49
+ go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk =
50
+ go.uber.org/goleak v1.2.0 /go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo =
49
51
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8 =
50
52
golang.org/x/net v0.35.0 /go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk =
51
53
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70 =
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ import (
39
39
"github.com/prometheus/common/expfmt"
40
40
"google.golang.org/protobuf/proto"
41
41
"google.golang.org/protobuf/types/known/timestamppb"
42
+ "go.uber.org/goleak"
42
43
)
43
44
44
45
// uncheckedCollector wraps a Collector but its Describe method yields no Desc.
@@ -1339,3 +1340,28 @@ func TestCheckMetricConsistency(t *testing.T) {
1339
1340
}
1340
1341
reg .Unregister (invalidCollector )
1341
1342
}
1343
+
1344
+ func TestGatherDoesNotLeakGoroutines (t * testing.T ) {
1345
+ // Use goleak to verify that no unexpected goroutines are leaked during the test.
1346
+ defer goleak .VerifyNone (t )
1347
+
1348
+ // Create a new Prometheus registry without any default collectors.
1349
+ reg := prometheus .NewRegistry ()
1350
+
1351
+ // Register 100 simple Gauge metrics with distinct names and constant labels.
1352
+ for i := 0 ; i < 100 ; i ++ {
1353
+ reg .MustRegister (prometheus .NewGauge (prometheus.GaugeOpts {
1354
+ Name : "test_metric_" + string (rune (i )),
1355
+ Help : "Test metric" ,
1356
+ ConstLabels : prometheus.Labels {"id" : string (rune (i ))},
1357
+ }))
1358
+ }
1359
+
1360
+ // Call Gather repeatedly to simulate stress and check for potential goroutine leaks.
1361
+ for i := 0 ; i < 1000 ; i ++ {
1362
+ _ , err := reg .Gather ()
1363
+ if err != nil {
1364
+ t .Fatalf ("unexpected error from Gather: %v" , err )
1365
+ }
1366
+ }
1367
+ }
You can’t perform that action at this time.
0 commit comments