From 4be5fe7c461d2287a95b6db415a1f97d3ed48502 Mon Sep 17 00:00:00 2001 From: Kyle Lemons Date: Fri, 4 Nov 2022 13:12:52 -0700 Subject: [PATCH] Make reregistration of prom metrics resilient to v0 + v2 --- internal/admin/server.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/admin/server.go b/internal/admin/server.go index 5ee5ebdfa..6d4397ca7 100644 --- a/internal/admin/server.go +++ b/internal/admin/server.go @@ -35,11 +35,11 @@ func init() { Mux.Handle("/metrics", promhttp.Handler()) - // Unregister the default GoCollector. - prometheus.Unregister(collectors.NewGoCollector()) - - // Register GoCollector with baseplate defaults. - prometheus.MustRegister(collectors.NewGoCollector(baseplateGoCollectors)) + // Unregister the default GoCollector, and reregister with baseplate defaults + if prometheus.Unregister(collectors.NewGoCollector()) { + // Only register a new collector if we unregistered one to avoid double-reregistration + prometheus.MustRegister(collectors.NewGoCollector(baseplateGoCollectors)) + } } func Serve() error {