mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 02:33:21 -05:00 
			
		
		
		
	This fixes a data race on the listener(s) that get started in the metrics plugins. It also restore pkg/uniq to its former glory and removes and state being carried in there; this means for metrics that registry.go was to replicate that behavior *with* locking (as pkg/uniq doesn't do, or need that). Also renamed uniqAddr to just u, to make it slightly shorter. Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			29 lines
		
	
	
		
			533 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			533 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package metrics
 | 
						|
 | 
						|
import (
 | 
						|
	"sync"
 | 
						|
 | 
						|
	"github.com/prometheus/client_golang/prometheus"
 | 
						|
)
 | 
						|
 | 
						|
type reg struct {
 | 
						|
	sync.RWMutex
 | 
						|
	r map[string]*prometheus.Registry
 | 
						|
}
 | 
						|
 | 
						|
func newReg() *reg { return ®{r: make(map[string]*prometheus.Registry)} }
 | 
						|
 | 
						|
// update sets the registry if not already there and returns the input. Or it returns
 | 
						|
// a previous set value.
 | 
						|
func (r *reg) getOrSet(addr string, pr *prometheus.Registry) *prometheus.Registry {
 | 
						|
	r.Lock()
 | 
						|
	defer r.Unlock()
 | 
						|
 | 
						|
	if v, ok := r.r[addr]; ok {
 | 
						|
		return v
 | 
						|
	}
 | 
						|
 | 
						|
	r.r[addr] = pr
 | 
						|
	return pr
 | 
						|
}
 |