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

@@ -4,19 +4,20 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// Metrics for the reload plugin
var (
// failedCount is the counter of the number of failed reload attempts.
failedCount = prometheus.NewCounter(prometheus.CounterOpts{
failedCount = promauto.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "reload",
Name: "failed_total",
Help: "Counter of the number of failed reload attempts.",
})
// reloadInfo is record the hash value during reload.
reloadInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
reloadInfo = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: plugin.Namespace,
Subsystem: "reload",
Name: "version_info",

View File

@@ -7,7 +7,6 @@ import (
"time"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/caddyserver/caddy"
@@ -70,10 +69,6 @@ func setup(c *caddy.Controller) error {
r.setUsage(used)
once.Do(func() {
caddy.RegisterEventHook("reload", hook)
c.OnRestart(func() error {
metrics.MustRegister(c, reloadInfo, failedCount)
return nil
})
})
// re-register on finalShutDown as the instance most-likely will be changed
shutOnce.Do(func() {