-
Notifications
You must be signed in to change notification settings - Fork 992
Validate supported fields for xDS #6736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fe32d03
impl
jrhee17 4a74337
cleanup
jrhee17 78aa0fb
address comment by @ikhoon
jrhee17 6346707
rnn
jrhee17 63557af
lint,test failure
jrhee17 27c4958
address comment by @minwoox
jrhee17 88c95b9
Merge branch 'main' into feat/xds-support-3
jrhee17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...src/test/resources/META-INF/services/com.linecorp.armeria.xds.validator.XdsValidatorIndex
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| com.linecorp.armeria.xds.api.StrictXdsValidatorIndex |
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
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
59 changes: 59 additions & 0 deletions
59
xds-api/src/main/java/com/linecorp/armeria/xds/api/PgvValidator.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.linecorp.armeria.xds.api; | ||
|
|
||
| import com.google.protobuf.Message; | ||
|
|
||
| import com.linecorp.armeria.common.annotation.UnstableApi; | ||
| import com.linecorp.armeria.xds.validator.XdsValidationException; | ||
|
|
||
| import io.envoyproxy.pgv.ReflectiveValidatorIndex; | ||
| import io.envoyproxy.pgv.ValidationException; | ||
| import io.envoyproxy.pgv.ValidatorIndex; | ||
|
|
||
| /** | ||
| * Validates xDS protobuf messages using pgv (protoc-gen-validate) structural validation. | ||
| */ | ||
| @UnstableApi | ||
| public final class PgvValidator { | ||
|
|
||
| private static final PgvValidator INSTANCE = new PgvValidator(); | ||
|
|
||
| private final ValidatorIndex delegate = new ReflectiveValidatorIndex(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. static? |
||
|
|
||
| private PgvValidator() {} | ||
|
|
||
| /** | ||
| * Returns the singleton {@link PgvValidator} instance. | ||
| */ | ||
| public static PgvValidator of() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| /** | ||
| * Validates the given message using pgv structural validation. | ||
| * | ||
| * @throws XdsValidationException if validation fails | ||
| */ | ||
| public void assertValid(Message message) { | ||
| try { | ||
| delegate.validatorFor(message).assertValid(message); | ||
| } catch (ValidationException e) { | ||
| throw XdsValidationException.of(message, e); | ||
| } | ||
| } | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
xds-api/src/main/java/com/linecorp/armeria/xds/api/StrictXdsValidatorIndex.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY Corporation licenses this file to you under the Apache License, | ||
| * version 2.0 (the "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at: | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
| * License for the specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package com.linecorp.armeria.xds.api; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import com.google.protobuf.Message; | ||
|
|
||
| import com.linecorp.armeria.common.annotation.UnstableApi; | ||
| import com.linecorp.armeria.xds.validator.XdsValidationException; | ||
| import com.linecorp.armeria.xds.validator.XdsValidatorIndex; | ||
|
|
||
| /** | ||
| * A strict {@link XdsValidatorIndex} that composes pgv (protoc-gen-validate) structural validation | ||
| * with supported-field validation. All unsupported field violations are collected and reported | ||
| * together in a single {@link XdsValidationException}. | ||
| * | ||
| * <p>This validator is intended for use in test environments via SPI to catch unsupported | ||
| * field usage early. Its {@link #priority()} is {@code 1}, which is higher than | ||
| * {@link DefaultXdsValidatorIndex} ({@code 0}), so it wins SPI selection when present | ||
| * on the classpath. | ||
| */ | ||
| @UnstableApi | ||
| public final class StrictXdsValidatorIndex implements XdsValidatorIndex { | ||
|
|
||
| private final PgvValidator pgvValidator = PgvValidator.of(); | ||
|
|
||
| @Override | ||
| public void assertValid(Message message) { | ||
| requireNonNull(message, "message"); | ||
| pgvValidator.assertValid(message); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| final List<String> violations = new ArrayList<>(); | ||
| final SupportedFieldValidator validator = | ||
| SupportedFieldValidator.of((descriptorName, fieldPath, value) -> | ||
| violations.add(descriptorName + ": " + fieldPath)); | ||
| validator.validate(message); | ||
| if (!violations.isEmpty()) { | ||
| throw XdsValidationException.of( | ||
| message, "Unsupported xDS fields detected: " + String.join(", ", violations)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| return 1; | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.