HTTP handler error log improvement
What type of enhancement is this?
User experience
What does the enhancement do?
Sometimes we may want to find out the reason for a non-200 HTTP response and we may not be able to get the error log from client side.
To collect the error logs in the HTTP handler, we added a log in our IntoResponse implementation for the Error.
https://github.com/GreptimeTeam/greptimedb/blob/69f0249039f46e1caf713636748d29a649ce9b65/src/servers/src/error.rs#L804-L816
https://github.com/GreptimeTeam/greptimedb/blob/69f0249039f46e1caf713636748d29a649ce9b65/src/servers/src/http/result/error_result.rs#L71-L90
It'd be better to have some logs for HTTP errors so we can debug later. We may need to check all IntoResponse implementations.
Implementation challenges
Not all handler implementations convert errors into an Error. Then we won't be able to get the error message.
Case 1, the handler may returns an HTTPResponse directly: https://github.com/GreptimeTeam/greptimedb/blob/69f0249039f46e1caf713636748d29a649ce9b65/src/servers/src/http/event.rs#L700-L708
Case 2, we can't catch the error raised by the axum itself. Unfortunately, the trace layer also can't get the error message and 400 is not considered a failure. https://docs.rs/tower-http/latest/tower_http/trace/index.html#on_response https://github.com/tokio-rs/axum/blob/main/examples/error-handling/src/main.rs
We can get the remote address, which may be useful in logging. https://github.com/tokio-rs/axum/issues/43 https://docs.rs/axum/latest/axum/struct.Router.html#method.into_make_service_with_connect_info