-
Notifications
You must be signed in to change notification settings - Fork 28
feat: add metrics #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
metrics.go
Outdated
metricsOnce.Do(func() { | ||
globalMetrics = initializeMetrics(reg) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! I updated it as per your request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
This PR adds rate limit metrics requested in #79 to Caddy's internal metrics registry