Conversation
metrics.go
Outdated
| metricsOnce.Do(func() { | ||
| globalMetrics = initializeMetrics(reg) | ||
| }) |
There was a problem hiding this comment.
This will stop working on config reload, and no metrics will be registered or emitted. Unfortunately, the only way to manage it for now is to check for duplicate registration error, and ignore it.
There was a problem hiding this comment.
Thanks for the review! I updated it as per your request.
There was a problem hiding this comment.
Now it will panic if the rate_limiter is used multiple times in Caddy because internally it calls MustRegister, and prometheus will see an existing registration
There was a problem hiding this comment.
Thanks!
- Removed sync.Once to allow re-registration on config reloads.
- Now directly call initializeMetrics(reg) in registerMetrics.
- globalMetrics is only set if nil, keeping metrics functional across reloads.
- Duplicate registration errors are now ignored (returning nil as suggested).
This way, metrics continue working after reloads without panics, and Prometheus should handle any duplicate registrations gracefully.
|
I'm trying to address the issue of duplicate registration in caddyserver/caddy#7051. Do you have any feedback to give on that there? |
Hey sorry for the delay. I dont have any explicit feedback on your recommended solution in the PR you linked. Sorry this is my first foray into using caddy in production and just noticed some things were missing for my specific use case. |
|
Hi there. We're quite interested in those additional metrics, is it possible to finalize this ? |
Im happy to try and get this across the finish line. For now I use this instead @rgarrigue https://github.com/chalabi2/caddy-ratelimit |
This PR adds rate limit metrics requested in #79 to Caddy's internal metrics registry