From 26e3e074e36224b3733d92fc178621660b8c3620 Mon Sep 17 00:00:00 2001 From: Florent Clarret Date: Wed, 29 Nov 2023 08:52:20 +0100 Subject: [PATCH] Add missing config_models files and update the base check version --- kubernetes_state/changelog.d/16298.changed | 1 + .../config_models/__init__.py | 24 +++ .../config_models/defaults.py | 132 ++++++++++++++ .../config_models/instance.py | 168 ++++++++++++++++++ .../kubernetes_state/config_models/shared.py | 60 +++++++ .../config_models/validators.py | 13 ++ kubernetes_state/pyproject.toml | 2 +- 7 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 kubernetes_state/changelog.d/16298.changed create mode 100644 kubernetes_state/datadog_checks/kubernetes_state/config_models/__init__.py create mode 100644 kubernetes_state/datadog_checks/kubernetes_state/config_models/defaults.py create mode 100644 kubernetes_state/datadog_checks/kubernetes_state/config_models/instance.py create mode 100644 kubernetes_state/datadog_checks/kubernetes_state/config_models/shared.py create mode 100644 kubernetes_state/datadog_checks/kubernetes_state/config_models/validators.py diff --git a/kubernetes_state/changelog.d/16298.changed b/kubernetes_state/changelog.d/16298.changed new file mode 100644 index 0000000000000..a6909e1902dca --- /dev/null +++ b/kubernetes_state/changelog.d/16298.changed @@ -0,0 +1 @@ +Add missing config_models files and update the base check version diff --git a/kubernetes_state/datadog_checks/kubernetes_state/config_models/__init__.py b/kubernetes_state/datadog_checks/kubernetes_state/config_models/__init__.py new file mode 100644 index 0000000000000..bb07629c89aca --- /dev/null +++ b/kubernetes_state/datadog_checks/kubernetes_state/config_models/__init__.py @@ -0,0 +1,24 @@ +# (C) Datadog, Inc. 2023-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) + +# This file is autogenerated. +# To change this file you should edit assets/configuration/spec.yaml and then run the following commands: +# ddev -x validate config -s +# ddev -x validate models -s + +from .instance import InstanceConfig +from .shared import SharedConfig + + +class ConfigMixin: + _config_model_instance: InstanceConfig + _config_model_shared: SharedConfig + + @property + def config(self) -> InstanceConfig: + return self._config_model_instance + + @property + def shared_config(self) -> SharedConfig: + return self._config_model_shared diff --git a/kubernetes_state/datadog_checks/kubernetes_state/config_models/defaults.py b/kubernetes_state/datadog_checks/kubernetes_state/config_models/defaults.py new file mode 100644 index 0000000000000..afbeca7f5f727 --- /dev/null +++ b/kubernetes_state/datadog_checks/kubernetes_state/config_models/defaults.py @@ -0,0 +1,132 @@ +# (C) Datadog, Inc. 2023-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) + +# This file is autogenerated. +# To change this file you should edit assets/configuration/spec.yaml and then run the following commands: +# ddev -x validate config -s +# ddev -x validate models -s + + +def shared_skip_proxy(): + return False + + +def shared_timeout(): + return 10 + + +def instance_allow_redirects(): + return True + + +def instance_auth_type(): + return 'basic' + + +def instance_bearer_token_refresh_interval(): + return 60 + + +def instance_disable_generic_tags(): + return False + + +def instance_empty_default_hostname(): + return False + + +def instance_health_service_check(): + return True + + +def instance_hostname_override(): + return True + + +def instance_join_standard_tags(): + return False + + +def instance_kerberos_auth(): + return 'disabled' + + +def instance_kerberos_delegate(): + return False + + +def instance_kerberos_force_initiate(): + return False + + +def instance_log_requests(): + return False + + +def instance_min_collection_interval(): + return 15 + + +def instance_namespace(): + return 'service' + + +def instance_persist_connections(): + return False + + +def instance_request_size(): + return 10 + + +def instance_send_distribution_buckets(): + return False + + +def instance_send_distribution_counts_as_monotonic(): + return False + + +def instance_send_distribution_sums_as_monotonic(): + return False + + +def instance_send_histograms_buckets(): + return True + + +def instance_send_monotonic_counter(): + return True + + +def instance_send_monotonic_with_gauge(): + return False + + +def instance_skip_proxy(): + return False + + +def instance_timeout(): + return 10 + + +def instance_tls_ignore_warning(): + return False + + +def instance_tls_use_host_header(): + return False + + +def instance_tls_verify(): + return True + + +def instance_use_legacy_auth_encoding(): + return True + + +def instance_use_process_start_time(): + return False diff --git a/kubernetes_state/datadog_checks/kubernetes_state/config_models/instance.py b/kubernetes_state/datadog_checks/kubernetes_state/config_models/instance.py new file mode 100644 index 0000000000000..94193670f3fb3 --- /dev/null +++ b/kubernetes_state/datadog_checks/kubernetes_state/config_models/instance.py @@ -0,0 +1,168 @@ +# (C) Datadog, Inc. 2023-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) + +# This file is autogenerated. +# To change this file you should edit assets/configuration/spec.yaml and then run the following commands: +# ddev -x validate config -s +# ddev -x validate models -s + +from __future__ import annotations + +from types import MappingProxyType +from typing import Any, Optional, Union + +from pydantic import BaseModel, ConfigDict, field_validator, model_validator + +from datadog_checks.base.utils.functions import identity +from datadog_checks.base.utils.models import validation + +from . import defaults, validators + + +class AuthToken(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + reader: Optional[MappingProxyType[str, Any]] = None + writer: Optional[MappingProxyType[str, Any]] = None + + +class IgnoreMetricsByLabels(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + target_label_key: Optional[str] = None + target_label_value_list: Optional[tuple[str, ...]] = None + + +class TargetMetric(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + label_to_match: Optional[str] = None + labels_to_get: Optional[tuple[str, ...]] = None + + +class LabelJoins(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + target_metric: Optional[TargetMetric] = None + + +class MetricPatterns(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + exclude: Optional[tuple[str, ...]] = None + include: Optional[tuple[str, ...]] = None + + +class Proxy(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + http: Optional[str] = None + https: Optional[str] = None + no_proxy: Optional[tuple[str, ...]] = None + + +class InstanceConfig(BaseModel): + model_config = ConfigDict( + validate_default=True, + arbitrary_types_allowed=True, + frozen=True, + ) + allow_redirects: Optional[bool] = None + auth_token: Optional[AuthToken] = None + auth_type: Optional[str] = None + aws_host: Optional[str] = None + aws_region: Optional[str] = None + aws_service: Optional[str] = None + bearer_token_auth: Optional[Union[bool, str]] = None + bearer_token_path: Optional[str] = None + bearer_token_refresh_interval: Optional[int] = None + connect_timeout: Optional[float] = None + disable_generic_tags: Optional[bool] = None + empty_default_hostname: Optional[bool] = None + exclude_labels: Optional[tuple[str, ...]] = None + extra_headers: Optional[MappingProxyType[str, Any]] = None + headers: Optional[MappingProxyType[str, Any]] = None + health_service_check: Optional[bool] = None + hostname_override: Optional[bool] = None + ignore_metrics: Optional[tuple[str, ...]] = None + ignore_metrics_by_labels: Optional[IgnoreMetricsByLabels] = None + ignore_tags: Optional[tuple[str, ...]] = None + include_labels: Optional[tuple[str, ...]] = None + join_standard_tags: Optional[bool] = None + kerberos_auth: Optional[str] = None + kerberos_cache: Optional[str] = None + kerberos_delegate: Optional[bool] = None + kerberos_force_initiate: Optional[bool] = None + kerberos_hostname: Optional[str] = None + kerberos_keytab: Optional[str] = None + kerberos_principal: Optional[str] = None + kube_state_url: str + label_joins: Optional[LabelJoins] = None + label_to_hostname: Optional[str] = None + labels_mapper: Optional[MappingProxyType[str, Any]] = None + log_requests: Optional[bool] = None + metric_patterns: Optional[MetricPatterns] = None + metrics: Optional[tuple[Union[str, MappingProxyType[str, str]], ...]] = None + min_collection_interval: Optional[float] = None + namespace: Optional[str] = None + ntlm_domain: Optional[str] = None + password: Optional[str] = None + persist_connections: Optional[bool] = None + prometheus_metrics_prefix: Optional[str] = None + prometheus_url: Optional[str] = None + proxy: Optional[Proxy] = None + read_timeout: Optional[float] = None + request_size: Optional[float] = None + send_distribution_buckets: Optional[bool] = None + send_distribution_counts_as_monotonic: Optional[bool] = None + send_distribution_sums_as_monotonic: Optional[bool] = None + send_histograms_buckets: Optional[bool] = None + send_monotonic_counter: Optional[bool] = None + send_monotonic_with_gauge: Optional[bool] = None + service: Optional[str] = None + skip_proxy: Optional[bool] = None + tags: Optional[tuple[str, ...]] = None + timeout: Optional[float] = None + tls_ca_cert: Optional[str] = None + tls_cert: Optional[str] = None + tls_ignore_warning: Optional[bool] = None + tls_private_key: Optional[str] = None + tls_protocols_allowed: Optional[tuple[str, ...]] = None + tls_use_host_header: Optional[bool] = None + tls_verify: Optional[bool] = None + type_overrides: Optional[MappingProxyType[str, Any]] = None + use_legacy_auth_encoding: Optional[bool] = None + use_process_start_time: Optional[bool] = None + username: Optional[str] = None + + @model_validator(mode='before') + def _initial_validation(cls, values): + return validation.core.initialize_config(getattr(validators, 'initialize_instance', identity)(values)) + + @field_validator('*', mode='before') + def _validate(cls, value, info): + field = cls.model_fields[info.field_name] + field_name = field.alias or info.field_name + if field_name in info.context['configured_fields']: + value = getattr(validators, f'instance_{info.field_name}', identity)(value, field=field) + else: + value = getattr(defaults, f'instance_{info.field_name}', lambda: value)() + + return validation.utils.make_immutable(value) + + @model_validator(mode='after') + def _final_validation(cls, model): + return validation.core.check_model(getattr(validators, 'check_instance', identity)(model)) diff --git a/kubernetes_state/datadog_checks/kubernetes_state/config_models/shared.py b/kubernetes_state/datadog_checks/kubernetes_state/config_models/shared.py new file mode 100644 index 0000000000000..458a7003d92bb --- /dev/null +++ b/kubernetes_state/datadog_checks/kubernetes_state/config_models/shared.py @@ -0,0 +1,60 @@ +# (C) Datadog, Inc. 2023-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) + +# This file is autogenerated. +# To change this file you should edit assets/configuration/spec.yaml and then run the following commands: +# ddev -x validate config -s +# ddev -x validate models -s + +from __future__ import annotations + +from typing import Optional + +from pydantic import BaseModel, ConfigDict, field_validator, model_validator + +from datadog_checks.base.utils.functions import identity +from datadog_checks.base.utils.models import validation + +from . import defaults, validators + + +class Proxy(BaseModel): + model_config = ConfigDict( + arbitrary_types_allowed=True, + frozen=True, + ) + http: Optional[str] = None + https: Optional[str] = None + no_proxy: Optional[tuple[str, ...]] = None + + +class SharedConfig(BaseModel): + model_config = ConfigDict( + validate_default=True, + arbitrary_types_allowed=True, + frozen=True, + ) + proxy: Optional[Proxy] = None + service: Optional[str] = None + skip_proxy: Optional[bool] = None + timeout: Optional[float] = None + + @model_validator(mode='before') + def _initial_validation(cls, values): + return validation.core.initialize_config(getattr(validators, 'initialize_shared', identity)(values)) + + @field_validator('*', mode='before') + def _validate(cls, value, info): + field = cls.model_fields[info.field_name] + 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) + + @model_validator(mode='after') + def _final_validation(cls, model): + return validation.core.check_model(getattr(validators, 'check_shared', identity)(model)) diff --git a/kubernetes_state/datadog_checks/kubernetes_state/config_models/validators.py b/kubernetes_state/datadog_checks/kubernetes_state/config_models/validators.py new file mode 100644 index 0000000000000..b799bc7cf3264 --- /dev/null +++ b/kubernetes_state/datadog_checks/kubernetes_state/config_models/validators.py @@ -0,0 +1,13 @@ +# (C) Datadog, Inc. 2023-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 diff --git a/kubernetes_state/pyproject.toml b/kubernetes_state/pyproject.toml index 7758fc120624d..f360fab83c786 100644 --- a/kubernetes_state/pyproject.toml +++ b/kubernetes_state/pyproject.toml @@ -30,7 +30,7 @@ classifiers = [ "Private :: Do Not Upload", ] dependencies = [ - "datadog-checks-base>=25.1.0", + "datadog-checks-base>=32.6.0", ] dynamic = [ "version",