diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index c8b8a1d28..9eb6568ad 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -21,7 +21,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" + "k8s.io/component-base/metrics/legacyregistry" "k8s.io/klog/v2" ) @@ -38,24 +38,20 @@ var ( }, []string{"op"}) ) -var registry = prometheus.NewRegistry() +func init() { + GetRegistry().MustRegister(OperationCalled) +} -func GetRegistry() *prometheus.Registry { - return registry +func GetRegistry() prometheus.Registerer { + return legacyregistry.Registerer() } func GetHandler() http.Handler { - registry.MustRegister(OperationCalled) - - gatherers := prometheus.Gatherers{ - prometheus.DefaultGatherer, - registry, - } - - return promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{}) + return legacyregistry.Handler() } func Serve(address string) { + // The metrics are also served by k8s.io/cloud-provider on the secure serving port. mux := http.NewServeMux() mux.Handle("/metrics", GetHandler())