diff --git a/caddy/caddy_test.go b/caddy/caddy_test.go index 33ae50df..d352ce5e 100644 --- a/caddy/caddy_test.go +++ b/caddy/caddy_test.go @@ -52,7 +52,19 @@ localhost:9080 { mercure { anonymous publisher_jwt !ChangeMe! - %s + %[1]s + } + + respond 404 + } +} + +example.com:9080 { + route { + mercure { + anonymous + publisher_jwt !ChangeMe! + %[1]s } respond 404 diff --git a/metrics.go b/metrics.go index e5398bfe..70a695d5 100644 --- a/metrics.go +++ b/metrics.go @@ -1,6 +1,7 @@ package mercure import ( + "errors" "net/http" "github.com/dunglas/mercure/common" @@ -62,9 +63,19 @@ func NewPrometheusMetrics(registry prometheus.Registerer) *PrometheusMetrics { ), } - m.registry.MustRegister(m.subscribers) - m.registry.MustRegister(m.subscribersTotal) - m.registry.MustRegister(m.updatesTotal) + // https://github.com/caddyserver/caddy/pull/6820 + if err := m.registry.Register(m.subscribers); err != nil && + !errors.As(err, &prometheus.AlreadyRegisteredError{}) { + panic(err) + } + if err := m.registry.Register(m.subscribersTotal); err != nil && + !errors.As(err, &prometheus.AlreadyRegisteredError{}) { + panic(err) + } + if err := m.registry.Register(m.updatesTotal); err != nil && + !errors.As(err, &prometheus.AlreadyRegisteredError{}) { + panic(err) + } return m }