-
Notifications
You must be signed in to change notification settings - Fork 107
Extracts the transformation logic on Future instances into a dedicated class #688
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
base: main
Are you sure you want to change the base?
Extracts the transformation logic on Future instances into a dedicated class #688
Conversation
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
public ProxyResponseTransformer(QueryHistoryManager queryHistoryManager, | ||
RoutingManager routingManager) |
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.
The format is wrong. It should be:
public ProxyResponseTransformer(
QueryHistoryManager queryHistoryManager,
RoutingManager routingManager)
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.
fixed
this.routingManager = requireNonNull(routingManager, "routingManager is null"); | ||
this.queryHistoryManager = requireNonNull(queryHistoryManager, "queryHistoryManager is null"); |
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.
Replace the order of these lines for consistency with constructor parameter and fields.
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.
fixed
private static final Logger log = Logger.get(ProxyRequestHandler.class); | ||
private final QueryHistoryManager queryHistoryManager; |
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.
Add an empty line to separate static final
and final
.
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.
fixed
public ProxyResponse transform(Request request, ProxyResponse response, @Nullable String username, RoutingDestination routingDestination) | ||
{ | ||
return recordBackendForQueryId(request, response, username, routingDestination); | ||
} | ||
|
||
private ProxyResponse recordBackendForQueryId(Request request, ProxyResponse response, |
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.
Merge these methods into one.
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.
The main reason for introducing ProxyResponseTransformer is to make it easier to extend the functionality of the FluentFuture.
With that in mind, I believe it's better to separate the transform method from the internal helper methods it relies on.
@ebyhr What do you think?
gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyResponseTransformer.java
Outdated
Show resolved
Hide resolved
|
||
if (response.statusCode() == OK.getStatusCode()) { | ||
try { | ||
HashMap<String, String> results = OBJECT_MAPPER.readValue(response.body(), HashMap.class); |
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.
Fix warning or add //noinspection unchecked
.
gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyResponseTransformer.java
Outdated
Show resolved
Hide resolved
catch (IOException e) { | ||
log.error("Failed to get QueryId from response [%s] , Status code [%s]", response.body(), response.statusCode()); |
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 include e
in the logger message.
log.error(e, "Failed to get QueryId from response [%s] , Status code [%s]", response.body(), response.statusCode());
The commit title should start with an uppercase character: https://trino.io/development/process#pull-request-and-commit-guidelines- |
9a921d9
to
21a7937
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
21a7937
to
2fadbb7
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
|
||
public class ProxyResponseTransformer | ||
{ | ||
private static final Logger log = Logger.get(ProxyRequestHandler.class); |
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.
change to ProxyResponseTransformer
private static final Logger log = Logger.get(ProxyResponseTransformer.class);
|
||
@Inject | ||
public ProxyRequestHandler( | ||
@ForProxy HttpClient httpClient, | ||
RoutingManager routingManager, | ||
QueryHistoryManager queryHistoryManager, | ||
ProxyResponseTransformer proxyResponseTransformer, |
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 don't see how is ProxyResponseTransformer
being provided
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.
Pull Request Overview
This PR extracts the transformation logic on Future instances into the new ProxyResponseTransformer class to improve readability and testability. Key changes include the extraction of query transformation logic from ProxyRequestHandler, removal of the inner ProxyResponse record in favor of a dedicated file, and overall cleanup of redundant logic.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyResponseTransformer.java | New class for handling transformation and query detail recording |
gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyResponseHandler.java | Removed inner ProxyResponse record and tidied up unused imports |
gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyResponse.java | New record to represent proxy responses |
gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyRequestHandler.java | Refactored to utilize the new ProxyResponseTransformer and removed redundant logic |
|
||
public class ProxyResponseTransformer | ||
{ | ||
private static final Logger log = Logger.get(ProxyRequestHandler.class); |
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.
Logger in ProxyResponseTransformer should reference ProxyResponseTransformer.class instead of ProxyRequestHandler.class to ensure accurate logging context.
private static final Logger log = Logger.get(ProxyRequestHandler.class); | |
private static final Logger log = Logger.get(ProxyResponseTransformer.class); |
Copilot uses AI. Check for mistakes.
QueryHistoryManager.QueryDetail queryDetail = new QueryHistoryManager.QueryDetail(); | ||
queryDetail.setBackendUrl(getRemoteTarget(request.getUri())); | ||
queryDetail.setCaptureTime(System.currentTimeMillis()); | ||
if (Strings.isNullOrEmpty(username)) { |
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.
The condition appears inverted; username should be set only if it is not null or empty (i.e., use if (!Strings.isNullOrEmpty(username))).
if (Strings.isNullOrEmpty(username)) { | |
if (!Strings.isNullOrEmpty(username)) { |
Copilot uses AI. Check for mistakes.
This change moves the transformation logic applied to Future instances into a separate class, making it easier to extend and maintain. It also helps clarify the responsibilities of each component involved.
2fadbb7
to
79c9b5d
Compare
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
@@ -83,6 +85,7 @@ public class HaGatewayProviderModule | |||
protected void configure() | |||
{ | |||
jaxrsBinder(binder()).bindInstance(resourceSecurityDynamicFeature); | |||
bind(ProxyResponseTransformer.class).in(Scopes.SINGLETON); |
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 optionalBinder()
so that others can override it?
bind(ProxyResponseTransformer.class).in(Scopes.SINGLETON); | |
newOptionalBinder(binder(), ProxyResponseTransformer.class).setBinding() | |
.to(ProxyResponseTransformer.class) | |
.in(Scopes.SINGLETON); |
or we can make ProxyResponseTransformer
into an interface and have different impl...
@cla-bot check |
The cla-bot has been summoned, and re-checked this pull request! |
Please resolve merge conflict @yaelselig30 |
Description
This PR extracts the transformation logic on Future instances into a dedicated class to improve readability, enable easier extension, and make the logic more testable.
Additional context and related issues
Changes:
Benefits:
Release notes
(x) This is not user-visible or is docs only, and no release notes are required.