From dd938b12e6a27e72777d6a82f893f2b065199443 Mon Sep 17 00:00:00 2001 From: Marc Tuduri Date: Wed, 5 Apr 2023 12:52:26 +0200 Subject: [PATCH] Remove initialization of metrics from init functions Signed-off-by: Marc Tuduri --- config/config.go | 10 +++------- prober/handler.go | 7 ++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/config/config.go b/config/config.go index 9933884..1ce6ac9 100644 --- a/config/config.go +++ b/config/config.go @@ -34,17 +34,18 @@ import ( "github.com/go-kit/log/level" "github.com/miekg/dns" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/common/config" ) var ( - configReloadSuccess = prometheus.NewGauge(prometheus.GaugeOpts{ + configReloadSuccess = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: "blackbox_exporter", Name: "config_last_reload_successful", Help: "Blackbox exporter config loaded successfully.", }) - configReloadSeconds = prometheus.NewGauge(prometheus.GaugeOpts{ + configReloadSeconds = promauto.NewGauge(prometheus.GaugeOpts{ Namespace: "blackbox_exporter", Name: "config_last_reload_success_timestamp_seconds", Help: "Timestamp of the last successful configuration reload.", @@ -89,11 +90,6 @@ var ( } ) -func init() { - prometheus.MustRegister(configReloadSuccess) - prometheus.MustRegister(configReloadSeconds) -} - type Config struct { Modules map[string]Module `yaml:"modules"` } diff --git a/prober/handler.go b/prober/handler.go index 2a8a1d9..6658d3f 100644 --- a/prober/handler.go +++ b/prober/handler.go @@ -27,6 +27,7 @@ import ( "github.com/go-kit/log/level" "github.com/prometheus/blackbox_exporter/config" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/common/expfmt" "gopkg.in/yaml.v2" @@ -40,16 +41,12 @@ var ( "dns": ProbeDNS, "grpc": ProbeGRPC, } - moduleUnknownCounter = prometheus.NewCounter(prometheus.CounterOpts{ + moduleUnknownCounter = promauto.NewCounter(prometheus.CounterOpts{ Name: "blackbox_module_unknown_total", Help: "Count of unknown modules requested by probes", }) ) -func init() { - prometheus.MustRegister(moduleUnknownCounter) -} - func Handler(w http.ResponseWriter, r *http.Request, c *config.Config, logger log.Logger, rh *ResultHistory, timeoutOffset float64, params url.Values) { if params == nil { -- 2.25.1