Skip to content

Commit cadfc25

Browse files
vitkyrkaclaude
andcommitted
velero: add container-based config discovery support
Adds a discovery: strategy to spec.yaml (from_ports on port 8085, the metrics port shared by the velero server and node-agent components), the generated auto_conf.yaml/discovery config models, and Kubernetes-native discovery E2E tests using the new kube_discovery helpers. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 12fbb16 commit cadfc25

11 files changed

Lines changed: 1099 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``kube_discovery`` e2e test helpers for exercising Kubernetes/Kubelet Autodiscovery.

datadog_checks_dev/datadog_checks/dev/kube_discovery.py

Lines changed: 558 additions & 0 deletions
Large diffs are not rendered by default.

datadog_checks_dev/tests/test_kube_discovery.py

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

velero/assets/configuration/spec.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Velero
22
fleet_configurable: true
33
files:
44
- name: velero.yaml
5+
discovery:
6+
strategies:
7+
- template: discovery/openmetrics_from_ports
8+
overrides:
9+
port_hints:
10+
- 8085
511
options:
612
- template: init_config
713
options:
@@ -14,3 +20,10 @@ files:
1420
- type: docker
1521
source: velero
1622
service: <SERVICE>
23+
- name: auto_conf.yaml
24+
options:
25+
- template: ad_identifiers
26+
overrides:
27+
value.example:
28+
- velero
29+
- template: auto_conf/discovery

velero/changelog.d/24507.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add container-based config discovery support.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# (C) Datadog, Inc. 2026-present
2+
# All rights reserved
3+
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
5+
# This file is autogenerated.
6+
# To change this file you should edit assets/configuration/spec.yaml and then run the following commands:
7+
# ddev -x validate config -s <INTEGRATION_NAME>
8+
# ddev -x validate models -s <INTEGRATION_NAME>
9+
10+
from __future__ import annotations
11+
12+
from collections.abc import Iterator
13+
from typing import Any
14+
15+
from datadog_checks.base.utils.discovery import Service, candidate_ports
16+
from datadog_checks.velero.config_models import discovery_overrides
17+
from datadog_checks.velero.config_models.instance import InstanceConfig
18+
from datadog_checks.velero.config_models.shared import SharedConfig
19+
20+
21+
def _generated_candidates(service: Service) -> Iterator[dict[str, Any]]:
22+
shared = SharedConfig.model_validate({}, context={'configured_fields': frozenset()}).model_dump(
23+
by_alias=True, mode='json', exclude_none=True
24+
)
25+
# discovery[0]: from_ports
26+
for port in candidate_ports(service, [8085]):
27+
ctx = {'port': port}
28+
instance_data = {
29+
'openmetrics_endpoint': 'http://{service.host}:{port.number}/metrics'.format(service=service, **ctx),
30+
}
31+
instance = InstanceConfig.model_validate(
32+
instance_data, context={'configured_fields': frozenset(instance_data)}
33+
).model_dump(by_alias=True, mode='json', exclude_none=True)
34+
yield {'init_config': shared, 'instances': [instance]}
35+
36+
37+
def candidates(service: Service) -> Iterator[dict[str, Any]]:
38+
override = getattr(discovery_overrides, 'candidates', None)
39+
if override is None:
40+
yield from _generated_candidates(service)
41+
else:
42+
yield from override(service, default=_generated_candidates)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# (C) Datadog, Inc. 2026-present
2+
# All rights reserved
3+
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
5+
# Override the generated discovery candidates() for this integration.
6+
#
7+
# Define a candidates(service, default) function to wrap or replace the generated
8+
# candidate generation. `default` is the generated generator; call it to reuse
9+
# the spec-driven candidates, or ignore it to replace them entirely.
10+
#
11+
# def candidates(service, default):
12+
# yield from default(service)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# (C) Datadog, Inc. 2026-present
2+
# All rights reserved
3+
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
5+
# Here you can define custom (local:) discovery strategies for this integration.
6+
#
7+
# Decorate a generator with @discovery_strategy (imported from
8+
# datadog_checks.base.utils.discovery) and reference it from the spec discovery
9+
# stanza as `strategy: local:<function_name>`. The function receives the
10+
# discovered Service plus the inputs declared in the spec and yields one context
11+
# (ctx) mapping per candidate, exposing the keys listed in `provides`.
12+
#
13+
# from datadog_checks.base.utils.discovery import discovery_strategy
14+
#
15+
# @discovery_strategy(provides=('svc',))
16+
# def from_some_config(service, config_path):
17+
# ...
18+
# yield {'svc': ...}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## @param ad_identifiers - list of strings - required
2+
## A list of container identifiers that are used by Autodiscovery to identify
3+
## which container the check should be run against. For more information, see:
4+
## https://docs.datadoghq.com/agent/guide/ad_identifiers/
5+
#
6+
ad_identifiers:
7+
- velero
8+
9+
## Enables configuration discovery
10+
#
11+
discovery: {}
12+
13+
## Unused init configuration
14+
#
15+
init_config:
16+
17+
## Unused instance configuration
18+
#
19+
instances: []

velero/tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from datadog_checks.dev import TempDir, run_command
1010
from datadog_checks.dev.fs import path_join
1111
from datadog_checks.dev.kind import KindLoad, kind_run
12+
from datadog_checks.dev.kube_discovery import save_kube_discovery_state, setup_discovery_agent
1213
from datadog_checks.dev.kube_port_forward import port_forward
1314

1415
from .common import MOCKED_INSTANCE, PORT
@@ -88,6 +89,9 @@ def dd_environment():
8889
"HELM_CONFIG_HOME": path_join(helm_dir, 'Preferences'),
8990
},
9091
) as kubeconfig:
92+
setup_discovery_agent(kubeconfig)
93+
save_kube_discovery_state(kubeconfig)
94+
9195
with ExitStack() as stack:
9296
ip_ports = [
9397
stack.enter_context(port_forward(kubeconfig, 'velero', PORT, ressource, name))

0 commit comments

Comments
 (0)