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 request parameter 'cluster_manager_timeout' as the alternative for 'master_timeout', and deprecate 'master_timeout' - in CAT Nodes API #2435

Merged
merged 19 commits into from
Mar 18, 2022

Conversation

tlfeng
Copy link
Collaborator

@tlfeng tlfeng commented Mar 11, 2022

Description

master_timeout is being used in multiple APIs, such as cat allocation and cat nodes APIs.
The PR take CAT Nodes API as a sample.

  • Add a new request parameter cluster_manager_timeout, as the alternative for the existing master_timeout, in CAT Nodes API
  • Throw an exception when both master_timeout and cluster_manager_timeout are assigned but with different values, such as GET _cat/nodes?v&master_timeout=1s&cluster_manager_timeout=2s. This is addressed by the temporary method validateParamValuesAreEqual() added in RestRequest class.
    (The above behavior is changed by commit e1ee222 / PR Centralize codes related to 'master_timeout' deprecation for eaiser removal - in CAT Nodes API #2670)
    Throw an exception when both master_timeout and cluster_manager_timeout are assigned, no matter the assigned value are same or not, such as GET _cat/nodes?v&master_timeout=1s&cluster_manager_timeout=1s.
  • Add deprecation log when using request parameter master_timeout
  • Deprecate request parameter master_timeout of in rest api spec
  • Add unit tests

Deprecation notice:
With the built-in deprecation logger of OpenSearch (code), the following message will be recorded in the log files:
runTask_deprecation.log

[2022-03-14T20:32:37,588][DEPRECATION][o.o.d.r.a.c.RestNodesAction] [runTask-0] Deprecated parameter [master_timeout] used. To promote inclusive language, please use [cluster_manager_timeout] instead. It will be unsupported in a future major version.

runTask_deprecation.json

{"type": "deprecation", "timestamp": "2022-03-14T20:32:37,588-07:00", "level": "DEPRECATION", "component": "o.o.d.r.a.c.RestNodesAction", "cluster.name": "runTask", "node.name": "runTask-0", "message": "Deprecated parameter [master_timeout] used. To promote inclusive language, please use [cluster_manager_timeout] instead. It will be unsupported in a future major version.", "cluster.uuid": "rvONWP9qT8uj7_oYihbu4A", "node.id": "sxmmw2FbSG6vCXpPv4rpuQ"  }

Testing:
When the values of old and new parameters are not the same:

GET http://localhost:9200/_cat/nodes?v&master_timeout=1s&cluster_manager_timeout=2s

{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "The values of the request parameters: [master_timeout, cluster_manager_timeout] are required to be equal, otherwise please only assign value to one of the request parameters."
            }
        ],
        "type": "parse_exception",
        "reason": "The values of the request parameters: [master_timeout, cluster_manager_timeout] are required to be equal, otherwise please only assign value to one of the request parameters."
    },
    "status": 400
}

Issues Resolved

Part of #1549

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.

@opensearch-ci-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure b842e508de00a4009e250409fa0bcaabffbba79a
Log 3240

Reports 3240

@tlfeng tlfeng force-pushed the add-cluster-manager-timeout branch from b842e50 to e16ce49 Compare March 11, 2022 01:19
@tlfeng tlfeng added enhancement Enhancement or improvement to existing feature or request v2.0.0 Version 2.0.0 documentation pending Tracks issues which have PRs merged but documentation changes pending labels Mar 11, 2022
@tlfeng tlfeng force-pushed the add-cluster-manager-timeout branch from e16ce49 to 009ded2 Compare March 11, 2022 01:24
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure e16ce49116bb24ba1f94364a576dde27367a114b
Log 3242

Reports 3242

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 009ded2aed9f96d8a157cbe74bbf6edabf1407bb
Log 3243

Reports 3243

@tlfeng tlfeng force-pushed the add-cluster-manager-timeout branch from 009ded2 to 24cf061 Compare March 11, 2022 02:17
@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success 24cf061
Log 3246

Reports 3246

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 67d9e1b
Log 3259

Reports 3259

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 3f46f4e
Log 3310

Reports 3310

@tlfeng tlfeng force-pushed the add-cluster-manager-timeout branch from db4ba0f to 8e0e074 Compare March 15, 2022 00:21
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure db4ba0f9afafec513be70e53d6c14a754212f7c5
Log 3371

Reports 3371

@tlfeng tlfeng changed the title Add request parameter 'cluster_manager_timeout' as the alternative for 'master_timeout', and deprecate 'master_timeout' Add request parameter 'cluster_manager_timeout' as the alternative for 'master_timeout', and deprecate 'master_timeout' - In CAT Nodes API Mar 15, 2022
@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success 8e0e074
Log 3372

Reports 3372

@tlfeng tlfeng changed the title Add request parameter 'cluster_manager_timeout' as the alternative for 'master_timeout', and deprecate 'master_timeout' - In CAT Nodes API Add request parameter 'cluster_manager_timeout' as the alternative for 'master_timeout', and deprecate 'master_timeout' - in CAT Nodes API Mar 15, 2022
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure dec2597
Log 3377

Reports 3377

@tlfeng
Copy link
Collaborator Author

tlfeng commented Mar 15, 2022

in log 3377

> Task :qa:mixed-cluster:v1.2.5#mixedClusterTest

REPRODUCE WITH: ./gradlew ':qa:mixed-cluster:v1.2.5#mixedClusterTest' --tests "org.opensearch.backwards.MixedClusterClientYamlTestSuiteIT" -Dtests.method="test {p0=indices.get_field_mapping/20_missing_field/Return empty object if field doesn't exist, but index does}" -Dtests.seed=E592FBD43C377701 -Dtests.security.manager=true -Dtests.jvm.argline="-XX:TieredStopAtLevel=1 -XX:ReservedCodeCacheSize=64m" -Dtests.locale=fr-LU -Dtests.timezone=Australia/Tasmania -Druntime.java=17

org.opensearch.backwards.MixedClusterClientYamlTestSuiteIT > test {p0=indices.get_field_mapping/20_missing_field/Return empty object if field doesn't exist, but index does} FAILED
    java.lang.AssertionError: Failure at [indices.get_field_mapping/20_missing_field:20]: field [test_index.mappings] is null
        at __randomizedtesting.SeedInfo.seed([E592FBD43C377701:6DC6C40E92CB1AF9]:0)
        at org.opensearch.test.rest.yaml.OpenSearchClientYamlSuiteTestCase.executeSection(OpenSearchClientYamlSuiteTestCase.java:442)
        at org.opensearch.test.rest.yaml.OpenSearchClientYamlSuiteTestCase.test(OpenSearchClientYamlSuiteTestCase.java:415)

It's reported in issue #2440

Signed-off-by: Tianli Feng <[email protected]>
@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 2d36c8f
Log 3390

Reports 3390

@dblock dblock requested a review from andrross March 15, 2022 15:48
@andrross andrross removed their request for review March 15, 2022 19:15
@Deprecated
public void validateParamValuesAreEqual(String... keys) {
// Filter the non-empty values of the parameters with the key, and get the distinct values.
Set<String> set = new HashSet<>();
Copy link
Member

Choose a reason for hiding this comment

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

Minor improvement - you don't need a Set to check this. You can just track the last seen value and ensure that every subsequent value matches it. This would also force a break out of the loop as soon as there is a mismatch rather than attempting to parse all values of the input keys.

Copy link
Collaborator Author

@tlfeng tlfeng Mar 16, 2022

Choose a reason for hiding this comment

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

Hi @kartg Thank you so much for your careful review and your valuable opinion!
I will make the changes according to your suggestion!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in the commit 02e68b5. I learnt the nice way to check if all the values are the same, thank you! 👍

Comment on lines 543 to 546
if (request.hasParam(deprecatedTimeoutParam)) {
deprecationLogger.deprecate("cat_nodes_master_timeout_parameter", MASTER_TIMEOUT_DEPRECATED_MESSAGE);
request.validateParamValuesAreEqual(deprecatedTimeoutParam, clusterManagerTimeoutParam);
}
Copy link
Member

Choose a reason for hiding this comment

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

Two nitpicks here:

  1. Setting the masterNodeTimeout should occur within the if-condition
  2. The validation could occur before setting the value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great suggestion! Now the procedure is more reasonable 😄. I modified the code in the commit 399f2d9

+ valueForKey2,
Strings.isNullOrEmpty(valueForKey1) || Strings.isNullOrEmpty(valueForKey2) || valueForKey1.equals(valueForKey2)
);
} catch (OpenSearchParseException e) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we please split this into two tests?

We should deterministically test both cases - when the two are equal and for inequality - for all test runs rather than testing either code path through a random.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for telling me the opinion to design test case! Updated along wit the above comment 02e68b5

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success 399f2d9
Log 3459

Reports 3459

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success b99c8d5
Log 3482

Reports 3482

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success dfd260d
Log 3502

Reports 3502

@tlfeng tlfeng merged commit a87c9d4 into opensearch-project:main Mar 18, 2022
@tlfeng tlfeng deleted the add-cluster-manager-timeout branch March 18, 2022 22:02
tlfeng pushed a commit that referenced this pull request Apr 1, 2022
…emoval - in CAT Nodes API (#2670) (#2695)

The request parameter `master_timeout` for CAT Nodes API is deprecated and alternative parameter `cluster_manager_timeout` is added in commit a87c9d4 / PR #2435.
This PR refactors a previous code commit, and it's suggested by #2658 (comment).

Change:
This PR put the temporary code related to the 'master_timeout' deprecation in centralized places, so that it will be easier to remove when removing the deprecated parameter `master_timeout` in the future.
- Move the method `parseDeprecatedMasterTimeoutParameter()` into abstract base class `BaseRestHandler`, so that every REST API handler can call it.
- Put the unit tests related to the 'master_timeout' deprecation in one class.

Another notable change: Prohibit using two paramters `master_timeout` and `cluster_manager_timeout` together.

Reason:
There are other 60 REST APIs have got request parameter `master_timeout`, and the parameter pending to be deprecated. (See issue #2511 for the full list). 
- Adding new codes (creating deprecation warning, validating the parameter value and unit tests) in every class for the 60 APIs will cause large duplication.
- Removing the duplicate deprecated codes in the future is also a trouble.

Signed-off-by: Tianli Feng <[email protected]>
tlfeng pushed a commit that referenced this pull request Apr 1, 2022
…emoval - in CAT Nodes API (#2670) (#2696)

The request parameter `master_timeout` for CAT Nodes API is deprecated and alternative parameter `cluster_manager_timeout` is added in commit a87c9d4 / PR #2435.
This PR refactors a previous code commit, and it's suggested by #2658 (comment).

Change:
This PR put the temporary code related to the 'master_timeout' deprecation in centralized places, so that it will be easier to remove when removing the deprecated parameter `master_timeout` in the future.
- Move the method `parseDeprecatedMasterTimeoutParameter()` into abstract base class `BaseRestHandler`, so that every REST API handler can call it.
- Put the unit tests related to the 'master_timeout' deprecation in one class.

Another notable change: Prohibit using two paramters `master_timeout` and `cluster_manager_timeout` together.

Reason:
There are other 60 REST APIs have got request parameter `master_timeout`, and the parameter pending to be deprecated. (See issue #2511 for the full list). 
- Adding new codes (creating deprecation warning, validating the parameter value and unit tests) in every class for the 60 APIs will cause large duplication.
- Removing the duplicate deprecated codes in the future is also a trouble.

Signed-off-by: Tianli Feng <[email protected]>
tlfeng pushed a commit that referenced this pull request Apr 1, 2022
…r 'master_timeout', and deprecate 'master_timeout' - in CAT APIs (#2557)

Apply the change of CAT Nodes API in PR #2435 to other applicable CAT APIs.

- Deprecate the request parameter `master_timeout` that used in many CAT APIs.
- Add alternative new request parameter `cluster_manager_timeout`.
- Add unit tests.

Signed-off-by: Tianli Feng <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 1, 2022
…r 'master_timeout', and deprecate 'master_timeout' - in CAT APIs (#2557)

Apply the change of CAT Nodes API in PR #2435 to other applicable CAT APIs.

- Deprecate the request parameter `master_timeout` that used in many CAT APIs.
- Add alternative new request parameter `cluster_manager_timeout`.
- Add unit tests.

Signed-off-by: Tianli Feng <[email protected]>
(cherry picked from commit 78465b4)
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 1, 2022
…r 'master_timeout', and deprecate 'master_timeout' - in CAT APIs (#2557)

Apply the change of CAT Nodes API in PR #2435 to other applicable CAT APIs.

- Deprecate the request parameter `master_timeout` that used in many CAT APIs.
- Add alternative new request parameter `cluster_manager_timeout`.
- Add unit tests.

Signed-off-by: Tianli Feng <[email protected]>
(cherry picked from commit 78465b4)
nknize pushed a commit that referenced this pull request Apr 4, 2022
… alternative for 'master_timeout', and deprecate 'master_timeout' - in CAT APIs (#2716)

Apply the change of CAT Nodes API in PR #2435 to other applicable CAT APIs.

- Deprecate the request parameter `master_timeout` that used in many CAT APIs.
- Add alternative new request parameter `cluster_manager_timeout`.
- Add unit tests.

Signed-off-by: Tianli Feng <[email protected]>
(cherry picked from commit 78465b4)
nknize pushed a commit that referenced this pull request Apr 4, 2022
… alternative for 'master_timeout', and deprecate 'master_timeout' - in CAT APIs (#2717)

Apply the change of CAT Nodes API in PR #2435 to other applicable CAT APIs.

- Deprecate the request parameter `master_timeout` that used in many CAT APIs.
- Add alternative new request parameter `cluster_manager_timeout`.
- Add unit tests.

Signed-off-by: Tianli Feng <[email protected]>
(cherry picked from commit 78465b4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation pending Tracks issues which have PRs merged but documentation changes pending enhancement Enhancement or improvement to existing feature or request v2.0.0 Version 2.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants