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:
Francois Tur 2018-09-19 05:11:24 -04:00 committed by Yong Tang
parent cb932ca231
commit f9bdd382dd
13 changed files with 143 additions and 43 deletions

View file

@ -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