Skip to content

[dynamic control] Add pipeline config initialization from declarative config or failover to file#2766

Merged
jaydeluca merged 6 commits into
open-telemetry:mainfrom
jackshirazi:policy23a
May 7, 2026
Merged

[dynamic control] Add pipeline config initialization from declarative config or failover to file#2766
jaydeluca merged 6 commits into
open-telemetry:mainfrom
jackshirazi:policy23a

Conversation

@jackshirazi

Copy link
Copy Markdown
Contributor

Description:

Adding a method to read pipeline initialization from declarative config, or if not present failover to a file in yaml (or a json file).

The declarative config looks like

telemetry_policy:
  sources:
    - kind: opamp
      format: jsonkeyvalue
      location: vendor
      mappings:
        - sourceKey: sampling_rate
          policyType: trace_sampling_rate_policy

If declarative config is not present, the failover file is expected to have the node under telemetry_policy, ie starting at sources as the top-level node

Existing Issue(s):

#2546

Testing:

Added

Documentation:

Added

Outstanding items:

Wiring up the policy pipeline:

  • Generic: message -> provider -> policy -> policy handler -> implementer
  • eg change sampling rate message -> OpampPolicyProvider -> TraceSamplingRatePolicy -> PolicyStore -> TraceSamplingRatePolicyImplementer

Steps needed for the wiring:

  • configuring the pipeline
    • DONE in this PR
  • providers reading policies, eg OpampPolicyProvider, FilePolicyProvider, etc
    • DONE: OpampPolicyProvider
  • implementers applying policies, eg TraceSamplingRatePolicyImplementer
    • DONE: TraceSamplingRatePolicyImplementer
  • policy structures (eg TraceSamplingRatePolicy) that the provider converts messages into
    • DONE: TraceSamplingRatePolicy
  • registering config to policy structures (eg "trace_sampling_rate_policy" registered to TraceSamplingRatePolicy)
  • initializing policy classes (eg TraceSamplingRatePolicy needs to install a custom sampler)
    • DONE TraceSamplingRatePolicy initialization
  • activate configured providers (eg start OpampPolicyprovider reading from it's source)
  • register implementers for policies (eg a new TraceSamplingRatePolicy is applied by a TraceSamplingRatePolicyImplementer)
  • link the provider to processing policies and applying implementers

Copilot AI review requested due to automatic review settings April 17, 2026 13:37
@jackshirazi
jackshirazi requested a review from a team as a code owner April 17, 2026 13:37
@github-actions
github-actions Bot requested a review from LikeTheSalad April 17, 2026 13:38

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

Adds initialization of dynamic-control’s telemetry policy pipeline from OpenTelemetry declarative config (preferred) with fallback to file-based YAML/JSON config.

Changes:

  • Add PolicyInitConfig loaders for declarative config (telemetry_policy.sources) and declarative-first fallback helpers (including via OpenTelemetry / ExtendedOpenTelemetry).
  • Add file-based loading from otel.java.experimental.telemetry.policy.init.yaml/json with YAML precedence and warning-on-failure behavior.
  • Add unit tests covering declarative vs file fallback selection and error cases.

Reviewed changes

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

File Description
dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/registry/PolicyInitConfig.java Implements declarative-first init config parsing and file fallback, plus reflective access to “general config” accessor.
dynamic-control/src/test/java/io/opentelemetry/contrib/dynamic/policy/registry/PolicyInitConfigTest.java Adds tests for YAML/JSON precedence, parse failures, and declarative-vs-file selection paths.

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

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

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

dynamic-control/src/main/java/io/opentelemetry/contrib/dynamic/policy/registry/json/JsonNodePolicyInitConfigParser.java:55

  • JSON init-config parsing now trims/normalizes optional location, but other string fields (kind, format, sourceKey, policyType) are still accepted with leading/trailing whitespace (and even whitespace-only, since requireText only checks isEmpty()). This can lead to hard-to-debug mismatches because mapping keys/policy types are used verbatim downstream. Consider trimming and validating non-blank in requireText (returning the trimmed value), and applying the same normalization to mapping fields for consistency with declarative parsing.
    JsonNode locationNode = objectNode.get("location");
    String location =
        locationNode != null && locationNode.isTextual()
            ? normalizeOptionalText(locationNode.asText())
            : null;

    JsonNode mappingsNode =
        requireArray(objectNode.get("mappings"), "Each source must define a 'mappings' array.");
    List<PolicySourceMappingConfig> mappings = new ArrayList<>();

jackshirazi and others added 3 commits May 7, 2026 14:36
Although strictly speaking not a bug to have empty source mappings, it seems silly and most likely an error so agree it's good to catch it

Co-authored-by: Jay DeLuca <[email protected]>
@jaydeluca
jaydeluca enabled auto-merge May 7, 2026 14:50
@jaydeluca
jaydeluca added this pull request to the merge queue May 7, 2026
Merged via the queue into open-telemetry:main with commit e18edf9 May 7, 2026
32 of 34 checks passed
@jackshirazi
jackshirazi deleted the policy23a branch May 13, 2026 08:24
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