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

[Feature/extensions] Register REST API and forward REST requests to associated extension #4282

Merged

Conversation

dbwiddis
Copy link
Member

@dbwiddis dbwiddis commented Aug 23, 2022

Companion PR: opensearch-project/opensearch-sdk-java#101

Description

This and the companion PR linked above completes the work begun in #4100 by registering the received API with the RestController. When OpenSearch receives a RestRequest matching one of these registered routes, it forwards it to the appropriate extension for further action.

See the design schematic and description in #64

Issues Resolved

Closes #64, Closes #69, and Closes #70.

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff

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.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Daniel Widdis <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@dbwiddis
Copy link
Member Author

@saratvemulapalli @owaiskazi19 this is ready for your review. I've added tests for everything I think I can; the remainder of things that aren't tested belong in an integration test. Let me know if you think otherwise:

  • The RestActionsRequestHandler registers actions with the RestController. There is no public method available on that class to confirm the registration and it is stored in a private field. It can only really be confirmed by sending a REST request and validating that it is accepted (which I have done manually).
  • The RestSendToExtensionAction (the single RestHandler that acts for all routes for an extension) has a prepareRequest method which implements the logic of the REST handler. It requires a working Client to receive the response, and isn't easily tested in a unit test.

@dbwiddis dbwiddis marked this pull request as ready for review August 25, 2022 01:26
@dbwiddis dbwiddis requested review from a team and reta as code owners August 25, 2022 01:26
Signed-off-by: Daniel Widdis <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@@ -1165,7 +1165,6 @@ public Node start() throws NodeValidationException {
: "clusterService has a different local node than the factory provided";
transportService.acceptIncomingRequests();
extensionsOrchestrator.extensionsInitialize();
extensionsOrchestrator.setNamedWriteableRegistry();
Copy link
Member

Choose a reason for hiding this comment

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

Why are we removing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

The actions it accomplishes are being moved into the initialize call immediately above it to remove the need for a public setter and more strongly enforce the correct sequencing.

@owaiskazi19
Copy link
Member

owaiskazi19 commented Aug 26, 2022

I see we have the logs messages on the issue to explain the workflow. Thanks for adding that. A small request on top of that can we have a small diagram/representation of the code workflow as well to get better understanding of the Register REST APIs?
Something like:

RestActionsRequestHandler() - handler for registering rest API's coming from Extension -> RestSendToExtensionAction() - action forwards request coming from user to extension 

comment

@dbwiddis
Copy link
Member Author

dbwiddis commented Aug 26, 2022

I see we have the logs messages on the issue to explain the workflow. Thanks for adding that. A small request on top of that can we have a small diagram/representation of the code workflow as well to get better understanding of the Register REST APIs?

I updated the DESIGN.md in SDK #101 with a walk-through that identifies the classes involved. I'm not sure what added value another diagram would bring to that? Could you elaborate?

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@owaiskazi19
Copy link
Member

owaiskazi19 commented Aug 26, 2022

I updated the DESIGN.md in SDK #101 with a walk-through that identifies the classes involved. I'm not sure what added value another diagram would bring to that? Could you elaborate?

Personal preference to help understand the design from the diagram on the issue. You can ignore if you want to :)
I see you have updated the DESIGN.md with the classes. That helps too.

@dbwiddis
Copy link
Member Author

dbwiddis commented Aug 26, 2022

Personal preference to help understand the design from the diagram on the issue. You can ignore if you want to :) I see you have updated the DESIGN.md with the classes. That helps too.

If you can wait until SDK #102 I expect to have a full cradle-to-grave diagram that I think will answer this, so not quite ignoring but deferring to the next PR.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

github.com:opensearch-project/OpenSearch into restController

Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@codecov-commenter
Copy link

codecov-commenter commented Aug 27, 2022

Codecov Report

Merging #4282 (dfad6d4) into feature/extensions (60bb959) will decrease coverage by 0.09%.
The diff coverage is 70.67%.

@@                   Coverage Diff                    @@
##             feature/extensions    #4282      +/-   ##
========================================================
- Coverage                 70.64%   70.54%   -0.10%     
- Complexity                57195    57275      +80     
========================================================
  Files                      4625     4633       +8     
  Lines                    275473   275817     +344     
  Branches                  40291    40337      +46     
========================================================
- Hits                     194601   194577      -24     
- Misses                    64567    64940     +373     
+ Partials                  16305    16300       -5     
Impacted Files Coverage Δ
...ava/org/opensearch/client/RestHighLevelClient.java 44.02% <ø> (-0.31%) ⬇️
...egations/bucket/composite/GeoTileValuesSource.java 50.00% <ø> (ø)
...aggregations/bucket/geogrid/BoundedCellValues.java 100.00% <ø> (ø)
...gregations/bucket/geogrid/BucketPriorityQueue.java 75.00% <ø> (ø)
...arch/aggregations/bucket/geogrid/CellIdSource.java 69.23% <ø> (ø)
...search/aggregations/bucket/geogrid/CellValues.java 100.00% <ø> (ø)
...ions/bucket/geogrid/GeoGridAggregationBuilder.java 75.67% <ø> (ø)
...aggregations/bucket/geogrid/GeoGridAggregator.java 87.50% <ø> (ø)
.../bucket/geogrid/GeoHashGridAggregationBuilder.java 100.00% <ø> (ø)
...egations/bucket/geogrid/GeoHashGridAggregator.java 80.00% <ø> (ø)
... and 554 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@dbwiddis
Copy link
Member Author

Personal preference to help understand the design from the diagram on the issue. You can ignore if you want to :) I see you have updated the DESIGN.md with the classes. That helps too.

There is now a very pretty diagram as part of #109. Enjoy. 😉

Comment on lines +131 to +153
transportService.sendRequest(
discoveryExtension,
ExtensionsOrchestrator.REQUEST_REST_EXECUTE_ON_EXTENSION_ACTION,
new RestExecuteOnExtensionRequest(method, uri),
restExecuteOnExtensionResponseHandler
);
try {
inProgressLatch.await(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
return channel -> channel.sendResponse(
new BytesRestResponse(RestStatus.REQUEST_TIMEOUT, "No response from extension to request.")
);
}
} catch (Exception e) {
logger.info("Failed to send REST Actions to extension " + discoveryExtension.getName(), e);
}
String response = responseBuilder.toString();
if (response.isBlank() || response.startsWith("FAILED")) {
return channel -> channel.sendResponse(
new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, response.isBlank() ? "Request Failed" : response)
);
}
return channel -> channel.sendResponse(new BytesRestResponse(RestStatus.OK, response));
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for this @dbwiddis.
You've suggested an improvement to not let the user wait, could you open an issue if you haven't already to discuss a way to optimize it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll think about it. We probably need to implement more RestActions and see how long-running jobs are already handled, so I'm thinking it'll pop up later when it's needed and we can address it then, along with many other incremental changes we'll need.

Copy link
Member Author

Choose a reason for hiding this comment

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

Really I think this is part of a bigger meta-issue regarding initialization, reachability, etc. SDK #94 touches on some related issues and it can probably be discussed there.

@saratvemulapalli
Copy link
Member

Thanks @dbwiddis for the changes.
I am excited to see this rolling.

Copy link
Member

@owaiskazi19 owaiskazi19 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @dbwiddis for all the changes and the design diagram!

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.

4 participants