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

refactor: Implement log and authentication as tower::Layer #23

Merged
merged 5 commits into from
Aug 23, 2024

Conversation

AllexVeldman
Copy link
Owner

@AllexVeldman AllexVeldman commented Aug 20, 2024

This PR moves the sub-request logging and authentication to their own
tower::Layer middleware.

HttpTransport is now a Service<reqwest::Request> that we can apply
tower::Layer implementations on.

Currently I Pin<Box<>> the reqwest execute future and the
authentication future. Boxing the authentication future should be fine
as it will only happen once per request. boxing the reqwest execute
future might benefit from not having to be boxed as we can send multiple
subrequests per request, will have to figure
our how to do that at some point in the future (pun intended =).

Additionally some cases during authentication, where the upstream server caused an error, I now return 502 Bad Gateway instead of 500 or the upstream response.

This PR moves the sub-request logging and authentication to their own
`tower::Layer` middleware.

`HttpTransport` is now a `Service<reqwest::Request>` that we can apply
`tower::Layer` implementations on.

Currently I `Pin<Box<>>` the reqwest execute future and the
authentication future. boxing the authentication future should be fine
as it will only happen once per request. boxing the reqwest execute
future might benefit from not having to be boxed as we can send multiple
subrequests per request, will have to figure
our how to do that at some point in the future (pun intended =).
@AllexVeldman AllexVeldman self-assigned this Aug 20, 2024
@codecov-commenter
Copy link

codecov-commenter commented Aug 20, 2024

Codecov Report

Attention: Patch coverage is 95.66724% with 25 lines in your changes missing coverage. Please review.

Files Patch % Lines
src/pyoci.rs 66.66% 13 Missing ⚠️
src/app.rs 38.46% 8 Missing ⚠️
src/service/log.rs 94.28% 2 Missing ⚠️
src/otlp.rs 0.00% 1 Missing ⚠️
src/service/auth.rs 99.74% 1 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

If the provided auth String can't be used as a header value, return Err.
Minimizes the trait bounds in the auth module.
Strict bounds to reqwest::Request are now only defined on the Service and
Future impls, saving a lot of repetition.
The AuthService and AuthFuture are now setup to return anyhow errors.
This allows specific error handling through downcasting in app.rs if
needed. For now all errors we can't fall back to a response for will
return a server error.
@AllexVeldman AllexVeldman marked this pull request as ready for review August 22, 2024 12:58
Ensure we return BAD_GATEWAY during authentication when the error is due to an upstream server
@AllexVeldman AllexVeldman merged commit 6e8403b into main Aug 23, 2024
3 checks passed
@AllexVeldman AllexVeldman deleted the tower-service branch August 23, 2024 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants