[improve][admin] Validate dynamic configuration updates against FieldContext constraints#26087
Open
Dream95 wants to merge 1 commit into
Open
[improve][admin] Validate dynamic configuration updates against FieldContext constraints#26087Dream95 wants to merge 1 commit into
Dream95 wants to merge 1 commit into
Conversation
…Context constraints Signed-off-by: Dream95 <zhou_8621@163.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Most built-in dynamic configuration updates were not checked against
@FieldContextbefore being written to metadata. Validation only ran when a customPredicatewas registered, for example onloadManagerClassName.That meant invalid strings could be stored and only fail later at runtime, or not fail at all. Boolean fields were a concrete example:
FieldParserusesBoolean.valueOf(), sofailureDomainsEnabled=abcwas stored as"abc"butapplied as
falsewith no error.Modifications
isComplete()throughFieldContextValidator.validateParsedValue().FieldContextValidator.validateString()before persisting to ZK.BrokerService.getDynamicConfigurationValidationError()and return the specific message on HTTP 412 instead of" Invalid dynamic-config value".loadManagerClassName) afterFieldContextchecks.FieldContextValidatorTestand extendAdminApiDynamicConfigurationsTest.Admin updates now reject boolean values that are not exactly
trueorfalse.Startup and runtime loading still use
FieldParser, which callsBoolean.valueOf()and treats any other string asfalse.This change is scoped to the admin write path. Tightening
broker.confparsing or ZK replay would be a separate compatibility discussion.Verifying this change
Make sure that the change passes the CI checks.
./gradlew :pulsar-broker-common:test --tests org.apache.pulsar.common.configuration.FieldContextValidatorTest./gradlew :pulsar-broker-common:test --tests org.apache.pulsar.common.configuration.PulsarConfigurationLoaderTest./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.admin.AdminApiDynamicConfigurationsTestDoes this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Behavior changes
Affected admin API:
POST /admin/v2/brokers/configuration/{configName}/{configValue}Changes on this endpoint:
minValue/maxValue,maxCharLength, or boolean format.Unknown dynamic configuration: <key>instead ofCan't update non-dynamic configuration.trueorfalse(case-insensitive).