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

Add validation in Decommission Request for minimum awareness attributes #4767

Closed

Conversation

imRishN
Copy link
Member

@imRishN imRishN commented Oct 13, 2022

Description

This PR adds another layer of validation before executing decommission request. The decommission request hence would be acknowledged only if there are atleast 3 awareness attribute value set to the cluster to fail fast

Issues Resolved

#4768

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: Rishab Nahata <[email protected]>
@imRishN imRishN changed the title Decommission/validation Add validation in Decommission Request for minimum awareness attributes Oct 13, 2022
Signed-off-by: Rishab Nahata <[email protected]>
Signed-off-by: Rishab Nahata <[email protected]>
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@imRishN imRishN marked this pull request as ready for review October 13, 2022 12:29
@imRishN imRishN requested review from a team and reta as code owners October 13, 2022 12:29
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

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

Gradle Check (Jenkins) Run Completed with:

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2022

Codecov Report

Merging #4767 (24d0638) into main (8fda187) will decrease coverage by 0.02%.
The diff coverage is 60.00%.

@@             Coverage Diff              @@
##               main    #4767      +/-   ##
============================================
- Coverage     70.82%   70.80%   -0.03%     
+ Complexity    57885    57855      -30     
============================================
  Files          4689     4689              
  Lines        276913   276914       +1     
  Branches      40301    40303       +2     
============================================
- Hits         196122   196063      -59     
+ Misses        64548    64490      -58     
- Partials      16243    16361     +118     
Impacted Files Coverage Δ
...r/decommission/DecommissioningFailedException.java 38.46% <50.00%> (+5.12%) ⬆️
...arch/cluster/decommission/DecommissionService.java 32.90% <61.53%> (+0.86%) ⬆️
...ava/org/opensearch/action/NoSuchNodeException.java 0.00% <0.00%> (-50.00%) ⬇️
...cluster/coordination/PendingClusterStateStats.java 20.00% <0.00%> (-48.00%) ⬇️
...regations/metrics/AbstractHyperLogLogPlusPlus.java 51.72% <0.00%> (-44.83%) ⬇️
...n/admin/indices/readonly/AddIndexBlockRequest.java 35.71% <0.00%> (-35.72%) ⬇️
...ion/admin/cluster/node/info/PluginsAndModules.java 53.12% <0.00%> (-34.38%) ⬇️
...search/search/aggregations/pipeline/EwmaModel.java 24.44% <0.00%> (-33.34%) ⬇️
...nsearch/index/shard/IndexShardClosedException.java 66.66% <0.00%> (-33.34%) ⬇️
...min/cluster/snapshots/get/GetSnapshotsRequest.java 52.63% <0.00%> (-31.58%) ⬇️
... and 459 more

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

Comment on lines 398 to 416
if (awarenessAttributes == null) {
msg = "awareness attribute not set to the cluster.";
msg = "awareness attribute not set to the cluster";
} else if (forcedAwarenessAttributes == null) {
msg = "forced awareness attribute not set to the cluster.";
msg = "forced awareness attribute not set to the cluster";
} else if (awarenessAttributes.contains(decommissionAttribute.attributeName()) == false) {
msg = "invalid awareness attribute requested for decommissioning";
msg = "invalid awareness attribute requested for decommissioning, eligible attributes are ["
+ awarenessAttributes.toString()
+ "]";
} else if (forcedAwarenessAttributes.containsKey(decommissionAttribute.attributeName()) == false) {
msg = "forced awareness attribute [" + forcedAwarenessAttributes.toString() + "] doesn't have the decommissioning attribute";
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName())
.contains(decommissionAttribute.attributeValue()) == false) {
msg = "invalid awareness attribute value requested for decommissioning. Set forced awareness values before to decommission";
msg = "invalid awareness attribute value requested for decommissioning. Eligible forced awareness attributes ["
+ forcedAwarenessAttributes.toString()
+ "]";
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) {
msg = "total awareness attribute value set to cluster is ["
+ forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size()
+ "] which is less than minimum attribute value count required [3]";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than so many if..else if , this can be simplified with asserting just the expected values. If not we throw generic validation exception .

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 agree that it can be simplified to a single if statement or two, but the disadvantage of it would be not exposing a verbose exception to the end user which would just leave the user wondering what went wrong with the request.

Copy link
Member Author

Choose a reason for hiding this comment

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

Simplified the validations a bit now

Signed-off-by: Rishab Nahata <[email protected]>
Comment on lines 398 to 422

if (awarenessAttributes == null
|| forcedAwarenessAttributes == null
|| awarenessAttributes.isEmpty()
|| forcedAwarenessAttributes.isEmpty()) {
msg = "awareness attribute ["
+ awarenessAttributes
+ "] and forced awareness attribute ["
+ forcedAwarenessAttributes
+ "] must be set to execute decommissioning";
} else if (awarenessAttributes.contains(decommissionAttribute.attributeName()) == false
|| forcedAwarenessAttributes.containsKey(decommissionAttribute.attributeName()) == false) {
msg = "invalid awareness attribute requested for decommissioning, eligible attributes are ["
+ forcedAwarenessAttributes
+ "]";
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName())
.contains(decommissionAttribute.attributeValue()) == false) {
msg = "invalid awareness attribute value requested for decommissioning. Eligible forced awareness attributes ["
+ forcedAwarenessAttributes
+ "]";
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) {
msg = "total awareness attribute value set to cluster is ["
+ forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size()
+ "] which is less than minimum attribute value count required [3]";
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why the spotless check is messing up the indentation in the same level of if/else block

Copy link
Collaborator

@gbbafna gbbafna left a comment

Choose a reason for hiding this comment

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

code LTGM . Thanks Rishabh.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

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

Gradle Check (Jenkins) Run Completed with:

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

Gradle Check (Jenkins) Run Completed with:

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

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Comment on lines 413 to 422
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName())
.contains(decommissionAttribute.attributeValue()) == false) {
msg = "invalid awareness attribute value requested for decommissioning. Eligible forced awareness attributes ["
+ forcedAwarenessAttributes
+ "]";
} else if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) {
msg = "total awareness attribute value set to cluster is ["
+ forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size()
+ "] which is less than minimum attribute value count required [3]";
}
Copy link
Collaborator

@Bukhtawar Bukhtawar Oct 16, 2022

Choose a reason for hiding this comment

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

Lets say force zone awareness is set to AZ1, AZ2, AZ3 while actual discovered zone values are only

  1. AZ1, AZ4, AZ5
  2. AZ1 only

will decommission on AZ1 be supported?

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 think force zone awareness values is the only source of truth today to know the actual zone values. If the user has set the zones to AZ1, AZ2, AZ3 would it be wrong to assume that these are the actual zone values? And force zone values is a dynamically updatable setting which is set by the user and defaults to empty.

Another point here is, if the zone values that are set by the user is AZ1,AZ2,AZ3 and user requests to decommission to AZ4, these checks would anyways fail and hence decommission would fail

@imRishN imRishN force-pushed the decommission/validation branch from 59eedb6 to e3a9d04 Compare October 21, 2022 04:59
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

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

Gradle Check (Jenkins) Run Completed with:

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

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Rishab Nahata <[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:

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

Gradle Check (Jenkins) Run Completed with:

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

Gradle Check (Jenkins) Run Completed with:

Signed-off-by: Rishab Nahata <[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:

+ "]"
);
}
if (forcedAwarenessAttributes.get(decommissionAttribute.attributeName()).size() < 3) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be a configuration?

Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't get you. Configuration as in?

@imRishN imRishN closed this Jan 11, 2023
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