-
Notifications
You must be signed in to change notification settings - Fork 189
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
DEBUG
-log server request rejections
#2597
DEBUG
-log server request rejections
#2597
Conversation
This commit logs server request rejections at the `DEBUG` level in an operation's `FromRequest` implementation. This commit is analogous to the one in PR #2524 for response rejections. However, request rejections are _not_ errors, so they shouldn't be logged at the `ERROR` level. Indeed, they happen every time the server rejects a malformed request. Prior to this commit, the `RuntimeError::NotAcceptable` variant was the only `RuntimeError` variant that was manually constructed. This commit makes it so that it now results from a conversion from a new `RequestRejection::NotAcceptable` variant. We now leverage `futures_util::future::FutureExt::map` to map a future that uses `RequestRejection` as its error into a future that uses `RuntimeError`, and centrally log the rejection there. `futures_util` is already a transitive dependency of server SDKs (via e.g. `hyper` and `tower`), so adding it is a direct dependency is not worse. This helps with #2521.
@@ -18,6 +18,8 @@ pub enum ResponseRejection { | |||
pub enum RequestRejection { | |||
#[error("error converting non-streaming body to bytes: {0}")] | |||
BufferHttpBodyBytes(crate::Error), | |||
#[error("request contains invalid value for `Accept` header")] | |||
NotAcceptable, |
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.
I'll make these take in the invalid HeaderValue
in a follow-up PR.
A new generated diff is ready to view.
A new doc preview is ready to view. |
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.
Looks good.
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.
LGTM
@@ -252,13 +251,19 @@ class ServerHttpBoundProtocolTraitImplGenerator( | |||
.await | |||
.map_err(Into::into) | |||
}; | |||
use #{FuturesUtil}::future::FutureExt; |
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.
Can we use TryFutureExt::map_err
?
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.
Nice, TIL about TryFutureExt::map_err
. I switched over to that in e61ed46, and amended the PR description.
Oops, I realized I copy-pasted the |
I was wondering about that :) |
A new generated diff is ready to view.
A new doc preview is ready to view. |
This commit logs server request rejections at the `DEBUG` level in an operation's `FromRequest` implementation. This commit is analogous to the one in PR #2524 for response rejections. However, request rejections are _not_ errors, so they shouldn't be logged at the `ERROR` level. Indeed, they happen every time the server rejects a malformed request. Prior to this commit, the `RuntimeError::NotAcceptable` variant was the only `RuntimeError` variant that was manually constructed. This commit makes it so that it now results from a conversion from a new `RequestRejection::NotAcceptable` variant. We now leverage `futures_util::future::TryFutureExt::map` to map a future that uses `RequestRejection` as its error into a future that uses `RuntimeError`, and centrally log the rejection there. `futures_util` is already a transitive dependency of server SDKs (via e.g. `hyper` and `tower`), so adding it is a direct dependency is not worse. This helps with #2521. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
This commit logs server request rejections at the `DEBUG` level in an operation's `FromRequest` implementation. This commit is analogous to the one in PR #2524 for response rejections. However, request rejections are _not_ errors, so they shouldn't be logged at the `ERROR` level. Indeed, they happen every time the server rejects a malformed request. Prior to this commit, the `RuntimeError::NotAcceptable` variant was the only `RuntimeError` variant that was manually constructed. This commit makes it so that it now results from a conversion from a new `RequestRejection::NotAcceptable` variant. We now leverage `futures_util::future::TryFutureExt::map` to map a future that uses `RequestRejection` as its error into a future that uses `RuntimeError`, and centrally log the rejection there. `futures_util` is already a transitive dependency of server SDKs (via e.g. `hyper` and `tower`), so adding it is a direct dependency is not worse. This helps with #2521. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
This commit logs server request rejections at the
DEBUG
level in anoperation's
FromRequest
implementation.This commit is analogous to the one in PR #2524 for response rejections.
However, request rejections are not errors, so they shouldn't be
logged at the
ERROR
level. Indeed, they happen every time the serverrejects a malformed request.
Prior to this commit, the
RuntimeError::NotAcceptable
variant was theonly
RuntimeError
variant that was manually constructed. This commitmakes it so that it now results from a conversion from a new
RequestRejection::NotAcceptable
variant.We now leverage
futures_util::future::TryFutureExt::map
to map a futurethat uses
RequestRejection
as its error into a future that usesRuntimeError
, and centrally log the rejection there.futures_util
isalready a transitive dependency of server SDKs (via e.g.
hyper
andtower
), so adding it is a direct dependency is not worse.This helps with #2521.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.