aboutsummaryrefslogtreecommitdiff
path: root/plugin/metrics/registry.go
blob: 2d6a92e0db7aa0405c0359a54d9be6e4ead7858d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package metrics

import (
	"sync"

	"github.com/prometheus/client_golang/prometheus"
)

type reg struct {
	sync.RWMutex
	r map[string]*prometheus.Registry
}

func newReg() *reg { return &reg{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
}