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

Standardize int, long, double and float Setting constructors. #665

Merged
merged 4 commits into from
May 6, 2021

Conversation

dblock
Copy link
Member

@dblock dblock commented May 6, 2021

Signed-off-by: dblock [email protected]

Description

Enables an alterative to #643.

  • Refactored and corrected inconsistencies between constructors of various types (int, float, double and long). This adds some missing constructors. (There are two ways to create settings: (a) default value, min, max, etc., and (b) fallback value, min, max, etc. Each type now has a single constructor that calls new Setting<> for the fallback version, and a single constructor that calls new Setting<> for the default version. All other constructors call these two.)

  • Corrected a bug where the min value is confused with default value for positiveTimeSetting used together with a fallback. I removed that constructor to catch any instances (found one).

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.

@dblock dblock force-pushed the settings-constructors branch from d1fe9f9 to 6afba62 Compare May 6, 2021 17:27
@dblock
Copy link
Member Author

dblock commented May 6, 2021

start gradle check

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Precommit failure d1fe9f917da84a0f9db3753c6b1c4ee2eb0c2392
Log 373

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Wrapper Validation failure d1fe9f917da84a0f9db3753c6b1c4ee2eb0c2392

:alert: Gradle Wrapper integrity has been altered

@opensearch-ci-bot
Copy link
Collaborator

❌   DCO Check Failed d1fe9f917da84a0f9db3753c6b1c4ee2eb0c2392
Run ./dev-tools/signoff-check.sh remotes/origin/main d1fe9f917da84a0f9db3753c6b1c4ee2eb0c2392 to check locally
Use git commit with -s to add 'Signed-of-by: {EMAIL}' on impacted commits

@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 6afba62

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success 6afba62

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Precommit failure 6afba62
Log 374

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Check failure 6afba62
Log 165

Reports 165

@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 50d320f

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success 50d320f

}

public static Setting<Float> floatSetting(String key, float defaultValue, float minValue, Property... properties) {
return new Setting<>(key, (s) -> Float.toString(defaultValue), (s) -> {
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 new parser checks min and max, and we set max to Float.MAX_VALUE here, this works. I can do something more elaborate with separate parsers, but I don't think it's necessary.

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Precommit failure 50d320f
Log 375

@@ -106,8 +106,7 @@
public static final Setting.AffixSetting<TimeValue> SCRIPT_CACHE_EXPIRE_SETTING =
Setting.affixKeySetting(CONTEXT_PREFIX,
"cache_expire",
key -> Setting.positiveTimeSetting(key, SCRIPT_GENERAL_CACHE_EXPIRE_SETTING, TimeValue.timeValueMillis(0),
Copy link
Member Author

@dblock dblock May 6, 2021

Choose a reason for hiding this comment

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

This is positive, so >= 0 is redundant. Note that this is probably a confused declaration thinking 0 is the default (it's actually min), as this setting has a fallback, and defaults are used from the fallback.

@@ -100,7 +100,6 @@
Setting.positiveTimeSetting(
"cluster.remote.initial_connect_timeout",
SEARCH_REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING, // the default needs to be thirty seconds when fallback is removed
TimeValue.timeValueSeconds(30),
Copy link
Member Author

@dblock dblock May 6, 2021

Choose a reason for hiding this comment

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

This says "the value of this setting needs to be at least 30" rather than "the default value is 30", so this looks like a bug to me.

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success 44a7f57

@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 44a7f57

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Precommit success 44a7f57

@dblock
Copy link
Member Author

dblock commented May 6, 2021

start gradle check

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success 44a7f57
Log 166

Reports 166

@dblock dblock mentioned this pull request May 6, 2021
5 tasks
@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 33102173951b457a69f30b5cd2c9639c8a734ae7

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success 33102173951b457a69f30b5cd2c9639c8a734ae7

@dblock dblock force-pushed the settings-constructors branch from 3310217 to 870127e Compare May 6, 2021 20:23
@opensearch-ci-bot
Copy link
Collaborator

✅   DCO Check Passed 870127e

@opensearch-ci-bot
Copy link
Collaborator

❌   Gradle Precommit failure 33102173951b457a69f30b5cd2c9639c8a734ae7
Log 377

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Wrapper Validation success 870127e

Comment on lines +1171 to +1178
if (value < minValue) {
String err = "Failed to parse value" + (isFiltered ? "" : " [" + s + "]") + " for setting [" + key + "] must be >= " + minValue;
throw new IllegalArgumentException(err);
}
if (value > maxValue) {
String err = "Failed to parse value" + (isFiltered ? "" : " [" + s + "]") + " for setting [" + key + "] must be <= " + maxValue;
throw new IllegalArgumentException(err);
}
Copy link

Choose a reason for hiding this comment

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

I think it would be better to phrase the error message to include both the min and max:

Failed to parse value: <key> must in in the range [<min>, <max>]

It's a better user experience when all the constraints are spelled out. Also, less duplication in this code.

Copy link
Member Author

@dblock dblock May 6, 2021

Choose a reason for hiding this comment

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

This is basically existing code that was moved. The problem with the suggestion is that often max is MAX_INT or MAX_LONG, so in those cases you don't want this. Leaving it as an exercise for another time.

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Precommit success 870127e

Copy link

@camerski camerski left a comment

Choose a reason for hiding this comment

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

Looks good to me. Just one minor suggestion for error messages; take it or leave it.

@dblock
Copy link
Member Author

dblock commented May 6, 2021

start gradle check

@opensearch-ci-bot
Copy link
Collaborator

✅   Gradle Check success 870127e
Log 167

Reports 167

@dblock dblock merged commit 61f4c7d into opensearch-project:main May 6, 2021
ritty27 pushed a commit to ritty27/OpenSearch that referenced this pull request May 12, 2024
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.

3 participants