diff options
author | 2017-12-27 15:48:14 +0000 | |
---|---|---|
committer | 2017-12-27 15:48:14 +0000 | |
commit | 90dd4bbd4570560a4b72ca8525c99dc8fc1db163 (patch) | |
tree | ab7029569d9e281a28c6ab203a556176f6586eea /plugin/autopath/setup.go | |
parent | 5ac42ed5c29609ce710c2d9a8e145919f4124c00 (diff) | |
download | coredns-90dd4bbd4570560a4b72ca8525c99dc8fc1db163.tar.gz coredns-90dd4bbd4570560a4b72ca8525c99dc8fc1db163.tar.zst coredns-90dd4bbd4570560a4b72ca8525c99dc8fc1db163.zip |
metrics: correctly register all metrics (#1335)
After initial startup, see if prometheus is loaded and if so, register
our metrics with it.
Stop doing the init() func and just use the sync.Once so we don't double
registrer our metrics.
Diffstat (limited to 'plugin/autopath/setup.go')
-rw-r--r-- | plugin/autopath/setup.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/plugin/autopath/setup.go b/plugin/autopath/setup.go index f4b908465..ac0f05ec5 100644 --- a/plugin/autopath/setup.go +++ b/plugin/autopath/setup.go @@ -5,6 +5,7 @@ import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" + "github.com/coredns/coredns/plugin/metrics" "github.com/mholt/caddy" "github.com/miekg/dns" @@ -24,7 +25,18 @@ func setup(c *caddy.Controller) error { return plugin.Error("autopath", err) } - c.OnStartup(OnStartupMetrics) + c.OnStartup(func() error { + once.Do(func() { + m := dnsserver.GetConfig(c).Handler("prometheus") + if m == nil { + return + } + if x, ok := m.(*metrics.Metrics); ok { + x.MustRegister(AutoPathCount) + } + }) + return nil + }) // Do this in OnStartup, so all plugin has been initialized. c.OnStartup(func() error { |