@@ -145,10 +145,6 @@ func (e *Exporter) makeRegistry(ctx context.Context, client *mongo.Client, topol
145145 gc := newGeneralCollector (ctx , client , nodeType , e .opts .Logger )
146146 registry .MustRegister (gc )
147147
148- if client == nil {
149- return registry
150- }
151-
152148 // Enable collectors like collstats and indexstats depending on the number of collections
153149 // present in the database.
154150 limitsOk := false
@@ -340,13 +336,18 @@ func (e *Exporter) Handler() http.Handler {
340336 gatherers = append (gatherers , prometheus .DefaultGatherer )
341337 }
342338
339+ var registry * prometheus.Registry
343340 var ti * topologyInfo
344341 if client != nil {
345342 // Topology can change between requests, so we need to get it every time.
346343 ti = newTopologyInfo (ctx , client , e .logger )
344+ registry = e .makeRegistry (ctx , client , ti , requestOpts )
345+ } else {
346+ registry = prometheus .NewRegistry ()
347+ gc := newGeneralCollector (ctx , client , "" , e .opts .Logger )
348+ registry .MustRegister (gc )
347349 }
348350
349- registry := e .makeRegistry (ctx , client , ti , requestOpts )
350351 gatherers = append (gatherers , registry )
351352
352353 // Delegate http serving to Prometheus client library, which will call collector.Collect.
0 commit comments