HDDS-8082. Check for unnecessary newlines in config defaults - #10840
HDDS-8082. Check for unnecessary newlines in config defaults#10840cychiu8 wants to merge 4 commits into
Conversation
|
@adoroszlai Regarding HDDS-8082 you created, here is the PR. Happy to have your feedback whenever you get a chance. |
chihsuan
left a comment
There was a problem hiding this comment.
Thanks for picking this up! I left one question about properties filtered by xmlPropsToSkipCompare and xmlPrefixToSkipCompare, as they may unintentionally bypass the new check. The other comments are optional readability suggestions.
Overall, the approach looks good to me. Thanks!
| @Test | ||
| public void testXmlValuesHaveNoEmbeddedNewlines() { | ||
| Set<String> xmlValuesWithNewlines = new HashSet<>(); | ||
| for (Map.Entry<String, String> entry : xmlKeyValueMap.entrySet()) { |
There was a problem hiding this comment.
Would it make sense to check newlines before applying xmlPropsToSkipCompare and xmlPrefixToSkipCompare? therwise, properties excluded from field comparison also skip this check, even if they are not listed in xmlPropsAllowedToContainNewline.
There was a problem hiding this comment.
Thank you for reviewing. You mentioned a great point that I should decouple the newline check, which should not depend on the excluded properties.
|
|
||
| assertTrue(xmlValuesWithNewlines.isEmpty(), | ||
| "These properties in " + xmlFilename + " have an embedded line break in " | ||
| + "their <value>, which corrupts the runtime string: " + xmlValuesWithNewlines |
There was a problem hiding this comment.
nit: There is an extra space after runtime string:.
There was a problem hiding this comment.
Nice catch. Thank you!
| */ | ||
| @Test | ||
| public void testXmlValuesHaveNoEmbeddedNewlines() { | ||
| Set<String> xmlValuesWithNewlines = new HashSet<>(); |
There was a problem hiding this comment.
nit: Would a TreeSet be useful here to keep the failure output deterministic? The sibling checks in this class also use it.
There was a problem hiding this comment.
Thank you for the feedback. It makes sense! I have addressed it.
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks @cychiu8 for the patch.
| } | ||
| } | ||
|
|
||
| assertTrue(xmlValuesWithNewlines.isEmpty(), |
There was a problem hiding this comment.
nit: please use assertThat(xmlValuesWithNewlines).isEmpty(), see HDDS-9951
There was a problem hiding this comment.
Thank you for the review and feedback! I've addressed it.
adoroszlai
left a comment
There was a problem hiding this comment.
Thanks again @cychiu8 for the patch. On another look I found one more issue.
| Configuration conf = new Configuration(false); | ||
| conf.setAllowNullValueProperties(true); | ||
| conf.addResource(xmlFilename); |
There was a problem hiding this comment.
We need to use OzoneConfiguration to handle generated configuration files, too. Example violation to reproduce the problem:
--- hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
+++ hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/OzoneClientConfig.java
@@ -41,7 +41,7 @@ public class OzoneClientConfig {
defaultValue = "16MB",
type = ConfigType.SIZE,
description = "Size which determines at what buffer position a partial "
- + "flush will be initiated during write. It should be a multiple of"
+ + "flush will be initiated during write.\n\nIt should be a multiple of"
+ " ozone.client.stream.buffer.size",
tags = ConfigTag.CLIENT)
private long streamBufferFlushSize = 16 * 1024 * 1024;Suggestion:
Configuration conf = new OzoneConfiguration();
conf.setAllowNullValueProperties(true);- Needs new import as well.
- Probably worth tweaking the assertion failure message to omit mention of
ozone-default.xml, since that's not the only file where the property may live. - I also suggest moving the test case to
TestOzoneConfigurationFields, becauseConfigurationFieldsTestsis mostly supposed to be a copy of Hadoop'sTestConfigurationFieldsBase.
There was a problem hiding this comment.
Thanks @adoroszlai again.
I've switched the test to OzoneConfiguration, moved it to TestOzoneConfigurationFields, and dropped the ozone-default.xml reference from the failure message.
It now covers the generated <module>-default.xml files too.
Loading via OzoneConfiguration also brings in Hadoop's core-default.xml, which legitimately ships four multi-line values:
fs.s3a.aws.credentials.providerhadoop.security.sensitive-config-keyshadoop.system.tagshadoop.tags.system
I've added those to xmlPropsAllowedToContainNewline with a comment.
What changes were proposed in this pull request?
HDDS-8046 removed some unnecessary newlines embedded in default config values in ozone-default.xml. Ayush Saxena had a great suggestion for avoiding these in the future:
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-8082
How was this patch tested?
Test locally with the following command:
Testing three scenarios:
Detailed results for case 1 (Modify a value to include a newline: should fail)
Detailed results for case 2(Add a test property with an intentional newline in its value: should pass)
log:
Detailed results for case 3(Validate the current ozone-default.xml: should pass)