Skip to content

Commit

Permalink
Sync config models
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Mar 22, 2021
1 parent 1e39718 commit dfeaced
Show file tree
Hide file tree
Showing 5 changed files with 449 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cilium/datadog_checks/cilium/config_models/__init__.py
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
236 changes: 236 additions & 0 deletions cilium/datadog_checks/cilium/config_models/defaults.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
# (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_proxy(field, value):
return get_default_field_value(field, value)


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


def shared_skip_proxy(field, value):
return False


def shared_timeout(field, value):
return 10


def instance_agent_endpoint(field, value):
return 'http://localhost:9090/metrics'


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


def instance_auth_type(field, value):
return 'basic'


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


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


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


def instance_bearer_token_auth(field, value):
return False


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


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


def instance_empty_default_hostname(field, value):
return False


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


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


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


def instance_health_service_check(field, value):
return True


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


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


def instance_kerberos_auth(field, value):
return 'disabled'


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


def instance_kerberos_delegate(field, value):
return False


def instance_kerberos_force_initiate(field, value):
return False


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


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


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


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


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


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


def instance_log_requests(field, value):
return False


def instance_min_collection_interval(field, value):
return 15


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


def instance_operator_endpoint(field, value):
return 'http://localhost:6942/metrics'


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


def instance_persist_connections(field, value):
return False


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


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


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


def instance_send_distribution_buckets(field, value):
return False


def instance_send_distribution_counts_as_monotonic(field, value):
return False


def instance_send_distribution_sums_as_monotonic(field, value):
return False


def instance_send_histograms_buckets(field, value):
return True


def instance_send_monotonic_counter(field, value):
return True


def instance_send_monotonic_with_gauge(field, value):
return False


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


def instance_skip_proxy(field, value):
return False


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


def instance_timeout(field, value):
return 10


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


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


def instance_tls_ignore_warning(field, value):
return False


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


def instance_tls_use_host_header(field, value):
return False


def instance_tls_verify(field, value):
return True


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


def instance_use_legacy_auth_encoding(field, value):
return True


def instance_username(field, value):
return get_default_field_value(field, value)
138 changes: 138 additions & 0 deletions cilium/datadog_checks/cilium/config_models/instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
# (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 Any, Mapping, 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 AuthToken(BaseModel):
class Config:
allow_mutation = False

reader: Optional[Mapping[str, Any]]
writer: Optional[Mapping[str, Any]]


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

target_label_key: Optional[str]
target_label_value_list: Optional[Sequence[str]]


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

label_to_match: Optional[str]
labels_to_get: Optional[Sequence[str]]


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

target_metric: Optional[TargetMetric]


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

http: Optional[str]
https: Optional[str]
no_proxy: Optional[Sequence[str]]


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

agent_endpoint: Optional[str]
auth_token: Optional[AuthToken]
auth_type: Optional[str]
aws_host: Optional[str]
aws_region: Optional[str]
aws_service: Optional[str]
bearer_token_auth: Optional[bool]
bearer_token_path: Optional[str]
connect_timeout: Optional[float]
empty_default_hostname: Optional[bool]
exclude_labels: Optional[Sequence[str]]
extra_headers: Optional[Mapping[str, Any]]
headers: Optional[Mapping[str, Any]]
health_service_check: Optional[bool]
ignore_metrics: Optional[Sequence[str]]
ignore_metrics_by_labels: Optional[IgnoreMetricsByLabels]
kerberos_auth: Optional[str]
kerberos_cache: Optional[str]
kerberos_delegate: Optional[bool]
kerberos_force_initiate: Optional[bool]
kerberos_hostname: Optional[str]
kerberos_keytab: Optional[str]
kerberos_principal: Optional[str]
label_joins: Optional[LabelJoins]
label_to_hostname: Optional[str]
labels_mapper: Optional[Mapping[str, Any]]
log_requests: Optional[bool]
metrics: Sequence[str]
min_collection_interval: Optional[float]
namespace: str
ntlm_domain: Optional[str]
operator_endpoint: Optional[str]
password: Optional[str]
persist_connections: Optional[bool]
prometheus_metrics_prefix: Optional[str]
prometheus_url: str
proxy: Optional[Proxy]
read_timeout: Optional[float]
send_distribution_buckets: Optional[bool]
send_distribution_counts_as_monotonic: Optional[bool]
send_distribution_sums_as_monotonic: Optional[bool]
send_histograms_buckets: Optional[bool]
send_monotonic_counter: Optional[bool]
send_monotonic_with_gauge: Optional[bool]
service: Optional[str]
skip_proxy: Optional[bool]
tags: Optional[Sequence[str]]
timeout: Optional[float]
tls_ca_cert: Optional[str]
tls_cert: Optional[str]
tls_ignore_warning: Optional[bool]
tls_private_key: Optional[str]
tls_use_host_header: Optional[bool]
tls_verify: Optional[bool]
type_overrides: Optional[Mapping[str, Any]]
use_legacy_auth_encoding: Optional[bool]
username: Optional[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))
Loading

0 comments on commit dfeaced

Please sign in to comment.