-
Notifications
You must be signed in to change notification settings - Fork 925
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
Introduce Preprocessor
#6057
base: main
Are you sure you want to change the base?
Introduce Preprocessor
#6057
Conversation
core/src/main/java/com/linecorp/armeria/client/websocket/WebSocketClientBuilder.java
Outdated
Show resolved
Hide resolved
…cketClientBuilder.java
core/src/main/java/com/linecorp/armeria/client/websocket/WebSocketClientBuilder.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientPreprocessors.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/ClientPreprocessorsBuilder.java
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/HttpPreprocessor.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/client/DefaultWebClient.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/client/DefaultClientRequestContext.java
Show resolved
Hide resolved
BiFunction<ClientRequestContext, Throwable, O> errorResponseFactory) { | ||
final ClientRequestContextExtension ctxExt = ctx.as(ClientRequestContextExtension.class); | ||
if (ctxExt != null) { | ||
ctxExt.runContextCustomizer(); |
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.
👍
core/src/main/java/com/linecorp/armeria/client/RpcPreprocessor.java
Outdated
Show resolved
Hide resolved
grpc/src/main/java/com/linecorp/armeria/internal/client/grpc/ArmeriaClientCall.java
Outdated
Show resolved
Hide resolved
...thrift0.13/src/main/java/com/linecorp/armeria/internal/client/thrift/DefaultTHttpClient.java
Outdated
Show resolved
Hide resolved
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 work! 👍🚀
@minwoox Do you have time to review this? |
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.
Left some minor comments but looks good all in all. 👍
/** | ||
* Sets the {@link EndpointGroup} used for the current {@link Request}. | ||
*/ | ||
void endpointGroup(EndpointGroup endpointGroup); |
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.
setEndpointGroup
?
We usually name the method in ClientRequestContext
as setX
when a getter of the X exists.
@@ -83,7 +74,6 @@ protected UserClient(ClientBuilderParams params, Client<I, O> delegate, MeterReg | |||
BiFunction<ClientRequestContext, Throwable, O> errorResponseFactory) { | |||
super(delegate); | |||
this.params = params; | |||
this.meterRegistry = meterRegistry; |
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.
Could you remove this from the parameters?
Also, could you update HttpClientFactory.setMeterRegistry
if you don't want to use this meter?
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've just reverted to use HttpClientFactory.setMeterRegistry
for backwards compatibility
* The context customizer must be run before the following conditions. | ||
* <li> | ||
* <ul> | ||
* EndpointSelector.select() so that the customizer can inject the attributes which may be |
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.
Please insert {@link ...}
.
@@ -113,12 +120,9 @@ public HttpResponse execute(HttpRequest req, RequestOptions requestOptions) { | |||
newReq = req.withHeaders(req.headers().toBuilder().path(newPath)); | |||
} | |||
|
|||
return execute(protocol, |
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.
Would you add @Deprecated
annotation to the execute
methods?
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.
Way to go! 👍 🎉 👍
* illustrates a sample use-case: | ||
* <pre>{@code | ||
* HttpPreprocessor preprocessor = (delegate, ctx, req) -> { | ||
* ctx.endpointGroup(Endpoint.of("overriding-host")); |
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.
* ctx.endpointGroup(Endpoint.of("overriding-host")); | |
* ctx.setEndpointGroup(Endpoint.of("overriding-host")); |
* illustrates a sample use-case: | ||
* <pre>{@code | ||
* RpcPreprocessor preprocessor = (delegate, ctx, req) -> { | ||
* ctx.endpointGroup(Endpoint.of("overriding-host")); |
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.
* ctx.endpointGroup(Endpoint.of("overriding-host")); | |
* ctx.setEndpointGroup(Endpoint.of("overriding-host")); |
Motivation:
This PR introduces the notion of
Preprocessor
s and allows users to configure these to clients as options.The second part of this PR will introduce a way for users to solely create a client based on
Preprocessor
s. The eventual POC can be found here: https://github.com/jrhee17/armeria/pull/36/filesEventually this extension point will also make it easier/clearer for users to use xDS with existing Armeria APIs.
The full capability/limitations/design of
Preprocessors
are better described in the following PR: #6051Modifications:
Preprocessor
andPreClient
APIsClientPreprocessors
andClientPreprocessorsBuilder
to allow users to easily addPreprocessor
s to clients as optionsDefaultWebClient
,DefaultTHttpClient
, andArmeriaClientCall
to usePreprocessor
sEndpointGroup
, theEndpointGroup
is now specified when creating aClientRequestContext
instead of at initialization time.ClientUtil
methods to pass an additionalreq
field which signifies the original request for type-safety.Result:
Preprocessor
s when creating a client.