coredns plugin -- on server reload, metrics disappeared, therefore they must be registered on each reload instead of once

This commit is contained in:
Eugene Bujak 2018-09-06 02:07:57 +03:00
parent c143e3d57f
commit 876854d403
1 changed files with 16 additions and 18 deletions

View File

@ -187,23 +187,21 @@ func setup(c *caddy.Controller) error {
}) })
c.OnStartup(func() error { c.OnStartup(func() error {
onceMetrics.Do(func() { m := dnsserver.GetConfig(c).Handler("prometheus")
m := dnsserver.GetConfig(c).Handler("prometheus") if m == nil {
if m == nil { return nil
return }
} if x, ok := m.(*metrics.Metrics); ok {
if x, ok := m.(*metrics.Metrics); ok { x.MustRegister(requests)
x.MustRegister(requests) x.MustRegister(filtered)
x.MustRegister(filtered) x.MustRegister(filteredLists)
x.MustRegister(filteredLists) x.MustRegister(filteredSafebrowsing)
x.MustRegister(filteredSafebrowsing) x.MustRegister(filteredParental)
x.MustRegister(filteredParental) x.MustRegister(whitelisted)
x.MustRegister(whitelisted) x.MustRegister(safesearch)
x.MustRegister(safesearch) x.MustRegister(errorsTotal)
x.MustRegister(errorsTotal) x.MustRegister(d)
x.MustRegister(d) }
}
})
return nil return nil
}) })
c.OnShutdown(d.OnShutdown) c.OnShutdown(d.OnShutdown)
@ -508,4 +506,4 @@ func (d *Plugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
func (d *Plugin) Name() string { return "dnsfilter" } func (d *Plugin) Name() string { return "dnsfilter" }
var onceMetrics, onceQueryLog sync.Once var onceQueryLog sync.Once