Skip to content

[dynamic control] add config parsing for both json and yaml#2738

Merged
jaydeluca merged 9 commits intoopen-telemetry:mainfrom
jackshirazi:policy19
Apr 7, 2026
Merged

[dynamic control] add config parsing for both json and yaml#2738
jaydeluca merged 9 commits intoopen-telemetry:mainfrom
jackshirazi:policy19

Conversation

@jackshirazi
Copy link
Copy Markdown
Contributor

Description:

Adding parsing for json and yaml of initialization of the Policy pipeline for examples like the following json or yaml

{
  "sources": [
    {
      "kind": "opamp",
      "format": "jsonkeyvalue",
      "location": "vendor-specific",
      "mappings": [
        { "sourceKey": "sampling_rate", "policyType": "trace_sampling_rate_policy" },
        { "sourceKey": "send_logs", "policyType": "log_export_enabled_policy" }
      ]
    },
    {
      "kind": "file",
      "format": "keyvalue",
      "location": "/some/path/conf.file",
      "mappings": [
        { "sourceKey": "send_metrics", "policyType": "metric_export_enabled_policy" }
      ]
    }
  ]
}
sources:
  - kind: opamp
    format: jsonkeyvalue
    location: vendor-specific
    mappings:
      - sourceKey: sampling_rate
        policyType: trace_sampling_rate_policy
      - sourceKey: send_logs
        policyType: log_export_enabled_policy

  - kind: file
    format: keyvalue
    location: /some/path/conf.file
    mappings:
      - sourceKey: send_metrics
        policyType: metric_export_enabled_policy

Existing Issue(s):

#2546

Testing:

Added

Documentation:

to be added

Outstanding items:

Still to hook up config to actual policy and build the pipeline

@jackshirazi jackshirazi requested a review from a team as a code owner April 2, 2026 16:35
Copilot AI review requested due to automatic review settings April 2, 2026 16:35
@github-actions github-actions Bot requested a review from LikeTheSalad April 2, 2026 16:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds initial configuration parsing support for the dynamic-control policy registry, allowing the registry init model to be constructed from either JSON or YAML payloads/files.

Changes:

  • Introduces a shared JsonNode-based parser (JsonNodePolicyInitConfigParser) that converts config into PolicyInitConfig.
  • Adds JSON and YAML PolicyInitConfigReader implementations backed by Jackson (with YAMLFactory for YAML).
  • Adds unit tests for JSON/YAML reader behavior and validation errors; adds YAML Jackson dependency.

Reviewed changes

Copilot reviewed 6 out of 6 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/registry/json/JsonNodePolicyInitConfigParser.java Implements shared JsonNode → model parsing and validation logic.
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/registry/json/PolicyInitConfigReader.java Adds JSON reader that parses into JsonNode then delegates to the shared parser.
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/registry/yaml/PolicyInitConfigReader.java Adds YAML reader using Jackson YAMLFactory, delegating to the shared parser.
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/registry/json/PolicyInitConfigReaderTest.java Adds JSON reader tests (fixture + validation error cases).
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/registry/yaml/PolicyInitConfigReaderTest.java Adds YAML reader tests (fixture + validation error cases).
dynamic-control/build.gradle.kts Adds jackson-dataformat-yaml dependency for YAML parsing support.


private static final ObjectMapper MAPPER = new ObjectMapper(new YAMLFactory());

public PolicyInitConfig read(InputStream in) throws IOException {
Copy link
Copy Markdown
Member

@jaydeluca jaydeluca Apr 7, 2026

Choose a reason for hiding this comment

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

since these reader classes don't have any state, could they be static utility classes like JsonNodePolicyInitConfigParser?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, good call. If they need to be polymorphic we can move them back to instance methods but per your point I've made them static now

@jaydeluca jaydeluca enabled auto-merge April 7, 2026 20:22
@jaydeluca jaydeluca added this pull request to the merge queue Apr 7, 2026
Merged via the queue into open-telemetry:main with commit 5a76ebb Apr 7, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants