Skip to content

Enforce IncludedExcludeModel .included and .excluded are not empty#8266

Open
jack-berg wants to merge 3 commits intoopen-telemetry:mainfrom
jack-berg:include-exclude-factory
Open

Enforce IncludedExcludeModel .included and .excluded are not empty#8266
jack-berg wants to merge 3 commits intoopen-telemetry:mainfrom
jack-berg:include-exclude-factory

Conversation

@jack-berg
Copy link
Copy Markdown
Member

@jack-berg jack-berg requested a review from a team as a code owner April 8, 2026 16:25
import java.util.List;
import java.util.function.Predicate;

final class IncludeExcludeFactory implements Factory<IncludeExcludeModel, Predicate<String>> {
Copy link
Copy Markdown
Member Author

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

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 84.37500% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.28%. Comparing base (ec002c3) to head (d1aa80b).

Files with missing lines Patch % Lines
...ometheus/internal/PrometheusComponentProvider.java 33.33% 2 Missing and 2 partials ⚠️
.../fileconfig/ComposableRuleBasedSamplerFactory.java 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8266      +/-   ##
============================================
- Coverage     90.29%   90.28%   -0.02%     
- Complexity     7656     7667      +11     
============================================
  Files           844      845       +1     
  Lines         23071    23088      +17     
  Branches       2311     2318       +7     
============================================
+ Hits          20832    20845      +13     
- Misses         1521     1523       +2     
- Partials        718      720       +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.

Comment on lines +108 to +112
throw new DeclarativeConfigException(".included must not be empty");
}
List<String> excluded = attributePatternsModel.getExcluded();
if (excluded != null && excluded.isEmpty()) {
throw new DeclarativeConfigException(".excluded must not be empty");
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.

Is the . intentional here ? Can we provide parrent attribute name that helps the user to understand where the error is ? Is there any particular reason not to do the same with prometheus ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is the . intentional here

It was intentional because I thought that was the prevailing pattern but looking at other validation examples I was wrong. Will fix.

Can we provide parrent attribute name that helps the user to understand where the error is ?

I want to solve this holistically in #7949. Currently, we lack the context to have truly useful error messages. Sure we could include the type of the immediate parent, but that's a limited solution.

import java.util.List;
import java.util.function.Predicate;

final class IncludeExcludeFactory implements Factory<IncludeExcludeModel, Predicate<String>> {
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.

(minor/style) instead of having a dedicated factory class maybe we could have used a static factory method on IncludeExcludePredicate to keep things simpler as the factory is purely static here and has no state.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This factory pattern is employed widely in declarative config with the general pattern being one factory per model, with each factory responsible for translating an instance of the model to an instance of a corresponding SDK component. They're all stateless, but having singleton instances is still useful because it forces consistency in the pattern.

Can't move to IncludeExcludePredicate because the model class isn't there. Could have a static method in IncludeExcludePredicate which accepts @Nullable List<String> included and @Nullable List<String> excluded parameters, but DeclarativeConfigException isn't available so would need to wrap the call in a try/catch and map the IllegalArgumentException to DeclarativeConfigException.

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.

2 participants