diff --git a/spinnaker/datadog_checks/spinnaker/config_models/__init__.py b/spinnaker/datadog_checks/spinnaker/config_models/__init__.py index 2e7eff5e94dd7..106fff2032f68 100644 --- a/spinnaker/datadog_checks/spinnaker/config_models/__init__.py +++ b/spinnaker/datadog_checks/spinnaker/config_models/__init__.py @@ -7,7 +7,6 @@ # ddev -x validate config -s # ddev -x validate models -s - from .instance import InstanceConfig from .shared import SharedConfig diff --git a/spinnaker/datadog_checks/spinnaker/config_models/defaults.py b/spinnaker/datadog_checks/spinnaker/config_models/defaults.py index 7adf7c7b7abd3..4d46152df5d40 100644 --- a/spinnaker/datadog_checks/spinnaker/config_models/defaults.py +++ b/spinnaker/datadog_checks/spinnaker/config_models/defaults.py @@ -8,6 +8,10 @@ # ddev -x validate models -s +def instance_disable_generic_tags(): + return False + + def instance_empty_default_hostname(): return False diff --git a/spinnaker/datadog_checks/spinnaker/config_models/instance.py b/spinnaker/datadog_checks/spinnaker/config_models/instance.py index b2d32d2e62ea8..56acae21ba432 100644 --- a/spinnaker/datadog_checks/spinnaker/config_models/instance.py +++ b/spinnaker/datadog_checks/spinnaker/config_models/instance.py @@ -7,7 +7,6 @@ # ddev -x validate config -s # ddev -x validate models -s - from __future__ import annotations from typing import Optional @@ -20,13 +19,24 @@ from . import defaults, validators +class MetricPatterns(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + exclude: Optional[tuple[str, ...]] = None + include: Optional[tuple[str, ...]] = None + + class InstanceConfig(BaseModel): model_config = ConfigDict( validate_default=True, arbitrary_types_allowed=True, frozen=True, ) + disable_generic_tags: Optional[bool] = None empty_default_hostname: Optional[bool] = None + metric_patterns: Optional[MetricPatterns] = None min_collection_interval: Optional[float] = None service: Optional[str] = None tags: Optional[tuple[str, ...]] = None diff --git a/spinnaker/datadog_checks/spinnaker/config_models/shared.py b/spinnaker/datadog_checks/spinnaker/config_models/shared.py index 656c417aa3849..e39d447dfc4b9 100644 --- a/spinnaker/datadog_checks/spinnaker/config_models/shared.py +++ b/spinnaker/datadog_checks/spinnaker/config_models/shared.py @@ -7,7 +7,6 @@ # ddev -x validate config -s # ddev -x validate models -s - from __future__ import annotations from typing import Optional @@ -17,7 +16,7 @@ from datadog_checks.base.utils.functions import identity from datadog_checks.base.utils.models import validation -from . import defaults, validators +from . import validators class SharedConfig(BaseModel): @@ -38,8 +37,6 @@ def _validate(cls, value, info): field_name = field.alias or info.field_name if field_name in info.context['configured_fields']: value = getattr(validators, f'shared_{info.field_name}', identity)(value, field=field) - else: - value = getattr(defaults, f'shared_{info.field_name}', lambda: value)() return validation.utils.make_immutable(value) diff --git a/spinnaker/datadog_checks/spinnaker/config_models/validators.py b/spinnaker/datadog_checks/spinnaker/config_models/validators.py index 9103122bf028d..70150e85e6124 100644 --- a/spinnaker/datadog_checks/spinnaker/config_models/validators.py +++ b/spinnaker/datadog_checks/spinnaker/config_models/validators.py @@ -1,3 +1,13 @@ # (C) Datadog, Inc. 2024-present # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) + +# Here you can include additional config validators or transformers +# +# def initialize_instance(values, **kwargs): +# if 'my_option' not in values and 'my_legacy_option' in values: +# values['my_option'] = values['my_legacy_option'] +# if values.get('my_number') > 10: +# raise ValueError('my_number max value is 10, got %s' % str(values.get('my_number'))) +# +# return values