Skip to content

Commit aa98fc9

Browse files
vitkyrkaclaude
andcommitted
argo_rollouts: add container-based config discovery support
Add a discovery strategy and auto_conf.yaml for the argo-rollouts controller Deployment so the Agent's Kubernetes Autodiscovery listener can automatically generate an openmetrics_endpoint configuration for it, and wire the kind-based E2E test harness up to the new Kubernetes discovery e2e helpers (setup_discovery_agent/save_kube_discovery_state/run_discovery_check_kubernetes/ assert_all_discovery_candidates_stable_kubernetes). Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent ac0dd17 commit aa98fc9

9 files changed

Lines changed: 136 additions & 2 deletions

File tree

argo_rollouts/assets/configuration/spec.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ name: Argo Rollouts
22
fleet_configurable: true
33
files:
44
- name: argo_rollouts.yaml
5+
discovery:
6+
strategies:
7+
- template: discovery/openmetrics_from_ports
8+
overrides:
9+
port_hints:
10+
- 8090
511
options:
612
- template: init_config
713
options:
@@ -13,4 +19,11 @@ files:
1319
openmetrics_endpoint.value.example: http://localhost:8090/metrics
1420
openmetrics_endpoint.description: |
1521
Endpoint exposing the Argo Rollouts Controller's Prometheus metrics. For more information refer to:
16-
https://argo-rollouts.readthedocs.io/en/stable/features/controller-metrics/
22+
https://argo-rollouts.readthedocs.io/en/stable/features/controller-metrics/
23+
- name: auto_conf.yaml
24+
options:
25+
- template: ad_identifiers
26+
overrides:
27+
value.example:
28+
- argo-rollouts
29+
- template: auto_conf/discovery
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.argo_rollouts.config_models import discovery_overrides
16+
from datadog_checks.argo_rollouts.config_models.instance import InstanceConfig
17+
from datadog_checks.argo_rollouts.config_models.shared import SharedConfig
18+
from datadog_checks.base.utils.discovery import Service, candidate_ports
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, [8090]):
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+
- argo-rollouts
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: []

argo_rollouts/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
"Topic :: System :: Monitoring",
3030
]
3131
dependencies = [
32-
"datadog-checks-base>=37.33.0",
32+
"datadog-checks-base>=37.41.0",
3333
]
3434
dynamic = [
3535
"version",

argo_rollouts/tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from datadog_checks.dev import get_here
1010
from datadog_checks.dev.kind import kind_run
11+
from datadog_checks.dev.kube_discovery import save_kube_discovery_state, setup_discovery_agent
1112
from datadog_checks.dev.kube_port_forward import port_forward
1213
from datadog_checks.dev.subprocess import run_command
1314

@@ -28,6 +29,8 @@ def setup_argo_rollouts():
2829
@pytest.fixture(scope='session')
2930
def dd_environment():
3031
with kind_run(conditions=[setup_argo_rollouts], sleep=30) as kubeconfig, ExitStack() as stack:
32+
setup_discovery_agent(kubeconfig)
33+
save_kube_discovery_state(kubeconfig)
3134
argo_rollouts_host, argo_rollouts_port = stack.enter_context(
3235
port_forward(kubeconfig, 'argo-rollouts', 8090, 'deployment', 'argo-rollouts')
3336
)

argo_rollouts/tests/test_e2e.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# (C) Datadog, Inc. 2024-present
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
import pytest
5+
6+
from datadog_checks.argo_rollouts import ArgoRolloutsCheck
47
from datadog_checks.base.constants import ServiceCheck
8+
from datadog_checks.dev.kube_discovery import (
9+
assert_all_discovery_candidates_stable_kubernetes,
10+
run_discovery_check_kubernetes,
11+
)
512
from datadog_checks.dev.utils import assert_service_checks
613

714

@@ -10,3 +17,22 @@ def test_e2e_openmetrics_v2(dd_agent_check):
1017

1118
aggregator.assert_service_check('argo_rollouts.openmetrics.health', ServiceCheck.OK, count=1)
1219
assert_service_checks(aggregator)
20+
21+
22+
@pytest.mark.e2e
23+
def test_e2e_discovery(aggregator, datadog_agent):
24+
run_discovery_check_kubernetes(aggregator, datadog_agent)
25+
26+
aggregator.assert_service_check('argo_rollouts.openmetrics.health', ServiceCheck.OK, count=1)
27+
assert_service_checks(aggregator)
28+
29+
30+
@pytest.mark.e2e
31+
def test_e2e_discovery_all_candidates(aggregator, datadog_agent):
32+
assert_all_discovery_candidates_stable_kubernetes(
33+
ArgoRolloutsCheck,
34+
aggregator,
35+
datadog_agent,
36+
namespace='argo-rollouts',
37+
pod_selector='app.kubernetes.io/name=argo-rollouts',
38+
)

0 commit comments

Comments
 (0)