Skip to content

Commit d43155c

Browse files
vitkyrkaclaude
andcommitted
keda: add container-based config discovery support
Add a discovery strategy and auto_conf.yaml for the keda-operator-metrics-apiserver component so the Agent's Kubernetes Autodiscovery listener can automatically generate an openmetrics_endpoint configuration for it. Reuses the Kubernetes discovery e2e test helpers added in the velero-discovery branch instead of duplicating them. Environment: Datadog workspace Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent e183434 commit d43155c

12 files changed

Lines changed: 146 additions & 5 deletions

File tree

keda/assets/configuration/spec.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Keda
22
fleet_configurable: true
33
files:
44
- name: keda.yaml
5+
discovery:
6+
strategies:
7+
- template: discovery/openmetrics_from_named_ports
58
options:
69
- template: init_config
710
options:
@@ -13,4 +16,13 @@ files:
1316
openmetrics_endpoint.value.example: http://localhost:8080/metrics
1417
openmetrics_endpoint.description: |
1518
Endpoint exposing the Keda's Prometheus metrics. For more information refer to:
16-
https://keda.sh/docs/2.16/integrations/prometheus/
19+
https://keda.sh/docs/2.16/integrations/prometheus/
20+
- name: auto_conf.yaml
21+
options:
22+
- template: ad_identifiers
23+
overrides:
24+
value.example:
25+
- keda
26+
- keda-admission-webhooks
27+
- keda-metrics-apiserver
28+
- template: auto_conf/discovery

keda/changelog.d/24459.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.

keda/datadog_checks/keda/config_models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Datadog, Inc. 2024-present
1+
# (C) Datadog, Inc. 2026-present
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

keda/datadog_checks/keda/config_models/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Datadog, Inc. 2024-present
1+
# (C) Datadog, Inc. 2026-present
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

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_by_name
16+
from datadog_checks.keda.config_models import discovery_overrides
17+
from datadog_checks.keda.config_models.instance import InstanceConfig
18+
from datadog_checks.keda.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_named_ports
26+
for port in candidate_ports_by_name(service, ['metrics']):
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': ...}

keda/datadog_checks/keda/config_models/instance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Datadog, Inc. 2024-present
1+
# (C) Datadog, Inc. 2026-present
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

keda/datadog_checks/keda/config_models/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# (C) Datadog, Inc. 2024-present
1+
# (C) Datadog, Inc. 2026-present
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
- keda
8+
- keda-admission-webhooks
9+
- keda-metrics-apiserver
10+
11+
## Enables configuration discovery
12+
#
13+
discovery: {}
14+
15+
## Unused init configuration
16+
#
17+
init_config:
18+
19+
## Unused instance configuration
20+
#
21+
instances: []

0 commit comments

Comments
 (0)