using promauto package to ensure all created metrics are properly registered (#4025)

Signed-off-by: zounengren <zounengren@cmss.chinamobile.com>
This commit is contained in:
Zou Nengren
2020-07-25 23:06:28 +08:00
committed by GitHub
parent 05751bdb59
commit 4166dcc2fe
31 changed files with 71 additions and 163 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// overloaded queries the health end point and updates a metrics showing how long it took.
@@ -39,7 +40,7 @@ func (h *health) overloaded() {
var (
// HealthDuration is the metric used for exporting how fast we can retrieve the /health endpoint.
HealthDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
HealthDuration = promauto.NewHistogram(prometheus.HistogramOpts{
Namespace: plugin.Namespace,
Subsystem: "health",
Name: "request_duration_seconds",

View File

@@ -6,7 +6,6 @@ import (
"time"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/caddyserver/caddy"
)
@@ -21,11 +20,6 @@ func setup(c *caddy.Controller) error {
h := &health{Addr: addr, stop: make(chan bool), lameduck: lame}
c.OnStartup(func() error {
metrics.MustRegister(c, HealthDuration)
return nil
})
c.OnStartup(h.OnStartup)
c.OnRestart(h.OnFinalShutdown)
c.OnFinalShutdown(h.OnFinalShutdown)