[dynamic control] support the current spec structure - #3037
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
There are several fixable issues in the changed code/docs (Javadoc mismatch vs behavior, unnecessary log-message allocations, Markdown formatting, and a binary-compatibility risk from adding a method to a public interface).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
Aligns the dynamic-control JSON ingestion pipeline with the evolving OpenTelemetry spec by supporting “full policy” JSON objects (with id, name, and a single signal target containing match and keep) in addition to the existing keyed {"policy-id": value} shape.
Changes:
- Extend
JsonSourceWrapperparsing to accept full policy objects, unwrap the policy-specifickeepvalue, and support remapping via a newSourceWrapper.withPolicyType(...)API. - Update validation/conversion flow (
MappedPolicySourceConverter,AbstractSourcePolicyValidator, file provider) to operate on the normalized/remapped source and to validate against unwrapped policy values. - Add/adjust tests and update README documentation to cover the full policy structure and updated JSON parsing behavior.
File summaries
| File | Description |
|---|---|
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/source/SourceWrapper.java | Adds withPolicyType API for remapping policy identifiers. |
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/source/KeyValueSourceWrapper.java | Implements withPolicyType for KEYVALUE sources. |
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/source/JsonSourceWrapper.java | Adds full-policy parsing/validation, getPolicyValue() unwrapping, and remapping behavior. |
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/MappedPolicySourceConverter.java | Switches to SourceWrapper.withPolicyType(...) for normalization/remapping. |
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/AbstractSourcePolicyValidator.java | Validates JSON policies using JsonSourceWrapper.getPolicyType() + getPolicyValue(). |
| dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/LinePerPolicyFileProvider.java | Accepts per-line full policy JSON via isSinglePolicyObject. |
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/tracesampling/TraceSamplingValidatorTest.java | Updates trace sampling JSON tests to use full policy structure + additional envelope checks. |
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/source/SourceFormatTest.java | Updates expectations for multi-key JSON objects (now rejected). |
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/source/KeyValueSourceWrapperTest.java | Adds withPolicyType immutability/remap behavior test. |
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/source/JsonSourceWrapperTest.java | Adds extensive coverage for full policy parsing, dropping invalid objects, and remapping. |
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/MappedPolicySourceConverterTest.java | New test ensuring full policy remapping does not mutate the original source. |
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/LinePerPolicyFileProviderTest.java | Adds coverage for parsing full-policy JSON lines. |
| dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/AbstractSourcePolicyValidatorTest.java | New test ensuring validators receive only the unwrapped keep value. |
| dynamic-control/README.md | Documents full policy object support for jsonkeyvalue sources and updates formatting. |
Review details
- Files reviewed: 14/14 changed files
- Comments generated: 4
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
It introduces a couple of concrete correctness/docs issues (notably inconsistent whitespace handling for required text fields and a Markdown list formatting problem) that should be addressed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Review details
Suppressed comments (2)
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/source/JsonSourceWrapper.java:295
hasNonEmptyTexttrims to check emptiness but otherwise treats leading/trailing whitespace as acceptable, while mapping and policy-id comparisons use the rawasText()value. This inconsistency means anid/namelike " trace-sampling " is considered structurally valid but will never match configured mappings, leading to confusing drops. Consider rejecting leading/trailing whitespace explicitly (or normalize consistently).
private static boolean hasNonEmptyText(@Nullable JsonNode value) {
return value != null && value.isTextual() && !value.asText().trim().isEmpty();
}
dynamic-control/README.md:180
- The JSON example code block isn’t indented under the
jsonkeyvaluelist item, so it will typically break the surrounding list formatting in Markdown. Indent the fenced block to keep it associated with the bullet item.
array, and a target `keep` value. The `id` must match a configured `policyId`. For example:
```json
{
"id": "trace-sampling",
- Files reviewed: 14/14 changed files
- Comments generated: 0 new
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Description:
Align to spec, supporting the fuller message structure for JSON structures.
Primarily this adds parsing in the JsonSourceWrapper, and some smaller changes in other classes that use that source wrapper supported by a new interface method. Plus a bunch of tests
Existing Issue(s):
#2868
Testing:
changed as needed
Documentation:
changed as needed
Outstanding items:
#2868