Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk-extensions/declarative-config/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ jsonSchema2Pojo {

// Append Model as suffix to the generated classes.
classNameSuffix = "Model"

// Initialize collection fields to null rather than empty collections so that absent YAML
// properties deserialize as null (not present) rather than [] (explicitly empty). This lets
// factories distinguish between "user omitted the field" and "user provided an empty list",
// which is important for validations like IncludeExcludeFactory.
initializeCollections = false
}

val generateJsonSchema2Pojo = tasks.getByName("generateJsonSchema2Pojo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ public ComposableSampler create(
rule -> {
AttributeMatcher valueMatcher = attributeValuesMatcher(rule.getAttributeValues());
AttributeMatcher patternMatcher = attributePatternsMatcher(rule.getAttributePatterns());
// TODO: should be null when omitted but is empty
Set<ExperimentalSpanParent> matchingParents =
rule.getParent() != null && !rule.getParent().isEmpty()
? new HashSet<>(rule.getParent())
: null;
// TODO: should be null when omitted but is empty
Set<SpanKind> matchingSpanKinds =
rule.getSpanKinds() != null && !rule.getSpanKinds().isEmpty()
? rule.getSpanKinds().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@ private static Stream<Arguments> createTestCases() {
Arguments.of(
new ExperimentalComposableRuleBasedSamplerModel(),
ComposableSampler.ruleBasedBuilder().build()),
// attributePatterns with only included (no excluded) - analogous to
// https://github.com/open-telemetry/opentelemetry-java/issues/8337
Arguments.of(
new ExperimentalComposableRuleBasedSamplerModel()
.withRules(
Collections.singletonList(
new ExperimentalComposableRuleBasedSamplerRuleModel()
.withAttributePatterns(
new ExperimentalComposableRuleBasedSamplerRuleAttributePatternsModel()
.withKey("http.path")
.withIncluded(Collections.singletonList("/internal/*")))
.withSampler(
new ExperimentalComposableSamplerModel()
.withAlwaysOn(
new ExperimentalComposableAlwaysOnSamplerModel())))),
ComposableSampler.ruleBasedBuilder()
.add(
new DeclarativeConfigSamplingPredicate(
null,
new AttributeMatcher(
"http.path",
IncludeExcludePredicate.createPatternMatching(
Collections.singletonList("/internal/*"), null)),
null,
null),
ComposableSampler.alwaysOn())
.build()),
// Recreate example
Arguments.of(
new ExperimentalComposableRuleBasedSamplerModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,65 @@
import io.opentelemetry.sdk.metrics.View;
import java.util.Arrays;
import java.util.Collections;
import org.junit.jupiter.api.Test;
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 ViewFactoryTest {

@Test
void create_Defaults() {
View expectedView = View.builder().build();

View view =
ViewFactory.getInstance()
.create(
new ViewStreamModel().withAttributeKeys(null),
mock(DeclarativeConfigContext.class));

@ParameterizedTest
@MethodSource("createArguments")
void create(ViewStreamModel model, View expectedView) {
View view = ViewFactory.getInstance().create(model, mock(DeclarativeConfigContext.class));
assertThat(view.toString()).isEqualTo(expectedView.toString());
}

@Test
void create() {
View expectedView =
View.builder()
.setName("name")
.setDescription("description")
.setAttributeFilter(
IncludeExcludePredicate.createPatternMatching(
Arrays.asList("foo", "bar"), Collections.singletonList("baz")))
.setAggregation(
Aggregation.explicitBucketHistogram(
ExplicitBucketHistogramOptions.builder()
.setBucketBoundaries(Arrays.asList(1.0, 2.0))
.build()))
.build();

View view =
ViewFactory.getInstance()
.create(
new ViewStreamModel()
.withName("name")
.withDescription("description")
.withAttributeKeys(
new IncludeExcludeModel()
.withIncluded(Arrays.asList("foo", "bar"))
.withExcluded(Collections.singletonList("baz")))
.withAggregation(
new AggregationModel()
.withExplicitBucketHistogram(
new ExplicitBucketHistogramAggregationModel()
.withBoundaries(Arrays.asList(1.0, 2.0)))),
mock(DeclarativeConfigContext.class));

assertThat(view.toString()).isEqualTo(expectedView.toString());
private static Stream<Arguments> createArguments() {
return Stream.of(
// defaults
Arguments.of(new ViewStreamModel().withAttributeKeys(null), View.builder().build()),
// attribute_keys with only included (no excluded) - reproduces
// https://github.com/open-telemetry/opentelemetry-java/issues/8337
Arguments.of(
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 new test case fails without the change to build.gradle.kts.

Refactored these tests to follow the parameterized test pattern used elsewhere in these declarative config factory tests.

new ViewStreamModel()
.withAttributeKeys(
new IncludeExcludeModel()
.withIncluded(
Arrays.asList(
"url.full", "http.request.method", "http.response.status_code"))),
View.builder()
.setAttributeFilter(
IncludeExcludePredicate.createPatternMatching(
Arrays.asList(
"url.full", "http.request.method", "http.response.status_code"),
null))
.build()),
// full configuration
Arguments.of(
new ViewStreamModel()
.withName("name")
.withDescription("description")
.withAttributeKeys(
new IncludeExcludeModel()
.withIncluded(Arrays.asList("foo", "bar"))
.withExcluded(Collections.singletonList("baz")))
.withAggregation(
new AggregationModel()
.withExplicitBucketHistogram(
new ExplicitBucketHistogramAggregationModel()
.withBoundaries(Arrays.asList(1.0, 2.0)))),
View.builder()
.setName("name")
.setDescription("description")
.setAttributeFilter(
IncludeExcludePredicate.createPatternMatching(
Arrays.asList("foo", "bar"), Collections.singletonList("baz")))
.setAggregation(
Aggregation.explicitBucketHistogram(
ExplicitBucketHistogramOptions.builder()
.setBucketBoundaries(Arrays.asList(1.0, 2.0))
.build()))
.build()));
}
}
Loading