File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -407,6 +407,14 @@ func (r *Registry) MustRegister(cs ...Collector) {
407407
408408// Gather implements Gatherer.
409409func (r * Registry ) Gather () ([]* dto.MetricFamily , error ) {
410+ r .mtx .RLock ()
411+
412+ if len (r .collectorsByID ) == 0 && len (r .uncheckedCollectors ) == 0 {
413+ // Fast path.
414+ r .mtx .RUnlock ()
415+ return nil , nil
416+ }
417+
410418 var (
411419 checkedMetricChan = make (chan Metric , capMetricChan )
412420 uncheckedMetricChan = make (chan Metric , capMetricChan )
@@ -416,7 +424,6 @@ func (r *Registry) Gather() ([]*dto.MetricFamily, error) {
416424 registeredDescIDs map [uint64 ]struct {} // Only used for pedantic checks
417425 )
418426
419- r .mtx .RLock ()
420427 goroutineBudget := len (r .collectorsByID ) + len (r .uncheckedCollectors )
421428 metricFamiliesByName := make (map [string ]* dto.MetricFamily , len (r .dimHashesByName ))
422429 checkedCollectors := make (chan Collector , len (r .collectorsByID ))
You can’t perform that action at this time.
0 commit comments