@@ -93,7 +93,9 @@ func TestWithGoCollectorDefault(t *testing.T) {
93
93
got = append (got , r .GetName ())
94
94
}
95
95
96
- if diff := cmp .Diff (got , withBaseMetrics (memstatMetrics )); diff != "" {
96
+ expected := append (withBaseMetrics (memstatMetrics ), defaultRuntimeMetrics ... )
97
+ sort .Strings (expected )
98
+ if diff := cmp .Diff (got , expected ); diff != "" {
97
99
t .Errorf ("[IMPORTANT, those are default metrics, can't change in 1.x] missmatch (-want +got):\n %s" , diff )
98
100
}
99
101
}
@@ -113,7 +115,7 @@ func TestWithGoCollectorMemStatsMetricsDisabled(t *testing.T) {
113
115
got = append (got , r .GetName ())
114
116
}
115
117
116
- if diff := cmp .Diff (got , baseMetrics ); diff != "" {
118
+ if diff := cmp .Diff (got , withBaseMetrics ( defaultRuntimeMetrics ) ); diff != "" {
117
119
t .Errorf ("missmatch (-want +got):\n %s" , diff )
118
120
}
119
121
}
@@ -127,7 +129,7 @@ func TestGoCollectorAllowList(t *testing.T) {
127
129
{
128
130
name : "Without any rules" ,
129
131
rules : nil ,
130
- expected : baseMetrics ,
132
+ expected : withBaseMetrics ( defaultRuntimeMetrics ) ,
131
133
},
132
134
{
133
135
name : "allow all" ,
@@ -137,22 +139,22 @@ func TestGoCollectorAllowList(t *testing.T) {
137
139
{
138
140
name : "allow GC" ,
139
141
rules : []GoRuntimeMetricsRule {MetricsGC },
140
- expected : withGCMetrics (),
142
+ expected : withDefaultRuntimeMetrics ( withGCMetrics (), true , false ),
141
143
},
142
144
{
143
145
name : "allow Memory" ,
144
146
rules : []GoRuntimeMetricsRule {MetricsMemory },
145
- expected : withMemoryMetrics (),
147
+ expected : withDefaultRuntimeMetrics ( withMemoryMetrics (), false , false ),
146
148
},
147
149
{
148
150
name : "allow Scheduler" ,
149
151
rules : []GoRuntimeMetricsRule {MetricsScheduler },
150
- expected : withSchedulerMetrics (),
152
+ expected : withDefaultRuntimeMetrics ( withSchedulerMetrics (), false , true ),
151
153
},
152
154
{
153
155
name : "allow debug" ,
154
156
rules : []GoRuntimeMetricsRule {MetricsDebug },
155
- expected : withDebugMetrics (),
157
+ expected : withDefaultRuntimeMetrics ( withDebugMetrics (), false , false ),
156
158
},
157
159
} {
158
160
t .Run (test .name , func (t * testing.T ) {
@@ -193,7 +195,7 @@ func TestGoCollectorDenyList(t *testing.T) {
193
195
{
194
196
name : "Without any matchers" ,
195
197
matchers : nil ,
196
- expected : baseMetrics ,
198
+ expected : withBaseMetrics ( defaultRuntimeMetrics ) ,
197
199
},
198
200
{
199
201
name : "deny all" ,
@@ -206,6 +208,14 @@ func TestGoCollectorDenyList(t *testing.T) {
206
208
regexp .MustCompile ("^/gc/.*" ),
207
209
regexp .MustCompile ("^/sched/latencies:.*" ),
208
210
},
211
+ expected : withDefaultRuntimeMetrics (baseMetrics , true , false ),
212
+ },
213
+ {
214
+ name : "deny gc and scheduler" ,
215
+ matchers : []* regexp.Regexp {
216
+ regexp .MustCompile ("^/gc/.*" ),
217
+ regexp .MustCompile ("^/sched/.*" ),
218
+ },
209
219
expected : baseMetrics ,
210
220
},
211
221
} {
@@ -235,7 +245,7 @@ func TestGoCollectorDenyList(t *testing.T) {
235
245
func ExampleGoCollector () {
236
246
reg := prometheus .NewRegistry ()
237
247
238
- // Register the GoCollector with the default options. Only the base metrics and memstats are enabled.
248
+ // Register the GoCollector with the default options. Only the base metrics, default runtime metrics and memstats are enabled.
239
249
reg .MustRegister (NewGoCollector ())
240
250
241
251
http .Handle ("/metrics" , promhttp .HandlerFor (reg , promhttp.HandlerOpts {}))
0 commit comments