File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ require (
12
12
github.com/prometheus/client_model v0.6.1
13
13
github.com/prometheus/common v0.63.0
14
14
github.com/prometheus/procfs v0.16.0
15
+ go.uber.org/goleak v1.2.0
15
16
golang.org/x/sys v0.30.0
16
17
google.golang.org/protobuf v1.36.6
17
18
)
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ 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 =
51
+ golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs =
52
+ golang.org/x/lint v0.0.0-20190930215403-16217165b5de /go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc =
49
53
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8 =
50
54
golang.org/x/net v0.35.0 /go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk =
51
55
golang.org/x/oauth2 v0.25.0 h1:CY4y7XT9v0cRI9oupztF8AgiIu99L/ksR/Xp/6jrZ70 =
@@ -54,6 +58,8 @@ golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
54
58
golang.org/x/sys v0.30.0 /go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA =
55
59
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM =
56
60
golang.org/x/text v0.22.0 /go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY =
61
+ golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg =
62
+ golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d /go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk =
57
63
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY =
58
64
google.golang.org/protobuf v1.36.6 /go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY =
59
65
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 /go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0 =
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ import (
37
37
38
38
dto "github.com/prometheus/client_model/go"
39
39
"github.com/prometheus/common/expfmt"
40
+ "go.uber.org/goleak"
40
41
"google.golang.org/protobuf/proto"
41
42
"google.golang.org/protobuf/types/known/timestamppb"
42
43
)
@@ -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