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

Have consistent warning between CLI, ENV and TOML config #3969

Merged
merged 5 commits into from
Jun 16, 2022

Conversation

wcgcyx
Copy link
Contributor

@wcgcyx wcgcyx commented Jun 16, 2022

PR description

Add additional check of option in environment variables and config file for detecting ignored dependent config warning.

Fixed Issue(s)

fixes #2069

wcgcyx added 2 commits June 16, 2022 10:36
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
Signed-off-by: wcgcyx <wcgcyx@gmail.com>
@wcgcyx wcgcyx force-pushed the 2069-consistent-warning branch from 8111e58 to 2b363c3 Compare June 16, 2022 00:36
Copy link
Contributor

@macfarla macfarla left a comment

Choose a reason for hiding this comment

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

LGTM

@siladu siladu self-requested a review June 16, 2022 23:03
@macfarla macfarla merged commit e29c654 into hyperledger:main Jun 16, 2022
@@ -2073,6 +2110,31 @@ public void rpcHttpOptionsRequiresServiceToBeEnabled() {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
public void rpcHttpOptionsRequiresServiceToBeEnabledToml() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we have junit 5 now, creating a parameterized tests for both command line and toml woud be nice and keep this BesuCOmmandTest a little bit smaller

Copy link
Contributor

Choose a reason for hiding this comment

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

Could start a BesuCommandTomlTest file perhaps?

try {
return !option.stringValues().isEmpty()
|| commandLine.getDefaultValueProvider().defaultValue(option) != null;
} catch (Exception e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need the try catch here? Does default value fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

defaultValue throws Exception when fails to load default value from provider, in this case it would be an IOException as it reads value from config file. It shouldn't throw because the default value has been loaded prior to this, if fails to load config file, besu exits before here.

option -> {
try {
return !option.stringValues().isEmpty()
|| commandLine.getDefaultValueProvider().defaultValue(option) != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this also work for environment variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, default value provider in besu checks for environmental variables before config file.

@@ -2073,6 +2110,31 @@ public void rpcHttpOptionsRequiresServiceToBeEnabled() {
assertThat(commandErrorOutput.toString(UTF_8)).isEmpty();
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't see any tests for environment variables, can test be added for that as well

Copy link
Contributor

@siladu siladu left a comment

Choose a reason for hiding this comment

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

Tests look good, just a small refactoring suggestion.

It feels like there should be an easier way to check the defaults, e.g. option.defaultValue() but I couldn't find anything that worked with the tests.

createTempFile(
"toml",
"miner-coinbase=\""
+ requestedCoinbase.toString()
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant toString()

@@ -99,10 +99,16 @@ public static void checkMultiOptionDependencies(
private static String getAffectedOptions(
final CommandLine commandLine, final List<String> dependentOptionsNames) {
return commandLine.getCommandSpec().options().stream()
.filter(option -> Arrays.stream(option.names()).anyMatch(dependentOptionsNames::contains))
Copy link
Contributor

@siladu siladu Jun 16, 2022

Choose a reason for hiding this comment

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

Pulling this into its own filter makes this a lot cleaner 👍

Comment on lines +105 to +110
try {
return !option.stringValues().isEmpty()
|| commandLine.getDefaultValueProvider().defaultValue(option) != null;
} catch (Exception e) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could extract the exception throwing part into its own method to hide this complexity from the filter body.
Also, may want to check for empty string as well as null, e.g. !Strings.isNullOrEmpty(...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll have a look

eum602 pushed a commit to lacchain/besu that referenced this pull request Nov 3, 2023
…#3969)

* Update CommandLineUtils.java

Signed-off-by: wcgcyx <wcgcyx@gmail.com>

Co-authored-by: Sally MacFarlane <sally.macfarlane@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make ignored dependent configuration warnings consistent between CLI options and TOML config
4 participants