Skip to content

Add Config Discovery support for Vault - #24851

Draft
martavicentenavarro wants to merge 5 commits into
masterfrom
add-vault-config-discovery
Draft

Add Config Discovery support for Vault#24851
martavicentenavarro wants to merge 5 commits into
masterfrom
add-vault-config-discovery

Conversation

@martavicentenavarro

@martavicentenavarro martavicentenavarro commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds Config Discovery support to the Vault integration. assets/configuration/spec.yaml now declares a discovery: strategy block that matches on port 8200 and the vault container image, generating two candidates in priority order, both with no_token: true:

  1. OpenMetrics scrape, no token
  2. Legacy (non-OpenMetrics) collection, no token

This covers Vault's use_openmetrics dispatch (OpenMetrics vs. legacy collection). Both candidates set no_token: true deliberately: discovery has no way to obtain a client_token/client_token_path on its own, and without one of no_token, client_token, or client_token_path set, VaultCheckV2.metric_collection_enabled (and the equivalent legacy-check gating) disables the metrics scrape entirely — the check would only ever reach Vault's always-unauthenticated /sys/health and /sys/leader endpoints. Since discovery accepts the first candidate whose run completes without error and collects at least one metric, a token-less candidate without no_token could still "succeed" on health/leader data alone and get locked in permanently as a degraded config with no real metrics. Earlier candidates that combined use_openmetrics/legacy mode without any credential signal were removed for this reason; only the two no_token: true candidates remain.

Also:

  • Wires get_e2e_discovery_metadata() into the E2E docker environment (tests/conftest.py) so the Agent container running E2E discovery tests can read container labels.
  • Bumps the datadog-checks-base floor to >=38.0.0 — the version that ships both the discovery runtime (Service/candidate_ports) the generated discovery.py imports, and a fix for bracketing IPv6 hosts in discovery-generated URLs.
  • Adds tests/test_discovery.py (unit coverage for the generated candidate list, API URL construction, and an explicit assertion that every candidate enables metric collection) and test_e2e_discovery / test_e2e_discovery_all_candidates (E2E coverage for the generated candidates against a real Vault container).

Known gap: HTTP only. Generated candidates use http:// exclusively; there is no auto-generated HTTPS/TLS candidate. The check already supports TLS today via manual configuration (api_url: https://... plus the existing tls_ca_cert, tls_cert, tls_verify, and related options), but discovery has no per-deployment field to supply a trusted CA bundle, and defaulting an auto-generated HTTPS candidate to tls_verify: false would be unsafe. This PR intentionally scopes discovery to HTTP listeners; users running Vault with TLS should continue to configure the integration manually.

Known gap: test_e2e_discovery exercises the no_token discovery candidate, which only ever hits Vault's unauthenticated status endpoints (/sys/health, /sys/leader, metrics scrape). 24 metrics that are only emitted once a request passes through Vault's authenticated logical-request pipeline (audit logging of the request/response, ACL/token checks, policy lookups, lease issuance) can't be produced by that candidate, so they're excluded from this test's assertions (see the exclude list and comment in tests/test_e2e.py). These metrics remain fully covered by the existing test_e2e suite, which authenticates.

Motivation

Config Discovery lets the Agent automatically detect and configure integrations from running containers, without requiring a hand-written Autodiscovery template. Vault didn't yet support this; this PR brings it in line with other integrations that have already adopted the discovery framework (krakend, n8n, ray, pulsar, temporal).

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

Adds a `discovery:` strategy block to Vault's spec.yaml targeting port
8200, with candidates covering the legacy/OpenMetrics x token/no-token
dispatch matrix in priority order (rich OpenMetrics, safe OpenMetrics,
rich legacy, safe legacy). Wires `get_e2e_discovery_metadata()` into the
E2E docker environment and adds unit and E2E coverage for the generated
candidates.

Known gap: `test_e2e_discovery`'s `no_token` candidate never
authenticates against Vault, so 24 metrics that only appear once a
request passes through Vault's authenticated logical-request pipeline
(audit logging, ACL/token checks, policy lookups, lease issuance) are
excluded from that test's assertions. These metrics remain fully
covered by the existing `test_e2e` suite.

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Aug 13, 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 (11 files):
  vault/assets/configuration/spec.yaml
  vault/changelog.d/24851.added
  vault/datadog_checks/vault/config_models/discovery.py
  vault/datadog_checks/vault/config_models/discovery_overrides.py
  vault/datadog_checks/vault/config_models/discovery_strategies.py
  vault/datadog_checks/vault/data/auto_conf.yaml
  vault/pyproject.toml
  vault/tests/conftest.py
  vault/tests/test_discovery.py
  vault/tests/test_e2e.py
  vault/tests/utils.py

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

Learn more about CI impact filtering

@datadog-prod-us1-4

datadog-prod-us1-4 Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Tests  Code Coverage

⚠️ Warnings

❄️ 1 New flaky test detected

test_ipv6_host_is_bracketed_in_generated_api_url from test_discovery.py   View in Datadog
assert False
 &#43;  where False = all(&lt;generator object test_ipv6_host_is_bracketed_in_generated_api_url.&lt;locals&gt;.&lt;genexpr&gt; at 0x7f1778364ba0&gt;)

New test introduced in this PR is flaky.

View in Flaky Test Management

ℹ️ Info

No other issues found (see more)

🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 92.59%
Overall Coverage: 95.49% (+7.00%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 68a3d5b | Docs | Datadog PR Page | Give us feedback!

@martavicentenavarro

Copy link
Copy Markdown
Contributor Author

@codex

@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: 4ef4aae0b7

ℹ️ 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".

- 8200
candidates:
- use_openmetrics: "true"
api_url: "http://{service.host}:{port.number}/v1"

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 Probe HTTPS Vault listeners as well

When a Vault listener has TLS enabled, every generated candidate uses plaintext http://, so each probe fails before it can collect the leader/health metric and discovery returns no configuration. This excludes secure production Vault deployments even though the check's api_url supports HTTPS; include HTTPS candidates or derive the listener scheme rather than only probing HTTP.

Useful? React with 👍 / 👎.

martavicentenavarro and others added 3 commits August 13, 2026 14:26
Vault's check only skips its metrics scrape when neither a token nor
`no_token` is configured (see `VaultCheckV2.metric_collection_enabled`
and the equivalent legacy-check gating), so the two `no_token: false`
candidates never attempt to collect metrics at all — they trivially
"succeed" on the always-unauthenticated `is_leader`/health output
alone. With the previous ordering (openmetrics+no_token, openmetrics,
legacy+no_token, legacy), a failed openmetrics scrape on the first
candidate would let the second, health-only candidate win immediately,
permanently starving out the third candidate even though it could
still collect the full metric set. Reorder so both `no_token: true`
candidates are tried, in either mode, before either health-only
fallback.

Flagged by Codex review on PR #24851.

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The discovery templates rely on datadog-checks-base bracketing IPv6-literal
hosts when interpolating `{service.host}` into a candidate URL. That fix
landed in datadog-checks-base 38.0.0 (37.41.0 predates it), so the
minimum-base-package CI job fails test_ipv6_host_is_bracketed_in_generated_api_url
with the previously declared 37.41.0 floor.

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The two "with token" candidates omitted `no_token` without configuring
`client_token`/`client_token_path`. `VaultCheckV2.metric_collection_enabled`
(and the equivalent legacy-check gating) skips the metrics scrape entirely in
that case, so those candidates could only ever emit the always-unauthenticated
leader/health metrics. Discovery accepts the first candidate whose check run
collects at least one metric with no error, so a health-only candidate would
trivially "succeed" and get locked in permanently -- a degraded config
masquerading as working, with no core metrics.

Discovery has no way to synthesize a token on its own, so `no_token: true` is
the only signal it can produce that guarantees a real metrics scrape. Remove
the two credential-less candidates, keeping only the OpenMetrics and legacy
`no_token: true` candidates.

Updates tests/test_discovery.py for the two-candidate expectation and adds an
explicit assertion that every generated candidate enables metric collection
(`no_token` true, since no credential is ever synthesized).

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Aug 13, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant