Skip to content

Validate Property Values#3177

Merged
dlmarion merged 10 commits into
apache:2.1from
ddanielr:bugfix/property-validation
Feb 2, 2023
Merged

Validate Property Values#3177
dlmarion merged 10 commits into
apache:2.1from
ddanielr:bugfix/property-validation

Conversation

@ddanielr

Copy link
Copy Markdown
Contributor

Closes #3145
These changes add the ability to validate system, namespace, and table-specific properties for accumulo.

Values are now being validated on the backend and client validation exceptions show as a ThriftPropertyException exception type.

See #3173 for WIP feedback if desired.

Refactor the `isTablePropertyValid` method to be more generic.

This change moves the `isValidTablePropertyKey` method calls out
from the `isTablePropertyValid` method and to the calling locations.
This allows for the `isTablePropertyValid` method to be renamed to
`isValidProperty`.

Moving that method allowed for error messages to accurately discribe
an invalid table property error and an invalid value error.

Added 'throws' to method signatures in partial attempt to improve
error visibilites.
Adds new `ThriftPropertyException` to allow for the
`IllegalArgumentException` runtime expection to be caught and displayed
to the client.

Raise exceptions for setting invalid properties at the system,
namespace, and table level.
Validate System properties as well as check if property is mutable
in zookeeper.
Add tests for setting invalid system, namespace, and table properties.
Change the error messages to be more uniform for test validation.
break;
case CLASSNAME:
Shell.log.debug("CLASSNAME properties currently fail this test");
Shell.log.debug("Regex used for CLASSNAME property types may need to be modified");

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.

Should we fix the regex as part of this PR?

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.

Currently, all of these changes don't alter property structure, they just enforce the previously defined types.

Modifying a property regex has the potential to break legitimate uses.
So, I'd rather open an issue for the regex fix and track that as a separate action.

Comment thread test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java Outdated
@dlmarion

Copy link
Copy Markdown
Contributor

Kicked off full IT build

@dlmarion

Copy link
Copy Markdown
Contributor

Full IT build succeeded.

Change the `tableName` variable to use `getUniqueNames()` for
uniformity.
Comment thread test/src/main/java/org/apache/accumulo/test/shell/ShellIT.java Outdated
Comment thread test/src/main/java/org/apache/accumulo/test/shell/ShellIT.java Outdated
Comment thread core/src/test/java/org/apache/accumulo/core/conf/PropertyTest.java Outdated

@EdColeman EdColeman 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.

Looks good - just some minor suggestions.

Remove unnecessary `toString()` calls on `propertyType`.
Add a property validation test in the `PropertyTest` class.
This new test replaces the boolean-only validation test.

@EdColeman EdColeman 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.

LGTM - maybe as a follow-on the tests in PropertyTest could be expanded to test variations of valid values. The boolean test that was modified was testing combinations of true, True, false, False, my initial though that it was unnecessary to loop through all of the properties, not the condition.

The testPropertyValidation test is a nice addition to check that each type will fail validation.

While the is a specific host:port test in PropertyTest, it may be an improvement if tests were included for things like 100M, 100m, 100G, 100g for memory, (or whatever is valid) for each of the expected types (assuming that they are not tested elsewhere)

@EdColeman EdColeman 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.

Noticed that the check failed with a junit package issue:

Expected 0, but found 1 classes using the wrong JUnit APIs:
core/src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java
Error: Process completed with exit code 1.

Not sure where that is coming from, but it should be corrected before merging

@EdColeman

Copy link
Copy Markdown
Contributor

The offending import in TabletLocatorImplTest is

import org.junit.Assert;

Also, there may be other checkstyle issues that need to be addressed:

[WARNING] src/main/java/org/apache/accumulo/core/clientImpl/TabletLocatorImpl.java:[356,9] (blocks) NeedBraces: 'if' construct must use '{}'s.
[WARNING] src/test/java/org/apache/accumulo/core/clientImpl/TabletLocatorImplTest.java:[61] (regexp) RegexpSinglelineJava: Use static imports for Assert.* methods for consistency

@ddanielr

ddanielr commented Feb 1, 2023

Copy link
Copy Markdown
Contributor Author

@EdColeman those changes weren't introduced in this PR.

I think the latest merge to 2.1 caused the problem
cb22cc4

@EdColeman

Copy link
Copy Markdown
Contributor

I have a PR incoming to fix 2.1

@EdColeman

Copy link
Copy Markdown
Contributor

Should be fixed when #3179 is merged

@ddanielr

ddanielr commented Feb 1, 2023

Copy link
Copy Markdown
Contributor Author

@EdColeman I merged in the latest changes from 2.1 and all tests are now passing.

Comment thread core/src/test/java/org/apache/accumulo/core/conf/PropertyTest.java Outdated
Comment thread server/base/src/main/java/org/apache/accumulo/server/util/SystemPropUtil.java Outdated
Comment thread test/src/main/java/org/apache/accumulo/test/NamespacesIT.java Outdated
Switch the logger from "debug" to "error" in SystemPropUtil
Use test namespace instead of creating a new one in NamespacesIT
Add a logger and remove `System.out.print` statements in PropertyTest.
@dlmarion dlmarion linked an issue Feb 2, 2023 that may be closed by this pull request
IllegalArgumentException iae =
new IllegalArgumentException("Zookeeper property is not mutable: " + property);
log.debug("Attempted to set zookeeper property. It is not mutable", iae);
log.error("Encountered error setting zookeeper property", iae);

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.

Did you happen to look at the exceptions as printed in the logs? It seems likely that the method that catches the exception will also printout the stack trace. If there was additional info to help development, maybe a trace statement? Otherwise the logs may end up with two identical stack traces without adding additional information.

Also, error seems rather aggressive, services are going to keep running,

If this code get reworked, it may be worth considering.

(I realize this has been merged, it was changed, committed before I got back to it. Just wanted to mention it if it helps going forward)

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.

@EdColeman confirmed that the calling method does in fact log the exceptions at the error level.
I've opened #3184 to revert this change.

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.

Shell commands allow for invalid Property types to be set

5 participants