Skip to content

Commit

Permalink
Update generated config models (#15212)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored Jul 19, 2023
1 parent 73fad79 commit 3b6363c
Show file tree
Hide file tree
Showing 546 changed files with 22,708 additions and 35,572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,30 @@
# ddev -x validate config -s <INTEGRATION_NAME>
# ddev -x validate models -s <INTEGRATION_NAME>

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 shared_use_localized_counters(field, value):
def shared_use_localized_counters():
return False


def instance_additional_metrics(field, value):
return get_default_field_value(field, value)


def instance_counter_data_types(field, value):
return get_default_field_value(field, value)


def instance_disable_generic_tags(field, value):
def instance_disable_generic_tags():
return False


def instance_empty_default_hostname(field, value):
def instance_empty_default_hostname():
return False


def instance_enable_health_service_check(field, value):
def instance_enable_health_service_check():
return True


def instance_extra_metrics(field, value):
return get_default_field_value(field, value)


def instance_host(field, value):
def instance_host():
return '.'


def instance_metric_patterns(field, value):
return get_default_field_value(field, value)


def instance_metrics(field, value):
return get_default_field_value(field, value)


def instance_min_collection_interval(field, value):
def instance_min_collection_interval():
return 15


def instance_namespace(field, value):
return get_default_field_value(field, value)


def instance_password(field, value):
return get_default_field_value(field, value)


def instance_server(field, value):
return get_default_field_value(field, value)


def instance_server_tag(field, value):
return get_default_field_value(field, value)


def instance_service(field, value):
return get_default_field_value(field, value)


def instance_tags(field, value):
return get_default_field_value(field, value)


def instance_use_legacy_check_version(field, value):
def instance_use_legacy_check_version():
return False


def instance_username(field, value):
return get_default_field_value(field, value)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

from __future__ import annotations

from typing import Literal, Mapping, Optional, Sequence, Union
from typing import Mapping, Optional, Sequence, Union

from pydantic import BaseModel, Extra, Field, root_validator, validator
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
from typing_extensions import Literal

from datadog_checks.base.utils.functions import identity
from datadog_checks.base.utils.models import validation
Expand All @@ -20,101 +21,110 @@


class Counter(BaseModel):
class Config:
extra = Extra.allow
allow_mutation = False

aggregate: Optional[Union[bool, Literal['only']]]
average: Optional[bool]
metric_name: Optional[str]
name: Optional[str]
type: Optional[str]
model_config = ConfigDict(
extra='allow',
frozen=True,
)
aggregate: Optional[Union[bool, Literal['only']]] = None
average: Optional[bool] = None
metric_name: Optional[str] = None
name: Optional[str] = None
type: Optional[str] = None


class InstanceCounts(BaseModel):
class Config:
allow_mutation = False

monitored: Optional[str]
total: Optional[str]
unique: Optional[str]
model_config = ConfigDict(
frozen=True,
)
monitored: Optional[str] = None
total: Optional[str] = None
unique: Optional[str] = None


class ExtraMetrics(BaseModel):
class Config:
allow_mutation = False

model_config = ConfigDict(
frozen=True,
)
counters: Sequence[Mapping[str, Union[str, Counter]]]
exclude: Optional[Sequence[str]]
include: Optional[Sequence[str]]
instance_counts: Optional[InstanceCounts]
exclude: Optional[Sequence[str]] = None
include: Optional[Sequence[str]] = None
instance_counts: Optional[InstanceCounts] = None
name: str
tag_name: Optional[str]
use_localized_counters: Optional[bool]
tag_name: Optional[str] = None
use_localized_counters: Optional[bool] = None


class MetricPatterns(BaseModel):
class Config:
allow_mutation = False

exclude: Optional[Sequence[str]]
include: Optional[Sequence[str]]
model_config = ConfigDict(
frozen=True,
)
exclude: Optional[Sequence[str]] = None
include: Optional[Sequence[str]] = None


class Metrics(BaseModel):
class Config:
allow_mutation = False

model_config = ConfigDict(
frozen=True,
)
counters: Sequence[Mapping[str, Union[str, Counter]]]
exclude: Optional[Sequence[str]]
include: Optional[Sequence[str]]
instance_counts: Optional[InstanceCounts]
exclude: Optional[Sequence[str]] = None
include: Optional[Sequence[str]] = None
instance_counts: Optional[InstanceCounts] = None
name: str
tag_name: Optional[str]
use_localized_counters: Optional[bool]
tag_name: Optional[str] = None
use_localized_counters: Optional[bool] = None


class InstanceConfig(BaseModel):
class Config:
allow_mutation = False

additional_metrics: Optional[Sequence[Sequence[str]]]
counter_data_types: Optional[Sequence[str]]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
enable_health_service_check: Optional[bool]
extra_metrics: Optional[Mapping[str, ExtraMetrics]]
host: Optional[str]
metric_patterns: Optional[MetricPatterns]
metrics: Optional[Mapping[str, Metrics]]
min_collection_interval: Optional[float]
namespace: Optional[str] = Field(None, regex='\\w*')
password: Optional[str]
server: Optional[str]
server_tag: Optional[str]
service: Optional[str]
tags: Optional[Sequence[str]]
use_legacy_check_version: Optional[bool]
username: Optional[str]

@root_validator(pre=True)
model_config = ConfigDict(
validate_default=True,
frozen=True,
)
additional_metrics: Optional[Sequence[Sequence[str]]] = None
counter_data_types: Optional[Sequence[str]] = None
disable_generic_tags: Optional[bool] = None
empty_default_hostname: Optional[bool] = None
enable_health_service_check: Optional[bool] = None
extra_metrics: Optional[Mapping[str, ExtraMetrics]] = None
host: Optional[str] = None
metric_patterns: Optional[MetricPatterns] = None
metrics: Optional[Mapping[str, Metrics]] = None
min_collection_interval: Optional[float] = None
namespace: Optional[str] = Field(None, pattern='\\w*')
password: Optional[str] = None
server: Optional[str] = None
server_tag: Optional[str] = None
service: Optional[str] = None
tags: Optional[Sequence[str]] = None
use_legacy_check_version: 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))

@validator('*', pre=True, always=True)
def _ensure_defaults(cls, v, field):
if v is not None or field.required:
return v
@field_validator('*', mode='before')
def _ensure_defaults(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']:
return value

return getattr(defaults, f'instance_{info.field_name}', lambda: value)()

return getattr(defaults, f'instance_{field.name}')(field, v)
@field_validator('*')
def _run_validations(cls, value, info):
field = cls.model_fields[info.field_name]
field_name = field.alias or info.field_name
if field_name not in info.context['configured_fields']:
return value

@validator('*')
def _run_validations(cls, v, field):
if not v:
return v
return getattr(validators, f'instance_{info.field_name}', identity)(value, field=field)

return getattr(validators, f'instance_{field.name}', identity)(v, field=field)
@field_validator('*', mode='after')
def _make_immutable(cls, value):
return validation.utils.make_immutable(value)

@root_validator(pre=False)
def _final_validation(cls, values):
return validation.core.finalize_config(getattr(validators, 'finalize_instance', identity)(values))
@model_validator(mode='after')
def _final_validation(cls, model):
return validation.core.check_model(getattr(validators, 'check_instance', identity)(model))
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from typing import Optional

from pydantic import BaseModel, root_validator, validator
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
Expand All @@ -20,30 +20,39 @@


class SharedConfig(BaseModel):
class Config:
allow_mutation = False

service: Optional[str]
use_localized_counters: Optional[bool]

@root_validator(pre=True)
model_config = ConfigDict(
validate_default=True,
frozen=True,
)
service: Optional[str] = None
use_localized_counters: Optional[bool] = None

@model_validator(mode='before')
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
@field_validator('*', mode='before')
def _ensure_defaults(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']:
return value

return getattr(defaults, f'shared_{info.field_name}', lambda: value)()

return getattr(defaults, f'shared_{field.name}')(field, v)
@field_validator('*')
def _run_validations(cls, value, info):
field = cls.model_fields[info.field_name]
field_name = field.alias or info.field_name
if field_name not in info.context['configured_fields']:
return value

@validator('*')
def _run_validations(cls, v, field):
if not v:
return v
return getattr(validators, f'shared_{info.field_name}', identity)(value, field=field)

return getattr(validators, f'shared_{field.name}', identity)(v, field=field)
@field_validator('*', mode='after')
def _make_immutable(cls, value):
return validation.utils.make_immutable(value)

@root_validator(pre=False)
def _final_validation(cls, values):
return validation.core.finalize_config(getattr(validators, 'finalize_shared', identity)(values))
@model_validator(mode='after')
def _final_validation(cls, model):
return validation.core.check_model(getattr(validators, 'check_shared', identity)(model))
Loading

0 comments on commit 3b6363c

Please sign in to comment.