Skip to content
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

Merged
merged 4 commits into from
Apr 19, 2023

Conversation

david-perez
Copy link
Contributor

@david-perez david-perez commented Apr 19, 2023

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::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.
@david-perez david-perez added the server Rust server SDK label Apr 19, 2023
@david-perez david-perez requested a review from a team as a code owner April 19, 2023 09:12
@@ -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,
Copy link
Contributor Author

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.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Copy link
Contributor

@crisidev crisidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@david-perez david-perez added this pull request to the merge queue Apr 19, 2023
Copy link
Contributor

@hlbarber hlbarber left a 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;
Copy link
Contributor

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?

Copy link
Contributor Author

@david-perez david-perez Apr 19, 2023

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.

@david-perez david-perez removed this pull request from the merge queue due to a manual request Apr 19, 2023
@david-perez
Copy link
Contributor Author

Oops, I realized I copy-pasted the tracing::error! from response rejection logging, contrary to what the commit message says 😅. I fixed that in 62fe0f1.

@crisidev
Copy link
Contributor

Oops, I realized I copy-pasted the tracing::error! from response rejection logging, contrary to what the commit message says sweat_smile. I fixed that in 62fe0f1.

I was wondering about that :)

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@david-perez david-perez added this pull request to the merge queue Apr 19, 2023
Merged via the queue into main with commit 2f70ac8 Apr 19, 2023
@david-perez david-perez deleted the davidpz/debug-log-server-request-rejections branch April 19, 2023 11:28
unexge pushed a commit that referenced this pull request Apr 24, 2023
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._
rcoh pushed a commit that referenced this pull request Apr 24, 2023
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._
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Rust server SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants