Skip to content

HDDS-8082. Check for unnecessary newlines in config defaults#10840

Open
cychiu8 wants to merge 2 commits into
apache:masterfrom
cychiu8:HDDS-8082
Open

HDDS-8082. Check for unnecessary newlines in config defaults#10840
cychiu8 wants to merge 2 commits into
apache:masterfrom
cychiu8:HDDS-8082

Conversation

@cychiu8

@cychiu8 cychiu8 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

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:

I thought of adding a test, which checks for all the configs - set of configs added into the exception list and warns like don't add such breaks unnecessarily, if it is important and legitimate then add it into the exception list, that way even the reviewer would be aware that this practice isn't encouraged.

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:

mvn -pl :ozone-integration-test test \
-Dtest='TestOzoneConfigurationFields#testXmlValuesHaveNoEmbeddedNewlines' \
-DskipShade -DskipRecon

Testing three scenarios:

  1. Modify a value to include a newline: should fail
  2. Add a test property with an intentional newline in its value: should pass
  3. Validate the current ozone-default.xml: should pass

Detailed results for case 1 (Modify a value to include a newline: should fail)

[INFO] Running org.apache.hadoop.ozone.TestOzoneConfigurationFields
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.236 s <<< FAILURE! -- in org.apache.hadoop.ozone.TestOzoneConfigurationFields
[ERROR] org.apache.hadoop.ozone.TestOzoneConfigurationFields.testXmlValuesHaveNoEmbeddedNewlines -- Time elapsed: 0.163 s <<< FAILURE!
org.opentest4j.AssertionFailedError: These properties in ozone-default.xml have an embedded line break in their <value>, which corrupts the runtime string:  [ozone.client.key.latest.version.location] Put the value on a single line. If the newline is genuinely required, add the property to xmlPropsAllowedToContainNewline (in initializeMemberVariables) with a reason + Jira. See HDDS-8082. ==> expected: <true> but was: <false>
        at org.apache.hadoop.conf.ConfigurationFieldsTests.testXmlValuesHaveNoEmbeddedNewlines(ConfigurationFieldsTests.java:700)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   TestOzoneConfigurationFields>ConfigurationFieldsTests.testXmlValuesHaveNoEmbeddedNewlines:700 These properties in ozone-default.xml have an embedded line break in their <value>, which corrupts the runtime string:  [ozone.client.key.latest.version.location] Put the value on a single line. If the newline is genuinely required, add the property to xmlPropsAllowedToContainNewline (in initializeMemberVariables) with a reason + Jira. See HDDS-8082. ==> expected: <true> but was: <false>                                                                                                                                                                                                             
[INFO] 
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  11.897 s
[INFO] Finished at: 2026-07-22T17:11:09+09:00

Detailed results for case 2(Add a test property with an intentional newline in its value: should pass)
log:

2026-07-22 19:42:58,104 [main] INFO  conf.ConfigurationFieldsTests (ConfigurationFieldsTests.java:testXmlValuesHaveNoEmbeddedNewlines(696)) - XML Property: ozone.client.key.latest.version.location AllowedToContainNewline
[INFO] Running org.apache.hadoop.ozone.TestOzoneConfigurationFields
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.191 s -- in org.apache.hadoop.ozone.TestOzoneConfigurationFields
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.258 s
[INFO] Finished at: 2026-07-22T19:49:01+09:00
[INFO] ------------------------------------------------------------------------

Detailed results for case 3(Validate the current ozone-default.xml: should pass)

[INFO] Running org.apache.hadoop.ozone.TestOzoneConfigurationFields
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.158 s -- in org.apache.hadoop.ozone.TestOzoneConfigurationFields
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

@cychiu8

cychiu8 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@adoroszlai Regarding HDDS-8082 you created, here is the PR. Happy to have your feedback whenever you get a chance.

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: There is an extra space after runtime string:.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. Thank you!

*/
@Test
public void testXmlValuesHaveNoEmbeddedNewlines() {
Set<String> xmlValuesWithNewlines = new HashSet<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Would a TreeSet be useful here to keep the failure output deterministic? The sibling checks in this class also use it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the feedback. It makes sense! I have addressed it.

@chihsuan chihsuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @cychiu8 LGTM!

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.

2 participants