Metrics reload (#1586)

* wip

* plugin/metrics: fix reload behavior

Fixes #1472
This commit is contained in:
Miek Gieben
2018-03-02 17:16:25 -08:00
committed by GitHub
parent 5546dbf3c6
commit 6f3a7af548
3 changed files with 10 additions and 11 deletions

View File

@@ -33,6 +33,8 @@ Extra labels used are:
If monitoring is enabled, queries that do not enter the plugin chain are exported under the fake If monitoring is enabled, queries that do not enter the plugin chain are exported under the fake
name "dropped" (without a closing dot - this is never a valid domain name). name "dropped" (without a closing dot - this is never a valid domain name).
This plugin can only be used once per Server Block.
## Syntax ## Syntax
~~~ ~~~

View File

@@ -103,13 +103,8 @@ func (m *Metrics) OnStartup() error {
return nil return nil
} }
// OnShutdown tears down the metrics on shutdown and restart. // OnShutdown tears down the metrics listener on shutdown and restart.
func (m *Metrics) OnShutdown() error { func (m *Metrics) OnShutdown() error { return m.ln.Close() }
if m.ln != nil {
return m.ln.Close()
}
return nil
}
func keys(m map[string]bool) []string { func keys(m map[string]bool) []string {
sx := []string{} sx := []string{}

View File

@@ -31,12 +31,12 @@ func setup(c *caddy.Controller) error {
for a, v := range uniqAddr.a { for a, v := range uniqAddr.a {
if v == todo { if v == todo {
// During restarts we will keep this handler running, BUG.
c.OncePerServerBlock(m.OnStartup) c.OncePerServerBlock(m.OnStartup)
} }
uniqAddr.a[a] = done uniqAddr.a[a] = done
} }
c.OnFinalShutdown(m.OnShutdown)
c.OnShutdown(m.OnShutdown)
return nil return nil
} }
@@ -48,10 +48,12 @@ func prometheusParse(c *caddy.Controller) (*Metrics, error) {
uniqAddr.SetAddress(met.Addr) uniqAddr.SetAddress(met.Addr)
}() }()
i := 0
for c.Next() { for c.Next() {
if len(met.ZoneNames()) > 0 { if i > 0 {
return met, c.Err("can only have one metrics module per server") return nil, plugin.ErrOnce
} }
i++
for _, z := range c.ServerBlockKeys { for _, z := range c.ServerBlockKeys {
met.AddZone(plugin.Host(z).Normalize()) met.AddZone(plugin.Host(z).Normalize())