-
Notifications
You must be signed in to change notification settings - Fork 968
Enforce IncludedExcludeModel .included and .excluded are not empty #8266
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
jack-berg
merged 3 commits into
open-telemetry:main
from
jack-berg:include-exclude-factory
Apr 10, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
37 changes: 37 additions & 0 deletions
37
.../main/java/io/opentelemetry/sdk/extension/incubator/fileconfig/IncludeExcludeFactory.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,37 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigException; | ||
| import io.opentelemetry.sdk.common.internal.IncludeExcludePredicate; | ||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.IncludeExcludeModel; | ||
| import java.util.List; | ||
| import java.util.function.Predicate; | ||
|
|
||
| final class IncludeExcludeFactory implements Factory<IncludeExcludeModel, Predicate<String>> { | ||
|
jack-berg marked this conversation as resolved.
|
||
|
|
||
| private static final IncludeExcludeFactory INSTANCE = new IncludeExcludeFactory(); | ||
|
|
||
| private IncludeExcludeFactory() {} | ||
|
|
||
| static IncludeExcludeFactory getInstance() { | ||
| return INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| public Predicate<String> create(IncludeExcludeModel model, DeclarativeConfigContext context) { | ||
| List<String> included = model.getIncluded(); | ||
| if (included != null && included.isEmpty()) { | ||
| throw new DeclarativeConfigException(".included must not be empty"); | ||
| } | ||
| List<String> excluded = model.getExcluded(); | ||
| if (excluded != null && excluded.isEmpty()) { | ||
| throw new DeclarativeConfigException(".excluded must not be empty"); | ||
| } | ||
|
|
||
| return IncludeExcludePredicate.createPatternMatching(included, excluded); | ||
| } | ||
| } | ||
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
77 changes: 77 additions & 0 deletions
77
...t/java/io/opentelemetry/sdk/extension/incubator/fileconfig/IncludeExcludeFactoryTest.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,77 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package io.opentelemetry.sdk.extension.incubator.fileconfig; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigException; | ||
| import io.opentelemetry.common.ComponentLoader; | ||
| import io.opentelemetry.sdk.common.internal.IncludeExcludePredicate; | ||
| import io.opentelemetry.sdk.extension.incubator.fileconfig.internal.model.IncludeExcludeModel; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.function.Predicate; | ||
| import java.util.stream.Stream; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
|
|
||
| class IncludeExcludeFactoryTest { | ||
|
|
||
| private final DeclarativeConfigContext context = | ||
| new DeclarativeConfigContext(ComponentLoader.forClassLoader(getClass().getClassLoader())); | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("createArguments") | ||
| void create(IncludeExcludeModel model, Predicate<String> expectedPredicate) { | ||
| Predicate<String> predicate = IncludeExcludeFactory.getInstance().create(model, context); | ||
| assertThat(predicate.toString()).isEqualTo(expectedPredicate.toString()); | ||
| } | ||
|
|
||
| private static Stream<Arguments> createArguments() { | ||
| return Stream.of( | ||
| // included null, excluded null | ||
| Arguments.of( | ||
| new IncludeExcludeModel().withIncluded(null).withExcluded(null), | ||
| IncludeExcludePredicate.createPatternMatching(null, null)), | ||
| // included present, excluded null | ||
| Arguments.of( | ||
| new IncludeExcludeModel().withIncluded(Arrays.asList("foo", "bar")).withExcluded(null), | ||
| IncludeExcludePredicate.createPatternMatching(Arrays.asList("foo", "bar"), null)), | ||
| // included null, excluded present | ||
| Arguments.of( | ||
| new IncludeExcludeModel() | ||
| .withIncluded(null) | ||
| .withExcluded(Collections.singletonList("baz")), | ||
| IncludeExcludePredicate.createPatternMatching(null, Collections.singletonList("baz"))), | ||
| // both included and excluded present | ||
| Arguments.of( | ||
| new IncludeExcludeModel() | ||
| .withIncluded(Arrays.asList("foo", "bar")) | ||
| .withExcluded(Collections.singletonList("baz")), | ||
| IncludeExcludePredicate.createPatternMatching( | ||
| Arrays.asList("foo", "bar"), Collections.singletonList("baz")))); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("createInvalidArguments") | ||
| void createInvalid(IncludeExcludeModel model, String expectedMessage) { | ||
| assertThatThrownBy(() -> IncludeExcludeFactory.getInstance().create(model, context)) | ||
| .isInstanceOf(DeclarativeConfigException.class) | ||
| .hasMessage(expectedMessage); | ||
| } | ||
|
|
||
| private static Stream<Arguments> createInvalidArguments() { | ||
| return Stream.of( | ||
| Arguments.of( | ||
| new IncludeExcludeModel().withIncluded(Collections.emptyList()).withExcluded(null), | ||
| ".included must not be empty"), | ||
| Arguments.of( | ||
| new IncludeExcludeModel().withIncluded(null).withExcluded(Collections.emptyList()), | ||
| ".excluded must not be empty")); | ||
| } | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since IncludeExcludeFactory is a recurring concept in the config schema, create a dedicated factory which consistently enforces the constraints