Closed tgeoghegan closed 11 months ago
Hmm, could we fix metricsInstrumentedHandler
to check for caddyhttp.Error
instead? That way it's an actual recoverable error that can be handled with handle_errors
routes in Caddy.
Technically this is a breaking change because it means error routes can no longer be used to implement custom behaviour on rate limiting (e.g. render an error page or w/e).
Ah, breaking changes are no good. I'll see if I can put together a Caddy PR that does as you suggest
The change should be fairly simple, let me know if you have questions!
(Thanks as always Francis)
I think this change is obsoleted by https://github.com/caddyserver/caddy/pull/5979, which I've verified solves my problem. I'm going to close this PR for the sake of tidiness and we can re-open this discussion should the linked Caddy PR not go forward for some reason.
Sounds good! :)
Caddy can be set up to export Prometheus metrics from HTTP servers, and middleware automatically gets wrapped in a
metricsInstrumentedHandler
which will emit histograms of requests times, labeled by the HTTP status. However, this only happens if a handler'sServeHTTP
method doesn't return an error (source). The rate limiter'sServeHTTP
was doing just that, and so the metrics showed no trace of the 429 responses.