@@ -254,6 +254,43 @@ func TestAllDiagnosticDataCollectorMetrics(t *testing.T) {
254254 }
255255}
256256
257+ func TestMongosDiagnosticDataCollectorMetrics (t * testing.T ) {
258+ ctx , cancel := context .WithTimeout (context .Background (), 3 * time .Second )
259+ defer cancel ()
260+
261+ client := tu .DefaultTestClientMongoS (ctx , t )
262+
263+ logLevel := promslog .NewLevel ()
264+ err := logLevel .Set ("debug" )
265+ require .NoError (t , err )
266+ logger := promslog .New (& promslog.Config {
267+ Level : logLevel ,
268+ })
269+ ti := newTopologyInfo (ctx , client , logger )
270+
271+ dbBuildInfo , err := retrieveMongoDBBuildInfo (ctx , client , logger .With ("component" , "test" ))
272+ require .NoError (t , err )
273+
274+ c := newDiagnosticDataCollector (ctx , client , logger , true , ti , dbBuildInfo )
275+
276+ reg := prometheus .NewRegistry ()
277+ err = reg .Register (c )
278+ require .NoError (t , err )
279+ metrics := helpers .CollectMetrics (c )
280+ actualMetrics := helpers .ReadMetrics (metrics )
281+ filters := []string {
282+ "mongodb_ss_connections" ,
283+ }
284+ actualMetrics = filterMetrics (actualMetrics , filters )
285+ actualLines := helpers .Format (helpers .WriteMetrics (actualMetrics ))
286+ metricNames := getMetricNames (actualLines )
287+
288+ sort .Strings (filters )
289+ for _ , want := range filters {
290+ assert .True (t , metricNames [want ], fmt .Sprintf ("missing %q metric" , want ))
291+ }
292+ }
293+
257294// errorCountHandler is a custom handler that keeps tracks of the number of errors and warnings that were logged.
258295// it discards all errors of other levels.
259296type errorCountHandler struct {
0 commit comments