(self, instance)
return ksm_instance
Set up the kubernetes_state instance so it can be used in OpenMetricsBaseCheck
Set up the kubernetes_state instance so it can be used in OpenMetricsBaseCheck
Set up the kubernetes_state instance so it can be used in OpenMetricsBaseCheck
def _create_kubernetes_state_prometheus_instance(self, instance):
        """
        Set up the kubernetes_state instance so it can be used in OpenMetricsBaseCheck
        """
        ksm_instance = deepcopy(instance)
        endpoint = instance.get('kube_state_url')
        if endpoint is None:
            raise CheckException("Unable to find kube_state_url in config file.")

        extra_labels = ksm_instance.get('label_joins', {})
        hostname_override = is_affirmative(ksm_instance.get('hostname_override', True))
        join_kube_labels = is_affirmative(ksm_instance.get('join_kube_labels', False))
        join_standard_tags = is_affirmative(ksm_instance.get('join_standard_tags', False))

        ksm_instance.update(
            {
                'namespace': 'kubernetes_state',
                'metrics': [
                    {
                        'kube_daemonset_status_current_number_scheduled': 'daemonset.scheduled',
                        'kube_daemonset_status_desired_number_scheduled': 'daemonset.desired',
                        'kube_daemonset_status_number_misscheduled': 'daemonset.misscheduled',
                        'kube_daemonset_status_number_ready': 'daemonset.ready',
                        'kube_daemonset_updated_number_scheduled': 'daemonset.updated',
                        'kube_deployment_spec_paused': 'deployment.paused',
                        'kube_deployment_spec_replicas': 'deployment.replicas_desired',
                        'kube_deployment_spec_strategy_rollingupdate_max_unavailable': 'deployment.rollingupdate.max_unavailable',  # noqa: E501
                        'kube_deployment_status_replicas': 'deployment.replicas',
                        'kube_deployment_status_replicas_available': 'deployment.replicas_available',
                        'kube_deployment_status_replicas_unavailable': 'deployment.replicas_unavailable',
                        'kube_deployment_status_replicas_updated': 'deployment.replicas_updated',
                        'kube_endpoint_address_available': 'endpoint.address_available',
                        'kube_endpoint_address_not_ready': 'endpoint.address_not_ready',
                        'kube_endpoint_created': 'endpoint.created',
                        'kube_hpa_spec_min_replicas': 'hpa.min_replicas',
                        'kube_hpa_spec_max_replicas': 'hpa.max_replicas',
                        'kube_hpa_status_desired_replicas': 'hpa.desired_replicas',
                        'kube_hpa_status_current_replicas': 'hpa.current_replicas',
                        'kube_hpa_status_condition': 'hpa.condition',
                        'kube_node_info': 'node.count',
                        'kube_pod_info': 'pod.count',
                        'kube_node_status_allocatable_cpu_cores': 'node.cpu_allocatable',
                        'kube_node_status_allocatable_memory_bytes': 'node.memory_allocatable',
                        'kube_node_status_allocatable_pods': 'node.pods_allocatable',
                        'kube_node_status_capacity_cpu_cores': 'node.cpu_capacity',
                        'kube_node_status_capacity_memory_bytes': 'node.memory_capacity',
                        'kube_node_status_capacity_pods': 'node.pods_capacity',
                        'kube_node_status_allocatable_nvidia_gpu_cards': 'node.gpu.cards_allocatable',
                        'kube_node_status_capacity_nvidia_gpu_cards': 'node.gpu.cards_capacity',
                        'kube_pod_container_status_terminated': 'container.terminated',
                        'kube_pod_container_status_waiting': 'container.waiting',
                        'kube_persistentvolumeclaim_status_phase': 'persistentvolumeclaim.status',
                        'kube_persistentvolumeclaim_resource_requests_storage_bytes': 'persistentvolumeclaim.request_storage',  # noqa: E501
                        'kube_pod_container_resource_limits_cpu_cores': 'container.cpu_limit',
                        'kube_pod_container_resource_limits_memory_bytes': 'container.memory_limit',
                        'kube_pod_container_resource_requests_cpu_cores': 'container.cpu_requested',
                        'kube_pod_container_resource_requests_memory_bytes': 'container.memory_requested',
                        'kube_pod_container_status_ready': 'container.ready',
                        'kube_pod_container_status_restarts': 'container.restarts',  # up to kube-state-metrics 1.1.x
                        'kube_pod_container_status_restarts_total': 'container.restarts',  # noqa: E501, from kube-state-metrics 1.2.0
                        'kube_pod_container_status_running': 'container.running',
                        'kube_pod_container_resource_requests_nvidia_gpu_devices': 'container.gpu.request',
                        'kube_pod_container_resource_limits_nvidia_gpu_devices': 'container.gpu.limit',
                        'kube_pod_status_ready': 'pod.ready',
                        'kube_pod_status_scheduled': 'pod.scheduled',
                        'kube_pod_status_unschedulable': 'pod.unschedulable',
                        'kube_poddisruptionbudget_status_current_healthy': 'pdb.pods_healthy',
                        'kube_poddisruptionbudget_status_desired_healthy': 'pdb.pods_desired',
                        'kube_poddisruptionbudget_status_pod_disruptions_allowed': 'pdb.disruptions_allowed',
                        'kube_poddisruptionbudget_status_expected_pods': 'pdb.pods_total',
                        'kube_replicaset_spec_replicas': 'replicaset.replicas_desired',
                        'kube_replicaset_status_fully_labeled_replicas': 'replicaset.fully_labeled_replicas',
                        'kube_replicaset_status_ready_replicas': 'replicaset.replicas_ready',
                        'kube_replicaset_status_replicas': 'replicaset.replicas',
                        'kube_replicationcontroller_spec_replicas': 'replicationcontroller.replicas_desired',
                        'kube_replicationcontroller_status_available_replicas': 'replicationcontroller.replicas_available',  # noqa: E501
                        'kube_replicationcontroller_status_fully_labeled_replicas': 'replicationcontroller.fully_labeled_replicas',  # noqa: E501
                        'kube_replicationcontroller_status_ready_replicas': 'replicationcontroller.replicas_ready',
                        'kube_replicationcontroller_status_replicas': 'replicationcontroller.replicas',
                        'kube_statefulset_replicas': 'statefulset.replicas_desired',
                        'kube_statefulset_status_replicas': 'statefulset.replicas',
                        'kube_statefulset_status_replicas_current': 'statefulset.replicas_current',
                        'kube_statefulset_status_replicas_ready': 'statefulset.replicas_ready',
                        'kube_statefulset_status_replicas_updated': 'statefulset.replicas_updated',
                        'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound': (
                            'vpa.lower_bound'
                        ),
                        'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_target': (
                            'vpa.target'
                        ),
                        'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget': (
                            'vpa.uncapped_target'
                        ),
                        'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound': (
                            'vpa.upperbound'
                        ),
                        'kube_verticalpodautoscaler_spec_updatepolicy_updatemode': 'vpa.update_mode',
                    }
                ],
                'ignore_metrics': [
                    # _info, _labels and _created don't convey any metric
                    'kube_cronjob_info',
                    'kube_cronjob_created',
                    'kube_daemonset_created',
                    'kube_deployment_created',
                    'kube_deployment_labels',
                    'kube_job_created',
                    'kube_job_info',
                    'kube_limitrange_created',
                    'kube_namespace_created',
                    'kube_namespace_labels',
                    'kube_node_created',
                    'kube_node_labels',
                    'kube_pod_created',
                    'kube_pod_container_info',
                    'kube_pod_owner',
                    'kube_pod_start_time',
                    'kube_pod_labels',
                    'kube_poddisruptionbudget_created',
                    'kube_replicaset_created',
                    'kube_replicationcontroller_created',
                    'kube_resourcequota_created',
                    'kube_service_created',
                    'kube_service_info',
                    'kube_service_labels',
                    'kube_service_spec_external_ip',
                    'kube_service_status_load_balancer_ingress',
                    'kube_statefulset_labels',
                    'kube_statefulset_created',
                    'kube_statefulset_status_current_revision',
                    'kube_statefulset_status_update_revision',
                    # Already provided by the kubelet integration
                    'kube_pod_container_status_last_terminated_reason',
                    # _generation metrics are more metadata than metrics, no real use case for now
                    'kube_daemonset_metadata_generation',
                    'kube_deployment_metadata_generation',
                    'kube_deployment_status_condition',
                    'kube_replicaset_metadata_generation',
                    'kube_replicaset_status_observed_generation',
                    'kube_replicationcontroller_metadata_generation',
                    'kube_replicationcontroller_status_observed_generation',
                    'kube_statefulset_metadata_generation',
                    'kube_hpa_metadata_generation',
                    # kube_node_status_phase has no use case as a service check
                    'kube_node_status_phase',
                    # These CronJob and Job metrics need use cases to determine how do implement
                    'kube_cronjob_status_active',
                    'kube_cronjob_status_last_schedule_time',
                    'kube_cronjob_spec_suspend',
                    'kube_cronjob_spec_starting_deadline_seconds',
                    'kube_job_spec_active_dealine_seconds',
                    'kube_job_spec_completions',
                    'kube_job_spec_parallelism',
                    'kube_job_status_active',
                    'kube_job_status_completion_time',  # We could compute the duration=completion-start as a gauge
                    'kube_job_status_start_time',
                    'kube_verticalpodautoscaler_labels',
                ],
                'label_joins': {
                    'kube_pod_info': {'labels_to_match': ['pod', 'namespace'], 'labels_to_get': ['node']},
                    'kube_pod_status_phase': {'labels_to_match': ['pod', 'namespace'], 'labels_to_get': ['phase']},
                    'kube_persistentvolume_info': {
                        'labels_to_match': ['persistentvolume'],  # Persistent Volumes are not namespaced
                        'labels_to_get': ['storageclass'],
                    },
                    'kube_persistentvolumeclaim_info': {
                        'labels_to_match': ['persistentvolumeclaim', 'namespace'],
                        'labels_to_get': ['storageclass'],
                    },
                },
                # Defaults that were set when kubernetes_state was based on PrometheusCheck
                'send_monotonic_counter': ksm_instance.get('send_monotonic_counter', False),
                'health_service_check': ksm_instance.get('health_service_check', False),
            }
        )

        experimental_metrics_mapping = {
            'kube_hpa_spec_target_metric': 'hpa.spec_target_metric',
            'kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed': (
                'vpa.spec_container_minallowed'
            ),
            'kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed': (
                'vpa.spec_container_maxallowed'
            ),
        }
        experimental_metrics = is_affirmative(ksm_instance.get('experimental_metrics', False))
        if experimental_metrics:
            ksm_instance['metrics'].append(experimental_metrics_mapping)
        else:
            ksm_instance['ignore_metrics'].extend(experimental_metrics_mapping.keys())

        ksm_instance['prometheus_url'] = endpoint

        if join_kube_labels:
            ksm_instance['label_joins'].update(
                {
                    'kube_pod_labels': {'labels_to_match': ['pod', 'namespace'], 'labels_to_get': ['*']},
                    'kube_deployment_labels': {'labels_to_match': ['deployment', 'namespace'], 'labels_to_get': ['*']},
                    'kube_daemonset_labels': {'labels_to_match': ['daemonset', 'namespace'], 'labels_to_get': ['*']},
                }
            )

        labels_to_get = [
            "label_tags_datadoghq_com_env",
            "label_tags_datadoghq_com_service",
            "label_tags_datadoghq_com_version",
        ]

        if join_standard_tags:
            ksm_instance['label_joins'].update(
                {
                    "kube_pod_labels": {"labels_to_match": ["pod", "namespace"], "labels_to_get": labels_to_get},
                    "kube_deployment_labels": {
                        "labels_to_match": ["deployment", "namespace"],
                        "labels_to_get": labels_to_get,
                    },
                    "kube_replicaset_labels": {
                        "labels_to_match": ["replicaset", "namespace"],
                        "labels_to_get": labels_to_get,
                    },
                    "kube_daemonset_labels": {
                        "labels_to_match": ["daemonset", "namespace"],
                        "labels_to_get": labels_to_get,
                    },
                    "kube_statefulset_labels": {
                        "labels_to_match": ["statefulset", "namespace"],
                        "labels_to_get": labels_to_get,
                    },
                    "kube_job_labels": {"labels_to_match": ["job_name", "namespace"], "labels_to_get": labels_to_get},
                }
            )

            ksm_instance.setdefault("labels_mapper", {}).update(
                {
                    "label_tags_datadoghq_com_env": "env",
                    "label_tags_datadoghq_com_service": "service",
                    "label_tags_datadoghq_com_version": "version",
                }
            )

        ksm_instance['label_joins'].update(extra_labels)
        if hostname_override:
            ksm_instance['label_to_hostname'] = 'node'
            clustername = get_clustername()
            if clustername != "":
                # some cluster names are not valid RFC1123, but as we use them as a hostAlias we want them to be valid.
                clustername = clustername.replace("_", "-")
                ksm_instance['label_to_hostname_suffix'] = "-" + clustername

        if 'labels_mapper' in ksm_instance and not isinstance(ksm_instance['labels_mapper'], dict):
            self.log.warning("Option labels_mapper should be a dictionary for %s", endpoint)

        return ksm_instance
def _create_kubernetes_state_prometheus_instance ( self , instance ) : ksm_instance = deepcopy ( instance ) endpoint = instance . get ( 'kube_state_url' ) if endpoint is None : raise CheckException ( "Unable to find kube_state_url in config file." ) extra_labels = ksm_instance . get ( 'label_joins' , { } ) hostname_override = is_affirmative ( ksm_instance . get ( 'hostname_override' , True ) ) join_kube_labels = is_affirmative ( ksm_instance . get ( 'join_kube_labels' , False ) ) join_standard_tags = is_affirmative ( ksm_instance . get ( 'join_standard_tags' , False ) ) ksm_instance . update ( { 'namespace' : 'kubernetes_state' , 'metrics' : [ { 'kube_daemonset_status_current_number_scheduled' : 'daemonset.scheduled' , 'kube_daemonset_status_desired_number_scheduled' : 'daemonset.desired' , 'kube_daemonset_status_number_misscheduled' : 'daemonset.misscheduled' , 'kube_daemonset_status_number_ready' : 'daemonset.ready' , 'kube_daemonset_updated_number_scheduled' : 'daemonset.updated' , 'kube_deployment_spec_paused' : 'deployment.paused' , 'kube_deployment_spec_replicas' : 'deployment.replicas_desired' , 'kube_deployment_spec_strategy_rollingupdate_max_unavailable' : 'deployment.rollingupdate.max_unavailable' , # noqa: E501 'kube_deployment_status_replicas' : 'deployment.replicas' , 'kube_deployment_status_replicas_available' : 'deployment.replicas_available' , 'kube_deployment_status_replicas_unavailable' : 'deployment.replicas_unavailable' , 'kube_deployment_status_replicas_updated' : 'deployment.replicas_updated' , 'kube_endpoint_address_available' : 'endpoint.address_available' , 'kube_endpoint_address_not_ready' : 'endpoint.address_not_ready' , 'kube_endpoint_created' : 'endpoint.created' , 'kube_hpa_spec_min_replicas' : 'hpa.min_replicas' , 'kube_hpa_spec_max_replicas' : 'hpa.max_replicas' , 'kube_hpa_status_desired_replicas' : 'hpa.desired_replicas' , 'kube_hpa_status_current_replicas' : 'hpa.current_replicas' , 'kube_hpa_status_condition' : 'hpa.condition' , 'kube_node_info' : 'node.count' , 'kube_pod_info' : 'pod.count' , 'kube_node_status_allocatable_cpu_cores' : 'node.cpu_allocatable' , 'kube_node_status_allocatable_memory_bytes' : 'node.memory_allocatable' , 'kube_node_status_allocatable_pods' : 'node.pods_allocatable' , 'kube_node_status_capacity_cpu_cores' : 'node.cpu_capacity' , 'kube_node_status_capacity_memory_bytes' : 'node.memory_capacity' , 'kube_node_status_capacity_pods' : 'node.pods_capacity' , 'kube_node_status_allocatable_nvidia_gpu_cards' : 'node.gpu.cards_allocatable' , 'kube_node_status_capacity_nvidia_gpu_cards' : 'node.gpu.cards_capacity' , 'kube_pod_container_status_terminated' : 'container.terminated' , 'kube_pod_container_status_waiting' : 'container.waiting' , 'kube_persistentvolumeclaim_status_phase' : 'persistentvolumeclaim.status' , 'kube_persistentvolumeclaim_resource_requests_storage_bytes' : 'persistentvolumeclaim.request_storage' , # noqa: E501 'kube_pod_container_resource_limits_cpu_cores' : 'container.cpu_limit' , 'kube_pod_container_resource_limits_memory_bytes' : 'container.memory_limit' , 'kube_pod_container_resource_requests_cpu_cores' : 'container.cpu_requested' , 'kube_pod_container_resource_requests_memory_bytes' : 'container.memory_requested' , 'kube_pod_container_status_ready' : 'container.ready' , 'kube_pod_container_status_restarts' : 'container.restarts' , # up to kube-state-metrics 1.1.x 'kube_pod_container_status_restarts_total' : 'container.restarts' , # noqa: E501, from kube-state-metrics 1.2.0 'kube_pod_container_status_running' : 'container.running' , 'kube_pod_container_resource_requests_nvidia_gpu_devices' : 'container.gpu.request' , 'kube_pod_container_resource_limits_nvidia_gpu_devices' : 'container.gpu.limit' , 'kube_pod_status_ready' : 'pod.ready' , 'kube_pod_status_scheduled' : 'pod.scheduled' , 'kube_pod_status_unschedulable' : 'pod.unschedulable' , 'kube_poddisruptionbudget_status_current_healthy' : 'pdb.pods_healthy' , 'kube_poddisruptionbudget_status_desired_healthy' : 'pdb.pods_desired' , 'kube_poddisruptionbudget_status_pod_disruptions_allowed' : 'pdb.disruptions_allowed' , 'kube_poddisruptionbudget_status_expected_pods' : 'pdb.pods_total' , 'kube_replicaset_spec_replicas' : 'replicaset.replicas_desired' , 'kube_replicaset_status_fully_labeled_replicas' : 'replicaset.fully_labeled_replicas' , 'kube_replicaset_status_ready_replicas' : 'replicaset.replicas_ready' , 'kube_replicaset_status_replicas' : 'replicaset.replicas' , 'kube_replicationcontroller_spec_replicas' : 'replicationcontroller.replicas_desired' , 'kube_replicationcontroller_status_available_replicas' : 'replicationcontroller.replicas_available' , # noqa: E501 'kube_replicationcontroller_status_fully_labeled_replicas' : 'replicationcontroller.fully_labeled_replicas' , # noqa: E501 'kube_replicationcontroller_status_ready_replicas' : 'replicationcontroller.replicas_ready' , 'kube_replicationcontroller_status_replicas' : 'replicationcontroller.replicas' , 'kube_statefulset_replicas' : 'statefulset.replicas_desired' , 'kube_statefulset_status_replicas' : 'statefulset.replicas' , 'kube_statefulset_status_replicas_current' : 'statefulset.replicas_current' , 'kube_statefulset_status_replicas_ready' : 'statefulset.replicas_ready' , 'kube_statefulset_status_replicas_updated' : 'statefulset.replicas_updated' , 'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_lowerbound' : ( 'vpa.lower_bound' ) , 'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_target' : ( 'vpa.target' ) , 'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_uncappedtarget' : ( 'vpa.uncapped_target' ) , 'kube_verticalpodautoscaler_status_recommendation_containerrecommendations_upperbound' : ( 'vpa.upperbound' ) , 'kube_verticalpodautoscaler_spec_updatepolicy_updatemode' : 'vpa.update_mode' , } ] , 'ignore_metrics' : [ # _info, _labels and _created don't convey any metric 'kube_cronjob_info' , 'kube_cronjob_created' , 'kube_daemonset_created' , 'kube_deployment_created' , 'kube_deployment_labels' , 'kube_job_created' , 'kube_job_info' , 'kube_limitrange_created' , 'kube_namespace_created' , 'kube_namespace_labels' , 'kube_node_created' , 'kube_node_labels' , 'kube_pod_created' , 'kube_pod_container_info' , 'kube_pod_owner' , 'kube_pod_start_time' , 'kube_pod_labels' , 'kube_poddisruptionbudget_created' , 'kube_replicaset_created' , 'kube_replicationcontroller_created' , 'kube_resourcequota_created' , 'kube_service_created' , 'kube_service_info' , 'kube_service_labels' , 'kube_service_spec_external_ip' , 'kube_service_status_load_balancer_ingress' , 'kube_statefulset_labels' , 'kube_statefulset_created' , 'kube_statefulset_status_current_revision' , 'kube_statefulset_status_update_revision' , # Already provided by the kubelet integration 'kube_pod_container_status_last_terminated_reason' , # _generation metrics are more metadata than metrics, no real use case for now 'kube_daemonset_metadata_generation' , 'kube_deployment_metadata_generation' , 'kube_deployment_status_condition' , 'kube_replicaset_metadata_generation' , 'kube_replicaset_status_observed_generation' , 'kube_replicationcontroller_metadata_generation' , 'kube_replicationcontroller_status_observed_generation' , 'kube_statefulset_metadata_generation' , 'kube_hpa_metadata_generation' , # kube_node_status_phase has no use case as a service check 'kube_node_status_phase' , # These CronJob and Job metrics need use cases to determine how do implement 'kube_cronjob_status_active' , 'kube_cronjob_status_last_schedule_time' , 'kube_cronjob_spec_suspend' , 'kube_cronjob_spec_starting_deadline_seconds' , 'kube_job_spec_active_dealine_seconds' , 'kube_job_spec_completions' , 'kube_job_spec_parallelism' , 'kube_job_status_active' , 'kube_job_status_completion_time' , # We could compute the duration=completion-start as a gauge 'kube_job_status_start_time' , 'kube_verticalpodautoscaler_labels' , ] , 'label_joins' : { 'kube_pod_info' : { 'labels_to_match' : [ 'pod' , 'namespace' ] , 'labels_to_get' : [ 'node' ] } , 'kube_pod_status_phase' : { 'labels_to_match' : [ 'pod' , 'namespace' ] , 'labels_to_get' : [ 'phase' ] } , 'kube_persistentvolume_info' : { 'labels_to_match' : [ 'persistentvolume' ] , # Persistent Volumes are not namespaced 'labels_to_get' : [ 'storageclass' ] , } , 'kube_persistentvolumeclaim_info' : { 'labels_to_match' : [ 'persistentvolumeclaim' , 'namespace' ] , 'labels_to_get' : [ 'storageclass' ] , } , } , # Defaults that were set when kubernetes_state was based on PrometheusCheck 'send_monotonic_counter' : ksm_instance . get ( 'send_monotonic_counter' , False ) , 'health_service_check' : ksm_instance . get ( 'health_service_check' , False ) , } ) experimental_metrics_mapping = { 'kube_hpa_spec_target_metric' : 'hpa.spec_target_metric' , 'kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_minallowed' : ( 'vpa.spec_container_minallowed' ) , 'kube_verticalpodautoscaler_spec_resourcepolicy_container_policies_maxallowed' : ( 'vpa.spec_container_maxallowed' ) , } experimental_metrics = is_affirmative ( ksm_instance . get ( 'experimental_metrics' , False ) ) if experimental_metrics : ksm_instance [ 'metrics' ] . append ( experimental_metrics_mapping ) else : ksm_instance [ 'ignore_metrics' ] . extend ( experimental_metrics_mapping . keys ( ) ) ksm_instance [ 'prometheus_url' ] = endpoint if join_kube_labels : ksm_instance [ 'label_joins' ] . update ( { 'kube_pod_labels' : { 'labels_to_match' : [ 'pod' , 'namespace' ] , 'labels_to_get' : [ '*' ] } , 'kube_deployment_labels' : { 'labels_to_match' : [ 'deployment' , 'namespace' ] , 'labels_to_get' : [ '*' ] } , 'kube_daemonset_labels' : { 'labels_to_match' : [ 'daemonset' , 'namespace' ] , 'labels_to_get' : [ '*' ] } , } ) labels_to_get = [ "label_tags_datadoghq_com_env" , "label_tags_datadoghq_com_service" , "label_tags_datadoghq_com_version" , ] if join_standard_tags : ksm_instance [ 'label_joins' ] . update ( { "kube_pod_labels" : { "labels_to_match" : [ "pod" , "namespace" ] , "labels_to_get" : labels_to_get } , "kube_deployment_labels" : { "labels_to_match" : [ "deployment" , "namespace" ] , "labels_to_get" : labels_to_get , } , "kube_replicaset_labels" : { "labels_to_match" : [ "replicaset" , "namespace" ] , "labels_to_get" : labels_to_get , } , "kube_daemonset_labels" : { "labels_to_match" : [ "daemonset" , "namespace" ] , "labels_to_get" : labels_to_get , } , "kube_statefulset_labels" : { "labels_to_match" : [ "statefulset" , "namespace" ] , "labels_to_get" : labels_to_get , } , "kube_job_labels" : { "labels_to_match" : [ "job_name" , "namespace" ] , "labels_to_get" : labels_to_get } , } ) ksm_instance . setdefault ( "labels_mapper" , { } ) . update ( { "label_tags_datadoghq_com_env" : "env" , "label_tags_datadoghq_com_service" : "service" , "label_tags_datadoghq_com_version" : "version" , } ) ksm_instance [ 'label_joins' ] . update ( extra_labels ) if hostname_override : ksm_instance [ 'label_to_hostname' ] = 'node' clustername = get_clustername ( ) if clustername != "" : # some cluster names are not valid RFC1123, but as we use them as a hostAlias we want them to be valid. clustername = clustername . replace ( "_" , "-" ) ksm_instance [ 'label_to_hostname_suffix' ] = "-" + clustername if 'labels_mapper' in ksm_instance and not isinstance ( ksm_instance [ 'labels_mapper' ] , dict ) : self . log . warning ( "Option labels_mapper should be a dictionary for %s" , endpoint ) return ksm_instance