mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 00:34:24 -04:00
Ensure Re-register of metrics variables after a reload (#2080)
* - ensure plugins that use prometheus.MustRegister, re-register after reload - removing once.Do on the startup function was simplest way to do it. * - fix underscored names (advice of bot) * - tune existing UT for reload, and add a test verifying failing reload does not prevent correct registering for metrics * - ensure different ports for tests that can run in same time ..
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package autopath
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -16,5 +14,3 @@ var (
|
||||
Help: "Counter of requests that did autopath.",
|
||||
}, []string{"server"})
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
@@ -26,7 +26,7 @@ func setup(c *caddy.Controller) error {
|
||||
}
|
||||
|
||||
c.OnStartup(func() error {
|
||||
once.Do(func() { metrics.MustRegister(c, autoPathCount) })
|
||||
metrics.MustRegister(c, autoPathCount)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
3
plugin/cache/handler.go
vendored
3
plugin/cache/handler.go
vendored
@@ -3,7 +3,6 @@ package cache
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
@@ -126,5 +125,3 @@ var (
|
||||
Help: "The number responses that are not cached, because the reply is malformed.",
|
||||
}, []string{"server"})
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
8
plugin/cache/setup.go
vendored
8
plugin/cache/setup.go
vendored
@@ -34,11 +34,9 @@ func setup(c *caddy.Controller) error {
|
||||
})
|
||||
|
||||
c.OnStartup(func() error {
|
||||
once.Do(func() {
|
||||
metrics.MustRegister(c,
|
||||
cacheSize, cacheHits, cacheMisses,
|
||||
cachePrefetches, cacheDrops)
|
||||
})
|
||||
metrics.MustRegister(c,
|
||||
cacheSize, cacheHits, cacheMisses,
|
||||
cachePrefetches, cacheDrops)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package dnssec
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/metrics"
|
||||
@@ -81,5 +80,3 @@ var (
|
||||
|
||||
// Name implements the Handler interface.
|
||||
func (d Dnssec) Name() string { return "dnssec" }
|
||||
|
||||
var once sync.Once
|
||||
|
||||
@@ -35,9 +35,7 @@ func setup(c *caddy.Controller) error {
|
||||
})
|
||||
|
||||
c.OnStartup(func() error {
|
||||
once.Do(func() {
|
||||
metrics.MustRegister(c, cacheSize, cacheHits, cacheMisses)
|
||||
})
|
||||
metrics.MustRegister(c, cacheSize, cacheHits, cacheMisses)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package forward
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -48,5 +46,3 @@ var (
|
||||
Help: "Gauge of open sockets per upstream.",
|
||||
}, []string{"to"})
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
@@ -38,9 +38,7 @@ func setup(c *caddy.Controller) error {
|
||||
})
|
||||
|
||||
c.OnStartup(func() error {
|
||||
once.Do(func() {
|
||||
metrics.MustRegister(c, RequestCount, RcodeCount, RequestDuration, HealthcheckFailureCount, SocketGauge)
|
||||
})
|
||||
metrics.MustRegister(c, RequestCount, RcodeCount, RequestDuration, HealthcheckFailureCount, SocketGauge)
|
||||
return f.OnStartup()
|
||||
})
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ func setup(c *caddy.Controller) error {
|
||||
})
|
||||
|
||||
c.OnStartup(func() error {
|
||||
once.Do(func() { metrics.MustRegister(c, HealthDuration) })
|
||||
metrics.MustRegister(c, HealthDuration)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -36,5 +34,3 @@ func familyToString(f int) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var once sync.Once
|
||||
|
||||
@@ -33,7 +33,7 @@ func setup(c *caddy.Controller) error {
|
||||
})
|
||||
|
||||
c.OnStartup(func() error {
|
||||
once.Do(func() { metrics.MustRegister(c, RequestCount, RequestDuration) })
|
||||
metrics.MustRegister(c, RequestCount, RequestDuration)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package template
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/metrics"
|
||||
|
||||
@@ -34,13 +32,9 @@ var (
|
||||
// OnStartupMetrics sets up the metrics on startup.
|
||||
func setupMetrics(c *caddy.Controller) error {
|
||||
c.OnStartup(func() error {
|
||||
metricsOnce.Do(func() {
|
||||
metrics.MustRegister(c, templateMatchesCount, templateFailureCount, templateRRFailureCount)
|
||||
})
|
||||
metrics.MustRegister(c, templateMatchesCount, templateFailureCount, templateRRFailureCount)
|
||||
return nil
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var metricsOnce sync.Once
|
||||
|
||||
Reference in New Issue
Block a user