aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-03-02 17:16:25 -0800
committerGravatar GitHub <noreply@github.com> 2018-03-02 17:16:25 -0800
commit6f3a7af5486294c1ca5076e9c56827cd388900e7 (patch)
tree8120bfccd9ae84d9afc8c4b68ac7be4e49f6b926
parent5546dbf3c6dc7a5b437f0b41534052395e20f329 (diff)
downloadcoredns-6f3a7af5486294c1ca5076e9c56827cd388900e7.tar.gz
coredns-6f3a7af5486294c1ca5076e9c56827cd388900e7.tar.zst
coredns-6f3a7af5486294c1ca5076e9c56827cd388900e7.zip
Metrics reload (#1586)
* wip * plugin/metrics: fix reload behavior Fixes #1472
-rw-r--r--plugin/metrics/README.md2
-rw-r--r--plugin/metrics/metrics.go9
-rw-r--r--plugin/metrics/setup.go10
3 files changed, 10 insertions, 11 deletions
diff --git a/plugin/metrics/README.md b/plugin/metrics/README.md
index 4a27dfdf6..b0443a4e6 100644
--- a/plugin/metrics/README.md
+++ b/plugin/metrics/README.md
@@ -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
name "dropped" (without a closing dot - this is never a valid domain name).
+This plugin can only be used once per Server Block.
+
## Syntax
~~~
diff --git a/plugin/metrics/metrics.go b/plugin/metrics/metrics.go
index 25d6da488..0c24ffd15 100644
--- a/plugin/metrics/metrics.go
+++ b/plugin/metrics/metrics.go
@@ -103,13 +103,8 @@ func (m *Metrics) OnStartup() error {
return nil
}
-// OnShutdown tears down the metrics on shutdown and restart.
-func (m *Metrics) OnShutdown() error {
- if m.ln != nil {
- return m.ln.Close()
- }
- return nil
-}
+// OnShutdown tears down the metrics listener on shutdown and restart.
+func (m *Metrics) OnShutdown() error { return m.ln.Close() }
func keys(m map[string]bool) []string {
sx := []string{}
diff --git a/plugin/metrics/setup.go b/plugin/metrics/setup.go
index a0f68a53f..7dac5ee24 100644
--- a/plugin/metrics/setup.go
+++ b/plugin/metrics/setup.go
@@ -31,12 +31,12 @@ func setup(c *caddy.Controller) error {
for a, v := range uniqAddr.a {
if v == todo {
- // During restarts we will keep this handler running, BUG.
c.OncePerServerBlock(m.OnStartup)
}
uniqAddr.a[a] = done
}
- c.OnFinalShutdown(m.OnShutdown)
+
+ c.OnShutdown(m.OnShutdown)
return nil
}
@@ -48,10 +48,12 @@ func prometheusParse(c *caddy.Controller) (*Metrics, error) {
uniqAddr.SetAddress(met.Addr)
}()
+ i := 0
for c.Next() {
- if len(met.ZoneNames()) > 0 {
- return met, c.Err("can only have one metrics module per server")
+ if i > 0 {
+ return nil, plugin.ErrOnce
}
+ i++
for _, z := range c.ServerBlockKeys {
met.AddZone(plugin.Host(z).Normalize())