Skip to content

openmetrics v2: merge mapping-valued defaults instead of replacing them - #24921

Open
Kyle-Neale wants to merge 2 commits into
masterfrom
kyle.neale/openmetrics-v2-merge-mapping-defaults
Open

openmetrics v2: merge mapping-valued defaults instead of replacing them#24921
Kyle-Neale wants to merge 2 commits into
masterfrom
kyle.neale/openmetrics-v2-merge-mapping-defaults

Conversation

@Kyle-Neale

@Kyle-Neale Kyle-Neale commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

OpenMetricsBaseCheckV2.get_config_with_defaults layers the instance config over get_default_config() in a ChainMap, which resolves keys shallowly — so an instance that sets a mapping-valued option at all shadows the class default for that option wholesale instead of overriding individual entries.

Mapping-valued defaults are now merged entry by entry, with the instance's entries taking precedence. Defaults of any other type, notably the list-valued metrics, keep their existing replace semantics.

Motivation

Nine integrations declare rename_labels defaults this way to keep endpoint labels off Datadog's reserved tag keys. Adding one unrelated rename drops all of them and the raw reserved keys start being submitted as tags.

Verified on a real Agent scraping InterSystems IRIS: adding only rename_labels: {namespace: iris_namespace} replaced 24 interop_host: tags and 1 iris_version: tag with raw host:/version: tags. Metric count and health service check were unchanged, so the tag keys are the only signal — check_tag_names would have flagged it, but it exists only in the aggregator test stub.

Replace semantics for this case were untested and undocumented. kueue and avi_vantage already hand-roll this merge in their own code; both keep working unchanged, and their workarounds can be removed separately.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

🤖 Generated with Claude Code

`OpenMetricsBaseCheckV2.get_config_with_defaults` layers the instance config
over `get_default_config()` in a `ChainMap`, which resolves keys shallowly. An
instance that sets a mapping-valued option at all therefore shadows the class
default for that option wholesale rather than overriding individual entries.

The option this bites is `rename_labels`, which nine integrations use to keep
endpoint labels off Datadog's reserved tag keys (`host`, `version`, ...). A user
adding one unrelated rename silently drops every required rename, and the raw
reserved label keys start being submitted as tags. Nothing warns: the
forbidden-tag guard (`check_tag_names`) lives only in the aggregator test stub,
so this is loud in tests and silent in production.

Merge mapping-valued defaults with the instance's mapping entry by entry, with
the instance's own entries still taking precedence, so customizing such an
option adds to the defaults instead of replacing them. Options whose defaults
are of any other type -- notably the list-valued `metrics` -- keep their
existing replace semantics.

Replace semantics for this case were neither tested nor documented, so no
integration can have been relying on them deliberately. Two integrations
(`kueue`, `avi_vantage`) already hand-roll this exact merge in their own
`__init__`; those workarounds are now redundant and can be removed separately.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@Kyle-Neale Kyle-Neale added the qa/required QA is required for this PR and will generate a QA card label Aug 19, 2026
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 19, 2026

Copy link
Copy Markdown

evalya-impact-summary

evalya impact analysis
Impact analysis: 0 selected, 0 skipped (of 0 test tasks)
Publish tasks:   1 (always emitted)
Diff (3 files):
  datadog_checks_base/changelog.d/24921.fixed
  datadog_checks_base/datadog_checks/base/checks/openmetrics/v2/base.py
  datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_interface.py

Debug a specific task: evalya plan impact --path <path> --task <task>

Learn more about CI impact filtering

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Aug 19, 2026

Copy link
Copy Markdown

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 3 jobs - 3 passed on retry View in Datadog

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 88.69% (+0.09%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: c2455ae | Docs | View more details | Give us feedback!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e6ee494ed4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +145 to +148
if merged := {
option: {**default, **config[option]}
for option, default in defaults.items()
if isinstance(default, Mapping) and isinstance(config.get(option), Mapping)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit merging to options with additive semantics

When a Kuma instance explicitly supplies share_labels: {} or configures only a different source metric, this generic mapping merge also retains Kuma's default cp_info entry from kuma/datadog_checks/kuma/check.py:42. Previously the instance mapping replaced that default, but after this change LabelAggregator again propagates instance_id and version to the other metrics, unexpectedly changing their tags and leaving no way to disable that sharing. Restrict this merge to rename_labels, or define an explicit opt-out for other mapping-valued options.

Useful? React with 👍 / 👎.

check = Check('test', {}, [{'openmetrics_endpoint': 'test', 'rename_labels': {'qux': 'corge'}}])
dd_run_check(check)

assert default_renames == {'foo': 'bar'}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exercise isolation across two scraper configurations

This assertion only verifies that the caller-owned defaults dictionary was not mutated; it never creates a second scraper configuration or checks its effective renames, so it does not verify the stated behavior that one scraper's custom renames cannot leak into another. An implementation that caches accumulated merges on the check while leaving default_renames untouched would still pass, so the test should exercise two distinct configurations and assert their observable tag output.

AGENTS.md reference: AGENTS.md:L177-L180

Useful? React with 👍 / 👎.

@dd-octo-sts

dd-octo-sts Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant