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

Implement middleware types to allow intercepting client & request handling #232

Merged
merged 5 commits into from
Jan 17, 2024

Conversation

Xtansia
Copy link
Collaborator

@Xtansia Xtansia commented Dec 13, 2023

Description

Implement middleware types to allow intercepting client & request handling

Split from #132

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Thomas Farr <[email protected]>
Copy link

codecov bot commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (360e88c) 74.07% compared to head (2d8d0e8) 73.94%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #232      +/-   ##
==========================================
- Coverage   74.07%   73.94%   -0.13%     
==========================================
  Files         403      407       +4     
  Lines       64138    64286     +148     
==========================================
+ Hits        47508    47536      +28     
- Misses      16630    16750     +120     
Flag Coverage Δ
integration 73.94% <ø> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -104,3 +104,9 @@ impl OpenSearch {
.await
}
}

// Ensure that the client is `Send` and `Sync`
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is certainly useful but shouldn't be moved to tests?


dyn_clone::clone_trait_object!(BoxedRequestHandler);

pub struct RequestPipeline<'a> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Certainly debatable, but pipeline is a bit overloaded term here (to me), may be:

Suggested change
pub struct RequestPipeline<'a> {
pub struct RequestHandlerChain<'a> {

@Xtansia Xtansia requested a review from reta December 14, 2023 23:42
@Xtansia
Copy link
Collaborator Author

Xtansia commented Dec 14, 2023

@reta Have made changes regarding your comments

@reta
Copy link
Collaborator

reta commented Dec 15, 2023

@reta Have made changes regarding your comments

Thanks @Xtansia , I have briefly looked at it and overall looks pretty clean, I would love to have a bit more to go over the change but not reasons to hold it off if you need to, thank you

@Xtansia
Copy link
Collaborator Author

Xtansia commented Dec 15, 2023

@reta Have made changes regarding your comments

Thanks @Xtansia , I have briefly looked at it and overall looks pretty clean, I would love to have a bit more to go over the change but not reasons to hold it off if you need to, thank you

No rush on getting it merged, will need to go in a major release anyway due to the prior error type changes. Definitely open to feedback, don't want to do it half-baked. So take as much time as you like to go over it

@@ -80,11 +83,32 @@ enum Kind {
#[cfg(feature = "aws-auth")]
#[error("AwsSigV4 error: {0}")]
AwsSigV4(#[from] crate::http::aws_auth::AwsSigV4Error),

#[error("request initializer error: {0}")]
RequestInitializer(#[source] BoxError<'static>),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could get right of boxing (and this BoxError) type altogether and just use the reference &'static (dyn std::error::Error + Sync + Send):

    #[error("request initializer error: {0}")]
    RequestInitializer(#[source] &'static (dyn std::error::Error + Sync + Send)),

    #[error("request pipeline error: {0}")]
    RequestPipeline(#[source] &'static (dyn std::error::Error + Sync + Send)),

It is not necessarily a better option (in my opinion) but it is a bit simpler from "less abstractions" standpoint, curious what do you think about it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we took a &'static reference it would mean any errors returned would need to be defined as consts or leaked memory. The + 'static bound here just means the contained data must be owned (or contain only &'static references), such that we can hold onto the type for an indeterminate amount of time. https://doc.rust-lang.org/rust-by-example/scope/lifetime/static_lifetime.html

A Box is the best way to take ownership of the arbitrary error type and "erase" it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A Box is the best way to take ownership of the arbitrary error type and "erase" it.

That is a strong argument, thank you. I have no other comments left

@Xtansia Xtansia merged commit b175b34 into opensearch-project:main Jan 17, 2024
31 of 32 checks passed
@Xtansia Xtansia deleted the feat/middleware branch January 17, 2024 22:17
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