-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
3,386 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
datadog_checks_base/datadog_checks/base/utils/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) |
17 changes: 17 additions & 0 deletions
17
datadog_checks_base/datadog_checks/base/utils/models/fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from pydantic.fields import SHAPE_MAPPING, SHAPE_SEQUENCE, SHAPE_SINGLETON | ||
|
||
|
||
def get_default_field_value(field, value): | ||
if field.shape == SHAPE_MAPPING: | ||
return {} | ||
elif field.shape == SHAPE_SEQUENCE: | ||
return [] | ||
elif field.shape == SHAPE_SINGLETON: | ||
field_type = field.type_ | ||
if field_type in (float, int, str): | ||
return field_type() | ||
|
||
return value |
16 changes: 16 additions & 0 deletions
16
datadog_checks_base/datadog_checks/base/utils/models/types.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from collections.abc import Mapping, Sequence | ||
|
||
from immutables import Map | ||
|
||
|
||
def make_immutable_check_config(obj): | ||
if isinstance(obj, Sequence) and not isinstance(obj, str): | ||
return tuple(make_immutable_check_config(item) for item in obj) | ||
elif isinstance(obj, Mapping): | ||
# There are no ordering guarantees, see https://github.com/MagicStack/immutables/issues/57 | ||
return Map((k, make_immutable_check_config(v)) for k, v in obj.items()) | ||
|
||
return obj |
4 changes: 4 additions & 0 deletions
4
datadog_checks_base/datadog_checks/base/utils/models/validation/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from . import core, utils |
17 changes: 17 additions & 0 deletions
17
datadog_checks_base/datadog_checks/base/utils/models/validation/core.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from ..types import make_immutable_check_config | ||
|
||
|
||
def initialize_config(values, **kwargs): | ||
# This is what is returned by the initial root validator of each config model. | ||
return values | ||
|
||
|
||
def finalize_config(values, **kwargs): | ||
# This is what is returned by the final root validator of each config model. Note: | ||
# | ||
# 1. the final object must be a dict | ||
# 2. we maintain the original order of keys | ||
return {field: make_immutable_check_config(value) for field, value in values.items()} |
7 changes: 7 additions & 0 deletions
7
datadog_checks_base/datadog_checks/base/utils/models/validation/helpers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
|
||
def get_initialization_data(values): | ||
return values['__data'] |
27 changes: 27 additions & 0 deletions
27
datadog_checks_base/datadog_checks/base/utils/models/validation/utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
from .helpers import get_initialization_data | ||
|
||
|
||
def handle_deprecations(config_section, deprecations, values): | ||
warning_method = get_initialization_data(values)['warning'] | ||
|
||
for option, data in deprecations.items(): | ||
if option not in values: | ||
continue | ||
|
||
message = f'Option `{option}` in `{config_section}` is deprecated ->\n' | ||
|
||
for key, info in data.items(): | ||
key_part = f'{key}: ' | ||
info_pad = ' ' * len(key_part) | ||
message += key_part | ||
|
||
for i, line in enumerate(info.splitlines()): | ||
if i > 0: | ||
message += info_pad | ||
|
||
message += f'{line}\n' | ||
|
||
warning_method(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) |
18 changes: 18 additions & 0 deletions
18
datadog_checks_base/tests/models/config_models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
52 changes: 52 additions & 0 deletions
52
datadog_checks_base/tests/models/config_models/defaults.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# (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_deprecated(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def shared_timeout(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_array(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_deprecated(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_flag(field, value): | ||
return False | ||
|
||
|
||
def instance_hyphenated_name(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_mapping(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_obj(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_pass_(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_pid(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_text(field, value): | ||
return get_default_field_value(field, value) | ||
|
||
|
||
def instance_timeout(field, value): | ||
return get_default_field_value(field, value) |
11 changes: 11 additions & 0 deletions
11
datadog_checks_base/tests/models/config_models/deprecations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# (C) Datadog, Inc. 2021-present | ||
# All rights reserved | ||
# Licensed under a 3-clause BSD style license (see LICENSE) | ||
|
||
|
||
def shared(): | ||
return {'deprecated': {'Release': '8.0.0', 'Migration': 'do this\nand that\n'}} | ||
|
||
|
||
def instance(): | ||
return {'deprecated': {'Release': '9.0.0', 'Migration': 'do this\nand that\n'}} |
Oops, something went wrong.