Skip to content

[AI-8th] Add @Validated Support for Configuration Properties#1416

Open
pmupkin wants to merge 3 commits intosofastack:masterfrom
pmupkin:AI-8th-add-properties-validation
Open

[AI-8th] Add @Validated Support for Configuration Properties#1416
pmupkin wants to merge 3 commits intosofastack:masterfrom
pmupkin:AI-8th-add-properties-validation

Conversation

@pmupkin
Copy link
Copy Markdown

@pmupkin pmupkin commented Apr 9, 2026

Related issue #1405
AI Agent: Codex-GPT-5.4 && Claude-Opus-4.6

  • Added startup validation for key SOFABoot configuration properties.
  • Introduced Bean Validation dependency and @validated constraints.
  • Added a custom validator for SofaBootRpcProperties while preserving backward compatibility.
  • Added tests to ensure invalid configuration fails fast with clear validation errors.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.20%. Comparing base (459b02f) to head (5ab922a).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1416      +/-   ##
============================================
+ Coverage     82.94%   83.20%   +0.26%     
- Complexity     2975     3014      +39     
============================================
  Files           340      341       +1     
  Lines          9833     9964     +131     
  Branches       1178     1188      +10     
============================================
+ Hits           8156     8291     +135     
+ Misses         1163     1161       -2     
+ Partials        514      512       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Bean Validation (JSR-303/Jakarta Validation) to key @ConfigurationProperties classes so invalid configuration values fail fast at startup with clearer error messages, aligning with issue #1405’s goal of improving configuration correctness and diagnostics.

Changes:

  • Introduces spring-boot-starter-validation to provide runtime validation support.
  • Adds @Validated and constraint annotations to multiple configuration properties classes (tracer/runtime/isle/health) and adds a custom class-level validator for RPC properties.
  • Adds/extends auto-configuration tests to assert startup fails with expected validation messages for invalid property values.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
sofa-boot-project/sofaboot-dependencies/pom.xml Manages spring-boot-starter-validation version for the build/BOM.
sofa-boot-project/sofa-boot-autoconfigure/pom.xml Adds validation starter dependency to enable properties validation at runtime.
sofa-boot-project/sofa-boot-actuator-autoconfigure/pom.xml Adds validation starter dependency for actuator autoconfigure validation.
sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/tracer/SofaTracerProperties.java Adds @Validated and constraints for tracer-related properties.
sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeProperties.java Adds @Validated, numeric constraints, and a cross-field pool-size validity check.
sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/isle/SofaModuleProperties.java Adds @Validated and positivity constraints for parallel refresh settings.
sofa-boot-project/sofa-boot-actuator-autoconfigure/src/main/java/com/alipay/sofa/boot/actuator/autoconfigure/health/HealthProperties.java Adds @Validated and positivity constraints for health timeouts.
sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcProperties.java Enables validation and applies a class-level custom constraint.
sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/ValidSofaBootRpcProperties.java New custom constraint annotation for RPC properties.
sofa-boot-project/sofa-boot-autoconfigure/src/main/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaBootRpcPropertiesValidator.java New validator implementing RPC cross-field/range/format validation with targeted messages.
sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/tracer/SofaTracerAutoConfigurationTests.java Adds fail-fast test for invalid tracer sampling percentage.
sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/runtime/SofaRuntimeAutoConfigurationTests.java Adds fail-fast test for invalid async executor sizing.
sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/rpc/SofaRpcAutoConfigurationTests.java Adds fail-fast test for invalid RPC port/weight settings.
sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/boot/autoconfigure/isle/SofaModuleAutoConfigurationTests.java Adds fail-fast test for invalid parallel refresh factor.
sofa-boot-project/sofa-boot-actuator-autoconfigure/src/test/java/com/alipay/sofa/boot/actuator/autoconfigure/health/ReadinessAutoConfigurationTests.java Adds fail-fast test for invalid health timeout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CrazyHZM
Copy link
Copy Markdown
Member

@pmupkin Please change some of the Chinese descriptions to English.

@sofastack-cla sofastack-cla Bot added size/XL and removed size/L labels Apr 21, 2026
@CrazyHZM
Copy link
Copy Markdown
Member

@pmupkin I noticed that some descriptions haven't been corrected yet, please change the description to English as soon as possible, thanks.

@pmupkin
Copy link
Copy Markdown
Author

pmupkin commented Apr 24, 2026

@pmupkin I noticed that some descriptions haven't been corrected yet, please change the description to English as soon as possible, thanks.

@pmupkin I noticed that some descriptions haven't been corrected yet, please change the description to English as soon as possible, thanks.

ok

Comment on lines +30 to +46
public class SofaBootRpcPropertiesValidator
implements
ConstraintValidator<ValidSofaBootRpcProperties, SofaBootRpcProperties> {

@Override
public boolean isValid(SofaBootRpcProperties value, ConstraintValidatorContext context) {
if (value == null) {
return true;
}
context.disableDefaultConstraintViolation();
boolean valid = true;

valid = validatePort(context, valid, "boltPort", value.getBoltPort(),
"Bolt port must be between 1024 and 65535");
valid = validatePort(context, valid, "h2cPort", value.getH2cPort(),
"H2C port must be between 1024 and 65535");
valid = validatePort(context, valid, "restPort", value.getRestPort(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does the verification of rpc need to be handled separately?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants