|
| 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.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_ports |
| 26 | + for port in candidate_ports(service, [8080]): |
| 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) |
0 commit comments