Skip to content

[dynamic control] fix incorrectly special case parsing#3010

Open
jackshirazi wants to merge 3 commits into
open-telemetry:mainfrom
jackshirazi:policy-phase2-21
Open

[dynamic control] fix incorrectly special case parsing#3010
jackshirazi wants to merge 3 commits into
open-telemetry:mainfrom
jackshirazi:policy-phase2-21

Conversation

@jackshirazi

Copy link
Copy Markdown
Contributor

Description:

There was a special case parsing in OpampPolicyProvider, if ( ... format == SourceFormat.JSONKEYVALUE), on reviewing the code this clearly shouldn't be there, any parsing should exist within the format parsing and the provider should delegate all cases to there. This PR fixes this code smell.

Note the LinePerPolicyFileProvider.java and the keyvalue format are not fully implemented for now, they're pending later changes when the file provider is more fully specified

Existing Issue(s):

#2868

Testing:

changed as needed

Documentation:

not needed for this tech debt fix

Outstanding items:

#2868

@jackshirazi
jackshirazi requested a review from a team as a code owner July 21, 2026 19:34
Copilot AI review requested due to automatic review settings July 21, 2026 19:34
@github-actions
github-actions Bot requested a review from LikeTheSalad July 21, 2026 19:34

Copilot AI left a comment

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.

Pull request overview

This PR refactors dynamic-control policy payload parsing so providers always delegate parsing to SourceFormat (removing an OpAMP-specific JSON parsing fallback), and updates the JSON parsing path to validate policy IDs against configured mappings.

Changes:

  • Extend SourceFormat.parse / JsonSourceWrapper.parse to accept a mappedPolicyIds set and use it during parsing (JSONKEYVALUE).
  • Remove OpampPolicyProvider’s JSONKEYVALUE special-case parsing logic and delegate parsing solely to SourceFormat.
  • Update unit tests and the file-based provider to pass mapped/allowed policy IDs into the parser.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/source/SourceFormat.java Changes the parsing API to require mapped policy IDs and dispatches parsing with that context.
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/source/JsonSourceWrapper.java Updates JSON parsing to validate JSON object keys against configured mapped policy IDs.
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/OpampPolicyProvider.java Removes OpAMP-only JSONKEYVALUE fallback parsing and delegates parsing to SourceFormat.
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/LinePerPolicyFileProvider.java Computes allowed policy IDs from validators and passes them into SourceFormat.parse.
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/source/SourceFormatTest.java Updates tests for the new parse signature + adds coverage for rejecting unmapped JSON keys.
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/source/JsonSourceWrapperTest.java Updates tests for the new parse signature + adds coverage for rejecting unmapped JSON keys.
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/tracesampling/TraceSamplingValidatorTest.java Updates tests to provide mapped policy IDs when parsing source text.

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

return;
}
List<SourceWrapper> parsedSources = format.parse(trimmedLine);
List<SourceWrapper> parsedSources = format.parse(trimmedLine, policyIds);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think we lose some safety here in terms of rejecting objects with more than 1 item. Take a look at jackshirazi#1

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.

4 participants