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

Reject bulk requests with invalid actions #5302

Merged
merged 3 commits into from
Nov 21, 2022
Merged

Reject bulk requests with invalid actions #5302

merged 3 commits into from
Nov 21, 2022

Conversation

adnapibar
Copy link
Contributor

Description

Reject bulk requests that contain invalid actions.

Issues Resolved

Resolves #5299

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: Rabi Panda adnapibar@gmail.com

The existing bulk api silently ignores bulk item requests that have an invalid action. This change rejects those requests.

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
@adnapibar adnapibar requested review from a team and reta as code owners November 17, 2022 23:57
@@ -64,7 +64,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- Fix 'org.apache.hc.core5.http.ParseException: Invalid protocol version' under JDK 16+ ([#4827](https://github.com/opensearch-project/OpenSearch/pull/4827))
- Fixed compression support for h2c protocol ([#4944](https://github.com/opensearch-project/OpenSearch/pull/4944))
- Add jvm option to allow security manager ([#5194](https://github.com/opensearch-project/OpenSearch/pull/5194))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This shouldn't be included in the CHANGELOG as per the guidelines, removing it.

@adnapibar
Copy link
Contributor Author

Should this be considered as a breaking change?

@andrross
Copy link
Member

Should this be considered as a breaking change?

Yes, I think so.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: UNSTABLE ❕
  • TEST FAILURES:
      1 org.opensearch.cluster.allocation.AwarenessAllocationIT.testThreeZoneOneReplicaWithForceZoneValueAndLoadAwareness

@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2022

Codecov Report

Merging #5302 (dfefe0e) into main (7aa615f) will decrease coverage by 0.04%.
The diff coverage is 66.66%.

@@             Coverage Diff              @@
##               main    #5302      +/-   ##
============================================
- Coverage     71.02%   70.98%   -0.05%     
+ Complexity    58161    58126      -35     
============================================
  Files          4704     4704              
  Lines        277401   277404       +3     
  Branches      40166    40167       +1     
============================================
- Hits         197025   196907     -118     
- Misses        64204    64428     +224     
+ Partials      16172    16069     -103     
Impacted Files Coverage Δ
.../org/opensearch/action/bulk/BulkRequestParser.java 77.71% <66.66%> (-1.29%) ⬇️
...adonly/AddIndexBlockClusterStateUpdateRequest.java 0.00% <0.00%> (-75.00%) ⬇️
...readonly/TransportVerifyShardIndexBlockAction.java 9.75% <0.00%> (-58.54%) ⬇️
...ava/org/opensearch/action/NoSuchNodeException.java 0.00% <0.00%> (-50.00%) ⬇️
...adcast/BroadcastShardOperationFailedException.java 33.33% <0.00%> (-44.45%) ⬇️
...indices/readonly/TransportAddIndexBlockAction.java 20.68% <0.00%> (-37.94%) ⬇️
...cluster/coordination/PublishClusterStateStats.java 33.33% <0.00%> (-37.51%) ⬇️
.../opensearch/client/indices/CloseIndexResponse.java 42.50% <0.00%> (-35.00%) ⬇️
...nsearch/index/shard/IndexShardClosedException.java 66.66% <0.00%> (-33.34%) ⬇️
.../indices/readonly/AddIndexBlockRequestBuilder.java 0.00% <0.00%> (-33.34%) ⬇️
... and 481 more

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

@adnapibar
Copy link
Contributor Author

Should this be considered as a breaking change?

Yes, I think so.

Should we then deprecate in 2.5 and reject in 3.0?

@andrross
Copy link
Member

Should we then deprecate in 2.5 and reject in 3.0?

Yeah, I think a deprecation warning in 2.5 is a good idea.

@@ -176,7 +203,7 @@ public void parse(
+ "]"
);
}
String action = parser.currentName();
Action action = Action.of(parser.currentName(), line);
Copy link
Member

@andrross andrross Nov 18, 2022

Choose a reason for hiding this comment

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

You could maybe refactor this as Action.consume(parser, line) so that you can handle the failure case above in the same place. I think it currently prints "...expected FIELD_NAME but found [x]" and that could be improved as well to say the "expected one of ..." thing.

Feel free to think of a better name than "consume"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

consume sounds more like it doesn't return anything, let me think of a better name.
the error message does say ... expected one of [create, delete, index, update] but found ...

Copy link
Member

Choose a reason for hiding this comment

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

Yes, your new error message says that. I was suggesting to make it say that for the case on line 195 where a non-field name is encountered as well.

Action.parse might work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On line 195, the check is the type of token encountered, so I think we can keep the error message as is.

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
@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: Rabi Panda <adnapibar@gmail.com>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@reta reta added backport 2.x Backport to 2.x branch backport 2.4 Backport to 2.4 branch labels Nov 20, 2022
@adnapibar
Copy link
Contributor Author

adnapibar commented Nov 20, 2022

@reta I don't think we can backport this as it is to 2.x to 2.4 as it seems to be breaking ? Also on a related note, the backport labels only work after a PR is merged.

@reta
Copy link
Collaborator

reta commented Nov 20, 2022

@reta I don't think we can backport this as it is to 2.x to 2.4 as it seems to be breaking ?

It seems like we just fixing the bug, behavior wise it is breaking, yes, but I think the parser should have been rejecting invalid request since the beginning. @dblock wdyt?

Also on a related note, the backport labels only work after a PR is merged.

Sure.

@andrross
Copy link
Member

It seems like we just fixing the bug, behavior wise it is breaking, yes, but I think the parser should have been rejecting invalid request since the beginning

I agree that these requests should have been rejected, but the fact remains it is a breaking change in behavior. If we're being super strict about compatibility then this change should not be backported. The counter argument is that any user that would be impacted by this likely has a bug, and perhaps a serious one (e.g. using "remove" instead of "delete" and their intent is just being ignored). I would lean towards the second argument, and if this change actually breaks a user's workflow then that is a good thing because it uncovers a bug. But I could be swayed that our commitment to semantic versioning should be the priority. I'm also curious what @dblock thinks.

@reta reta removed backport 2.x Backport to 2.x branch backport 2.4 Backport to 2.4 branch labels Nov 21, 2022
@reta
Copy link
Collaborator

reta commented Nov 21, 2022

It seems like we just fixing the bug, behavior wise it is breaking, yes, but I think the parser should have been rejecting invalid request since the beginning

I agree that these requests should have been rejected, but the fact remains it is a breaking change in behavior. If we're being super strict about compatibility then this change should not be backported. The counter argument is that any user that would be impacted by this likely has a bug, and perhaps a serious one (e.g. using "remove" instead of "delete" and their intent is just being ignored). I would lean towards the second argument, and if this change actually breaks a user's workflow then that is a good thing because it uncovers a bug. But I could be swayed that our commitment to semantic versioning should be the priority. I'm also curious what @dblock thinks.

Thanks @andrross Removing the backport lables for now :-) we could always backport later

@dblock
Copy link
Member

dblock commented Nov 21, 2022

🤔 So the request would simply be ignored in the past, and now you get a proper error. It is indeed a behavior change, the old API was a noop, so let's not backport it.

@dblock dblock merged commit 66c5448 into opensearch-project:main Nov 21, 2022
@CEHENKLE
Copy link
Member

To my mind, if you provide a set of responses that are acceptable (create, delete, index, update), the expectation is that these are the only responses that acceptable. This is how we documented our API, which is the first rule of Semver. Our behavior of swallowing the error is a bug because it does not enforce our stated contract. Making the software correctly fulfil it's contract might be changing behavior, but it's not unexpected or new behavior. and does not change how the API contract was supposed to function.

Additionally, failing malformed requests silently on batch jobs is one of the worst things we could do -- since it makes it impossible to have confidence in your results.

So at the risk of sounding like these guys:
fixed_the_glitch

I think we should backport to enforce the existing contract and make it easier for people to find bugs in their requests.

(BTW, I also recognize this is a thing that reasonable people can disagree about, so I really appreciate the discussion!)

@dblock
Copy link
Member

dblock commented Nov 22, 2022

I keep going back and forth, so I think @adnapibar should make the call!

@adnapibar
Copy link
Contributor Author

I keep going back and forth, so I think @adnapibar should make the call!

After reading @CEHENKLE 's comment I think we should backport this to previous versions. We are not breaking the contract of the API, it is only breaking for someone who is incorrectly using the API.

Just to be safe, I think we can mention this in the CHANGELOG's that this change might break if the API was incorrectly used previously. (Should we have a breaking section in the CHANGELOG?)

@andrross
Copy link
Member

I wouldn't advertise this as "breaking" since we're not breaking the contract of the API :) I'd just add it under the "fixed" section.

@dblock dblock added the backport 2.x Backport to 2.x branch label Nov 23, 2022
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-5302-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 66c544821f019a30de47f38686e0ce5a3a08cfca
# Push it to GitHub
git push --set-upstream origin backport/backport-5302-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-5302-to-2.x.

@dblock
Copy link
Member

dblock commented Nov 23, 2022

@adnapibar You'll have to backport manually 😢

@adnapibar
Copy link
Contributor Author

@adnapibar You'll have to backport manually 😢

Yes, I think CHANGELOG causes it, I'll create the backport prs.

reta pushed a commit that referenced this pull request Nov 26, 2022
The existing bulk api silently ignores bulk item requests that have an invalid action. This change rejects those requests.

Signed-off-by: Rabi Panda <adnapibar@gmail.com>

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Bulk api silently ignores unknown operations
7 participants