diff --git a/hazelcast/assets/configuration/spec.yaml b/hazelcast/assets/configuration/spec.yaml index 423c81df944f2..b2d5623d07762 100644 --- a/hazelcast/assets/configuration/spec.yaml +++ b/hazelcast/assets/configuration/spec.yaml @@ -6,6 +6,7 @@ files: options: - template: init_config/jmx overrides: + is_jmx.required: false is_jmx.value.example: false - template: init_config/http - template: instances @@ -29,8 +30,10 @@ files: In Transition: WARNING - template: instances/jmx overrides: + host.required: false host.display_priority: 10 host.description: Hazelcast or Hazelcast Management Center server with which to connect. + port.required: false port.display_priority: 9 port.description: Hazelcast or Hazelcast Management Center port with which to connect. port.value.example: 1099 diff --git a/hazelcast/datadog_checks/hazelcast/config_models/__init__.py b/hazelcast/datadog_checks/hazelcast/config_models/__init__.py new file mode 100644 index 0000000000000..ba42dbdc7ffb0 --- /dev/null +++ b/hazelcast/datadog_checks/hazelcast/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/hazelcast/datadog_checks/hazelcast/config_models/defaults.py b/hazelcast/datadog_checks/hazelcast/config_models/defaults.py new file mode 100644 index 0000000000000..89ef2d924df3d --- /dev/null +++ b/hazelcast/datadog_checks/hazelcast/config_models/defaults.py @@ -0,0 +1,272 @@ +# (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_collect_default_metrics(field, value): + return False + + +def shared_conf(field, value): + return get_default_field_value(field, value) + + +def shared_is_jmx(field, value): + return False + + +def shared_new_gc_metrics(field, value): + return False + + +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_service_check_prefix(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_allow_redirects(field, value): + return True + + +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_collect_default_jvm_metrics(field, value): + return True + + +def instance_connect_timeout(field, value): + return get_default_field_value(field, value) + + +def instance_disable_generic_tags(field, value): + return False + + +def instance_empty_default_hostname(field, value): + return False + + +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_host(field, value): + return get_default_field_value(field, value) + + +def instance_is_jmx(field, value): + return False + + +def instance_java_bin_path(field, value): + return get_default_field_value(field, value) + + +def instance_java_options(field, value): + return get_default_field_value(field, value) + + +def instance_jmx_url(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_key_store_password(field, value): + return get_default_field_value(field, value) + + +def instance_key_store_path(field, value): + return get_default_field_value(field, value) + + +def instance_log_requests(field, value): + return False + + +def instance_mc_cluster_states(field, value): + return get_default_field_value(field, value) + + +def instance_mc_health_check_endpoint(field, value): + return get_default_field_value(field, value) + + +def instance_min_collection_interval(field, value): + return 15 + + +def instance_name(field, value): + return get_default_field_value(field, value) + + +def instance_ntlm_domain(field, value): + return get_default_field_value(field, value) + + +def instance_password(field, value): + return get_default_field_value(field, value) + + +def instance_persist_connections(field, value): + return False + + +def instance_port(field, value): + return 1099 + + +def instance_process_name_regex(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_request_size(field, value): + return 16 + + +def instance_rmi_client_timeout(field, value): + return 15000 + + +def instance_rmi_connection_timeout(field, value): + return 20000 + + +def instance_rmi_registry_ssl(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_tools_jar_path(field, value): + return get_default_field_value(field, value) + + +def instance_trust_store_password(field, value): + return get_default_field_value(field, value) + + +def instance_trust_store_path(field, value): + return get_default_field_value(field, value) + + +def instance_use_legacy_auth_encoding(field, value): + return True + + +def instance_user(field, value): + return get_default_field_value(field, value) + + +def instance_username(field, value): + return get_default_field_value(field, value) diff --git a/hazelcast/datadog_checks/hazelcast/config_models/instance.py b/hazelcast/datadog_checks/hazelcast/config_models/instance.py new file mode 100644 index 0000000000000..80084e54f2a67 --- /dev/null +++ b/hazelcast/datadog_checks/hazelcast/config_models/instance.py @@ -0,0 +1,116 @@ +# (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 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 + + allow_redirects: Optional[bool] + auth_token: Optional[AuthToken] + auth_type: Optional[str] + aws_host: Optional[str] + aws_region: Optional[str] + aws_service: Optional[str] + collect_default_jvm_metrics: Optional[bool] + connect_timeout: Optional[float] + disable_generic_tags: Optional[bool] + empty_default_hostname: Optional[bool] + extra_headers: Optional[Mapping[str, Any]] + headers: Optional[Mapping[str, Any]] + host: Optional[str] + is_jmx: Optional[bool] + java_bin_path: Optional[str] + java_options: Optional[str] + jmx_url: Optional[str] + 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] + key_store_password: Optional[str] + key_store_path: Optional[str] + log_requests: Optional[bool] + mc_cluster_states: Optional[Mapping[str, Any]] + mc_health_check_endpoint: Optional[str] + min_collection_interval: Optional[float] + name: Optional[str] + ntlm_domain: Optional[str] + password: Optional[str] + persist_connections: Optional[bool] + port: Optional[int] + process_name_regex: Optional[str] + proxy: Optional[Proxy] + read_timeout: Optional[float] + request_size: Optional[float] + rmi_client_timeout: Optional[float] + rmi_connection_timeout: Optional[float] + rmi_registry_ssl: 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] + tools_jar_path: Optional[str] + trust_store_password: Optional[str] + trust_store_path: Optional[str] + use_legacy_auth_encoding: Optional[bool] + user: Optional[str] + 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)) diff --git a/hazelcast/datadog_checks/hazelcast/config_models/shared.py b/hazelcast/datadog_checks/hazelcast/config_models/shared.py new file mode 100644 index 0000000000000..9e61aa822dad9 --- /dev/null +++ b/hazelcast/datadog_checks/hazelcast/config_models/shared.py @@ -0,0 +1,59 @@ +# (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 Proxy(BaseModel): + class Config: + allow_mutation = False + + http: Optional[str] + https: Optional[str] + no_proxy: Optional[Sequence[str]] + + +class SharedConfig(BaseModel): + class Config: + allow_mutation = False + + collect_default_metrics: Optional[bool] + conf: Optional[Sequence[Mapping[str, Any]]] + is_jmx: Optional[bool] + new_gc_metrics: Optional[bool] + proxy: Optional[Proxy] + service: Optional[str] + service_check_prefix: Optional[str] + skip_proxy: Optional[bool] + timeout: Optional[float] + + @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/hazelcast/datadog_checks/hazelcast/config_models/validators.py b/hazelcast/datadog_checks/hazelcast/config_models/validators.py new file mode 100644 index 0000000000000..9d0b0155542cb --- /dev/null +++ b/hazelcast/datadog_checks/hazelcast/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) diff --git a/hazelcast/datadog_checks/hazelcast/data/conf.yaml.example b/hazelcast/datadog_checks/hazelcast/data/conf.yaml.example index 8d98db1088c13..dbac72de5ba82 100644 --- a/hazelcast/datadog_checks/hazelcast/data/conf.yaml.example +++ b/hazelcast/datadog_checks/hazelcast/data/conf.yaml.example @@ -2,10 +2,10 @@ # init_config: - ## @param is_jmx - boolean - required + ## @param is_jmx - boolean - optional - default: false ## Whether or not this file is a configuration for a JMX integration. # - is_jmx: false + # is_jmx: false ## @param collect_default_metrics - boolean - optional - default: false ## Whether or not the check should collect all default metrics. @@ -85,15 +85,16 @@ init_config: # instances: - ## @param host - string - required + - + ## @param host - string - optional ## Hazelcast or Hazelcast Management Center server with which to connect. # - - host: + # host: - ## @param port - integer - required + ## @param port - integer - optional - default: 1099 ## Hazelcast or Hazelcast Management Center port with which to connect. # - port: 1099 + # port: 1099 ## @param mc_health_check_endpoint - string - optional ## Hazelcast Management Center health check endpoint with which