@@ -56,6 +56,20 @@ func (s *ServerInterceptorTestSuite) SetupTest() {
5656	s .serverMetrics .InitializeMetrics (s .Server )
5757}
5858
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+ 
5973func  (s  * ServerInterceptorTestSuite ) TestRegisterPresetsStuff () {
6074	registry  :=  prometheus .NewPedanticRegistry ()
6175	s .Require ().NoError (registry .Register (s .serverMetrics ))
@@ -233,6 +247,18 @@ func toFloat64HistCount(h prometheus.Observer) uint64 {
233247	panic (fmt .Errorf ("collected a non-histogram metric: %s" , pb ))
234248}
235249
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+ 
236262func  requireValue (t  * testing.T , expect  int , c  prometheus.Collector ) {
237263	t .Helper ()
238264	v  :=  int (testutil .ToFloat64 (c ))
@@ -245,6 +271,18 @@ func requireValue(t *testing.T, expect int, c prometheus.Collector) {
245271	t .Fail ()
246272}
247273
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+ 
248286func  requireValueHistCount (t  * testing.T , expect  int , o  prometheus.Observer ) {
249287	t .Helper ()
250288	v  :=  int (toFloat64HistCount (o ))
0 commit comments