@@ -56,6 +56,20 @@ func (s *ServerInterceptorTestSuite) SetupTest() {
56
56
s .serverMetrics .InitializeMetrics (s .Server )
57
57
}
58
58
59
+ func (s * ServerInterceptorTestSuite ) TestWithSubsystem () {
60
+ counterOpts := []CounterOption {
61
+ WithSubsystem ("subsystem1" ),
62
+ }
63
+ histOpts := []HistogramOption {
64
+ WithHistogramSubsystem ("subsystem1" ),
65
+ }
66
+ serverCounterOpts := WithServerCounterOptions (counterOpts ... )
67
+ serverMetrics := NewServerMetrics (serverCounterOpts , WithServerHandlingTimeHistogram (histOpts ... ))
68
+
69
+ requireSubsystemName (s .T (), "subsystem1" , serverMetrics .serverStartedCounter .WithLabelValues ("unary" , testpb .TestServiceFullName , "dummy" ))
70
+ requireHistSubsystemName (s .T (), "subsystem1" , serverMetrics .serverHandledHistogram .WithLabelValues ("unary" , testpb .TestServiceFullName , "dummy" ))
71
+ }
72
+
59
73
func (s * ServerInterceptorTestSuite ) TestRegisterPresetsStuff () {
60
74
registry := prometheus .NewPedanticRegistry ()
61
75
s .Require ().NoError (registry .Register (s .serverMetrics ))
@@ -233,6 +247,18 @@ func toFloat64HistCount(h prometheus.Observer) uint64 {
233
247
panic (fmt .Errorf ("collected a non-histogram metric: %s" , pb ))
234
248
}
235
249
250
+ func requireSubsystemName (t * testing.T , expect string , c prometheus.Collector ) {
251
+ t .Helper ()
252
+ metricFullName := reflect .ValueOf (* c .(prometheus.Metric ).Desc ()).FieldByName ("fqName" ).String ()
253
+
254
+ if strings .Split (metricFullName , "_" )[0 ] == expect {
255
+ return
256
+ }
257
+
258
+ t .Errorf ("expected %s value to start with %s; " , metricFullName , expect )
259
+ t .Fail ()
260
+ }
261
+
236
262
func requireValue (t * testing.T , expect int , c prometheus.Collector ) {
237
263
t .Helper ()
238
264
v := int (testutil .ToFloat64 (c ))
@@ -245,6 +271,18 @@ func requireValue(t *testing.T, expect int, c prometheus.Collector) {
245
271
t .Fail ()
246
272
}
247
273
274
+ func requireHistSubsystemName (t * testing.T , expect string , o prometheus.Observer ) {
275
+ t .Helper ()
276
+ metricFullName := reflect .ValueOf (* o .(prometheus.Metric ).Desc ()).FieldByName ("fqName" ).String ()
277
+
278
+ if strings .Split (metricFullName , "_" )[0 ] == expect {
279
+ return
280
+ }
281
+
282
+ t .Errorf ("expected %s value to start with %s; " , metricFullName , expect )
283
+ t .Fail ()
284
+ }
285
+
248
286
func requireValueHistCount (t * testing.T , expect int , o prometheus.Observer ) {
249
287
t .Helper ()
250
288
v := int (toFloat64HistCount (o ))
0 commit comments