Skip to content

[Feature/extensions] Return consumed params and content from extensions#4705

Merged
owaiskazi19 merged 5 commits intoopensearch-project:feature/extensionsfrom
dbwiddis:response
Oct 10, 2022
Merged

[Feature/extensions] Return consumed params and content from extensions#4705
owaiskazi19 merged 5 commits intoopensearch-project:feature/extensionsfrom
dbwiddis:response

Conversation

@dbwiddis
Copy link
Copy Markdown
Member

@dbwiddis dbwiddis commented Oct 7, 2022

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

Note: merging this PR will break SDK main due to changes in transport parameters. Merge the two together.

Description

Moves the ExtensionRestResponse class from the SDK to o.o.extensions.rest.

  • Updates the class to store the consumed parameters and content as fields
  • Updates the RestExecuteOnExtensionResponse to copy over the content from ExtensionRestResponse and use it for transport
    • These classes are somewhat the same but cannot be combined like we did the ExtensionRestRequest because they extend different superclasses (RestResponse and TransportResponse)
      • RestResponse is an interface and we could extend it but we'd lose all the goodness of the BytesRestResponse implementation that we extend, so we'd have to copy all that. Having two very similar classes here is better.
  • Simplified the logic in RestSendToExtensionAction enabled by the above two steps
  • Updated tests for the new methods

Issues Resolved

Fixes SDK #165

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
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

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: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
Signed-off-by: Daniel Widdis <widdis@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Oct 7, 2022

Gradle Check (Jenkins) Run Completed with:

@dbwiddis
Copy link
Copy Markdown
Member Author

dbwiddis commented Oct 7, 2022

Gradle check failure associated with #4661, need to catch up feature/extension branch to main

@peternied peternied removed their request for review October 7, 2022 14:38
*
* @return the list of consumed params.
*/
public List<String> getConsumedParams() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Trying to learn, how do regular HTTP servers respond?
Is returning back consumed params a standard?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure how it is outside of OpenSearch. All I know is that OpenSearch spits out an error if you include parameters which aren't included.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Which is pretty interesting, Is there a code pointer in OpenSearch. I would love to see why we put it in place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well, it's part of the RestRequest class that we have to use to forward the relevant bits to the extension (and track the consuming).

Here's where it throws an exception on unconsumed params:

// validate unconsumed params, but we must exclude params used to format the response
// use a sorted set so the unconsumed parameters appear in a reliable sorted order
final SortedSet<String> unconsumedParams = request.unconsumedParams()
.stream()
.filter(p -> !responseParams().contains(p))
.collect(Collectors.toCollection(TreeSet::new));
// validate the non-response params
if (!unconsumedParams.isEmpty()) {
final Set<String> candidateParams = new HashSet<>();
candidateParams.addAll(request.consumedParams());
candidateParams.addAll(responseParams());
throw new IllegalArgumentException(unrecognized(request, unconsumedParams, candidateParams, "parameter"));
}

Copy link
Copy Markdown
Member Author

@dbwiddis dbwiddis Oct 10, 2022

Choose a reason for hiding this comment

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

Here's the PR from 6 years ago with more info:
9a83ded

Looks like the intent is to provide a "you typed blah, did you mean bleh?" functionality

Copy link
Copy Markdown
Member

@saratvemulapalli saratvemulapalli left a comment

Choose a reason for hiding this comment

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

The changes look good to me.
Just a couple of questions for my learning. Thanks @dbwiddis !

@owaiskazi19
Copy link
Copy Markdown
Member

Started gradle check again

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #4705 (3fdaf6b) into feature/extensions (eee59c5) will increase coverage by 0.16%.
The diff coverage is 77.02%.

@@                   Coverage Diff                    @@
##             feature/extensions    #4705      +/-   ##
========================================================
+ Coverage                 70.52%   70.68%   +0.16%     
- Complexity                57898    57900       +2     
========================================================
  Files                      4708     4708              
  Lines                    278528   277873     -655     
  Branches                  40661    40395     -266     
========================================================
+ Hits                     196420   196421       +1     
+ Misses                    65740    65215     -525     
+ Partials                  16368    16237     -131     
Impacted Files Coverage Δ
...main/java/org/opensearch/gradle/PublishPlugin.java 43.43% <0.00%> (-0.45%) ⬇️
.../java/org/opensearch/gradle/pluginzip/Publish.java 11.62% <0.00%> (-0.57%) ⬇️
...earch/analysis/common/NGramTokenFilterFactory.java 75.00% <0.00%> (+10.71%) ⬆️
...gregations/bucket/geogrid/BucketPriorityQueue.java 75.00% <ø> (ø)
...arch/aggregations/bucket/geogrid/CellIdSource.java 69.23% <ø> (ø)
...ions/bucket/geogrid/GeoGridAggregationBuilder.java 75.67% <ø> (ø)
.../bucket/geogrid/GeoHashGridAggregationBuilder.java 100.00% <ø> (ø)
.../bucket/geogrid/GeoTileGridAggregationBuilder.java 100.00% <ø> (ø)
...ions/bucket/geogrid/InternalGeoHashGridBucket.java 100.00% <ø> (ø)
...ions/bucket/geogrid/InternalGeoTileGridBucket.java 100.00% <ø> (ø)
... and 646 more

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

@owaiskazi19 owaiskazi19 merged commit 528414b into opensearch-project:feature/extensions Oct 10, 2022
@dbwiddis dbwiddis deleted the response branch October 10, 2022 22:00
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.

5 participants