From eaac2f462d4bfee096372fb7c31c50f1cadfc0d2 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Mon, 22 Mar 2021 13:48:22 -0400 Subject: [PATCH] Sync config models --- .../vsphere/config_models/__init__.py | 18 +++ .../vsphere/config_models/defaults.py | 120 ++++++++++++++++++ .../vsphere/config_models/instance.py | 105 +++++++++++++++ .../vsphere/config_models/shared.py | 42 ++++++ .../vsphere/config_models/validators.py | 3 + 5 files changed, 288 insertions(+) create mode 100644 vsphere/datadog_checks/vsphere/config_models/__init__.py create mode 100644 vsphere/datadog_checks/vsphere/config_models/defaults.py create mode 100644 vsphere/datadog_checks/vsphere/config_models/instance.py create mode 100644 vsphere/datadog_checks/vsphere/config_models/shared.py create mode 100644 vsphere/datadog_checks/vsphere/config_models/validators.py diff --git a/vsphere/datadog_checks/vsphere/config_models/__init__.py b/vsphere/datadog_checks/vsphere/config_models/__init__.py new file mode 100644 index 0000000000000..ba42dbdc7ffb0 --- /dev/null +++ b/vsphere/datadog_checks/vsphere/config_models/__init__.py @@ -0,0 +1,18 @@ +# (C) Datadog, Inc. 2021-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) +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/vsphere/datadog_checks/vsphere/config_models/defaults.py b/vsphere/datadog_checks/vsphere/config_models/defaults.py new file mode 100644 index 0000000000000..78130cacd16ff --- /dev/null +++ b/vsphere/datadog_checks/vsphere/config_models/defaults.py @@ -0,0 +1,120 @@ +# (C) Datadog, Inc. 2021-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) +from datadog_checks.base.utils.models.fields import get_default_field_value + + +def shared_service(field, value): + return get_default_field_value(field, value) + + +def instance_attributes_prefix(field, value): + return '' + + +def instance_batch_property_collector_size(field, value): + return 500 + + +def instance_batch_tags_collector_size(field, value): + return 200 + + +def instance_collect_attributes(field, value): + return False + + +def instance_collect_events(field, value): + return True + + +def instance_collect_events_only(field, value): + return False + + +def instance_collect_per_instance_filters(field, value): + return get_default_field_value(field, value) + + +def instance_collect_tags(field, value): + return False + + +def instance_collection_level(field, value): + return 1 + + +def instance_collection_type(field, value): + return 'realtime' + + +def instance_excluded_host_tags(field, value): + return get_default_field_value(field, value) + + +def instance_include_datastore_cluster_folder_tag(field, value): + return True + + +def instance_max_historical_metrics(field, value): + return 256 + + +def instance_metric_filters(field, value): + return get_default_field_value(field, value) + + +def instance_metrics_per_query(field, value): + return 50 + + +def instance_min_collection_interval(field, value): + return 15 + + +def instance_refresh_infrastructure_cache_interval(field, value): + return 300 + + +def instance_refresh_metrics_metadata_cache_interval(field, value): + return 1800 + + +def instance_resource_filters(field, value): + return get_default_field_value(field, value) + + +def instance_service(field, value): + return get_default_field_value(field, value) + + +def instance_ssl_capath(field, value): + return get_default_field_value(field, value) + + +def instance_ssl_verify(field, value): + return True + + +def instance_tags(field, value): + return get_default_field_value(field, value) + + +def instance_tags_prefix(field, value): + return '' + + +def instance_threads_count(field, value): + return 4 + + +def instance_tls_ignore_warning(field, value): + return False + + +def instance_use_collect_events_fallback(field, value): + return False + + +def instance_use_guest_hostname(field, value): + return False diff --git a/vsphere/datadog_checks/vsphere/config_models/instance.py b/vsphere/datadog_checks/vsphere/config_models/instance.py new file mode 100644 index 0000000000000..aa3901aa99de8 --- /dev/null +++ b/vsphere/datadog_checks/vsphere/config_models/instance.py @@ -0,0 +1,105 @@ +# (C) Datadog, Inc. 2021-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) +from __future__ import annotations + +from typing import Optional, Sequence + +from pydantic import BaseModel, root_validator, validator + +from datadog_checks.base.utils.functions import identity +from datadog_checks.base.utils.models import validation + +from . import defaults, validators + + +class CollectPerInstanceFilters(BaseModel): + class Config: + allow_mutation = False + + cluster: Optional[Sequence[str]] + datastore: Optional[Sequence[str]] + host: Optional[Sequence[str]] + vm: Optional[Sequence[str]] + + +class MetricFilters(BaseModel): + class Config: + allow_mutation = False + + cluster: Optional[Sequence[str]] + datacenter: Optional[Sequence[str]] + datastore: Optional[Sequence[str]] + host: Optional[Sequence[str]] + vm: Optional[Sequence[str]] + + +class ResourceFilter(BaseModel): + class Config: + allow_mutation = False + + patterns: Optional[Sequence[str]] + property: Optional[str] + resource: Optional[str] + type: Optional[str] + + +class InstanceConfig(BaseModel): + class Config: + allow_mutation = False + + attributes_prefix: Optional[str] + batch_property_collector_size: Optional[int] + batch_tags_collector_size: Optional[int] + collect_attributes: Optional[bool] + collect_events: Optional[bool] + collect_events_only: Optional[bool] + collect_per_instance_filters: Optional[CollectPerInstanceFilters] + collect_tags: Optional[bool] + collection_level: Optional[int] + collection_type: Optional[str] + empty_default_hostname: bool + excluded_host_tags: Optional[Sequence[str]] + host: str + include_datastore_cluster_folder_tag: Optional[bool] + max_historical_metrics: Optional[int] + metric_filters: Optional[MetricFilters] + metrics_per_query: Optional[int] + min_collection_interval: Optional[float] + password: str + refresh_infrastructure_cache_interval: Optional[int] + refresh_metrics_metadata_cache_interval: Optional[int] + resource_filters: Optional[Sequence[ResourceFilter]] + service: Optional[str] + ssl_capath: Optional[str] + ssl_verify: Optional[bool] + tags: Optional[Sequence[str]] + tags_prefix: Optional[str] + threads_count: Optional[int] + tls_ignore_warning: Optional[bool] + use_collect_events_fallback: Optional[bool] + use_guest_hostname: Optional[bool] + use_legacy_check_version: bool + username: str + + @root_validator(pre=True) + def _initial_validation(cls, values): + return validation.core.initialize_config(getattr(validators, 'initialize_instance', identity)(values)) + + @validator('*', pre=True, always=True) + def _ensure_defaults(cls, v, field): + if v is not None or field.required: + return v + + return getattr(defaults, f'instance_{field.name}')(field, v) + + @validator('*') + def _run_validations(cls, v, field): + if not v: + return v + + return getattr(validators, f'instance_{field.name}', identity)(v, field=field) + + @root_validator(pre=False) + def _final_validation(cls, values): + return validation.core.finalize_config(getattr(validators, 'finalize_instance', identity)(values)) diff --git a/vsphere/datadog_checks/vsphere/config_models/shared.py b/vsphere/datadog_checks/vsphere/config_models/shared.py new file mode 100644 index 0000000000000..d1c10eced36ca --- /dev/null +++ b/vsphere/datadog_checks/vsphere/config_models/shared.py @@ -0,0 +1,42 @@ +# (C) Datadog, Inc. 2021-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) +from __future__ import annotations + +from typing import Optional + +from pydantic import BaseModel, root_validator, validator + +from datadog_checks.base.utils.functions import identity +from datadog_checks.base.utils.models import validation + +from . import defaults, validators + + +class SharedConfig(BaseModel): + class Config: + allow_mutation = False + + service: Optional[str] + + @root_validator(pre=True) + def _initial_validation(cls, values): + return validation.core.initialize_config(getattr(validators, 'initialize_shared', identity)(values)) + + @validator('*', pre=True, always=True) + def _ensure_defaults(cls, v, field): + if v is not None or field.required: + return v + + return getattr(defaults, f'shared_{field.name}')(field, v) + + @validator('*') + def _run_validations(cls, v, field): + if not v: + return v + + return getattr(validators, f'shared_{field.name}', identity)(v, field=field) + + @root_validator(pre=False) + def _final_validation(cls, values): + return validation.core.finalize_config(getattr(validators, 'finalize_shared', identity)(values)) diff --git a/vsphere/datadog_checks/vsphere/config_models/validators.py b/vsphere/datadog_checks/vsphere/config_models/validators.py new file mode 100644 index 0000000000000..9d0b0155542cb --- /dev/null +++ b/vsphere/datadog_checks/vsphere/config_models/validators.py @@ -0,0 +1,3 @@ +# (C) Datadog, Inc. 2021-present +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE)