plugin/metrcs: fix datarace on listeners (#2835)
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>
This commit is contained in:
parent
d41e9ff7b7
commit
118b0c9408
6 changed files with 62 additions and 30 deletions
|
@ -16,7 +16,8 @@ import (
|
|||
|
||||
var (
|
||||
log = clog.NewWithPlugin("prometheus")
|
||||
uniqAddr = uniq.New()
|
||||
u = uniq.New()
|
||||
registry = newReg()
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -31,12 +32,13 @@ func setup(c *caddy.Controller) error {
|
|||
if err != nil {
|
||||
return plugin.Error("prometheus", err)
|
||||
}
|
||||
m.Reg = registry.getOrSet(m.Addr, m.Reg)
|
||||
|
||||
c.OnStartup(func() error { m.Reg = uniqAddr.Set(m.Addr, m.OnStartup, m).(*Metrics).Reg; return nil })
|
||||
c.OnRestartFailed(func() error { m.Reg = uniqAddr.Set(m.Addr, m.OnStartup, m).(*Metrics).Reg; return nil })
|
||||
c.OnStartup(func() error { m.Reg = registry.getOrSet(m.Addr, m.Reg); u.Set(m.Addr, m.OnStartup); return nil })
|
||||
c.OnRestartFailed(func() error { m.Reg = registry.getOrSet(m.Addr, m.Reg); u.Set(m.Addr, m.OnStartup); return nil })
|
||||
|
||||
c.OnStartup(func() error { return uniqAddr.ForEach() })
|
||||
c.OnRestartFailed(func() error { return uniqAddr.ForEach() })
|
||||
c.OnStartup(func() error { return u.ForEach() })
|
||||
c.OnRestartFailed(func() error { return u.ForEach() })
|
||||
|
||||
c.OnStartup(func() error {
|
||||
conf := dnsserver.GetConfig(c)
|
||||
|
@ -75,7 +77,7 @@ func setup(c *caddy.Controller) error {
|
|||
}
|
||||
|
||||
func parse(c *caddy.Controller) (*Metrics, error) {
|
||||
var met = New(defaultAddr)
|
||||
met := New(defaultAddr)
|
||||
|
||||
i := 0
|
||||
for c.Next() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue