(self, instance=None)
return config
Creates a scraper configuration.

        If instance does not specify a value for a configuration option, the value will default to the `init_config`.
        Otherwise, the `default_instance` value will be used.

        A default mixin configuration will be returned if there is no instance.
Creates a scraper configuration.
Creates a scraper configuration .
def create_scraper_configuration(self, instance=None):
        """
        Creates a scraper configuration.

        If instance does not specify a value for a configuration option, the value will default to the `init_config`.
        Otherwise, the `default_instance` value will be used.

        A default mixin configuration will be returned if there is no instance.
        """
        if 'openmetrics_endpoint' in instance:
            raise CheckException('The setting `openmetrics_endpoint` is only available for Agent version 7 or later')

        # We can choose to create a default mixin configuration for an empty instance
        if instance is None:
            instance = {}

        # Supports new configuration options
        config = copy.deepcopy(instance)

        # Set the endpoint
        endpoint = instance.get('prometheus_url')
        if instance and endpoint is None:
            raise CheckException("You have to define a prometheus_url for each prometheus instance")

        config['prometheus_url'] = endpoint

        # `NAMESPACE` is the prefix metrics will have. Need to be hardcoded in the
        # child check class.
        namespace = instance.get('namespace')
        # Check if we have a namespace
        if instance and namespace is None:
            if self.default_namespace is None:
                raise CheckException("You have to define a namespace for each prometheus check")
            namespace = self.default_namespace

        config['namespace'] = namespace

        # Retrieve potential default instance settings for the namespace
        default_instance = self.default_instances.get(namespace, {})

        def _get_setting(name, default):
            return instance.get(name, default_instance.get(name, default))

        # `metrics_mapper` is a dictionary where the keys are the metrics to capture
        # and the values are the corresponding metrics names to have in datadog.
        # Note: it is empty in the parent class but will need to be
        # overloaded/hardcoded in the final check not to be counted as custom metric.

        # Metrics are preprocessed if no mapping
        metrics_mapper = {}
        # We merge list and dictionaries from optional defaults & instance settings
        metrics = default_instance.get('metrics', []) + instance.get('metrics', [])
        for metric in metrics:
            if isinstance(metric, string_types):
                metrics_mapper[metric] = metric
            else:
                metrics_mapper.update(metric)

        config['metrics_mapper'] = metrics_mapper

        # `_wildcards_re` is a Pattern object used to match metric wildcards
        config['_wildcards_re'] = None

        wildcards = set()
        for metric in config['metrics_mapper']:
            if "*" in metric:
                wildcards.add(translate(metric))

        if wildcards:
            config['_wildcards_re'] = compile('|'.join(wildcards))

        # `prometheus_metrics_prefix` allows to specify a prefix that all
        # prometheus metrics should have. This can be used when the prometheus
        # endpoint we are scrapping allows to add a custom prefix to it's
        # metrics.
        config['prometheus_metrics_prefix'] = instance.get(
            'prometheus_metrics_prefix', default_instance.get('prometheus_metrics_prefix', '')
        )

        # `label_joins` holds the configuration for extracting 1:1 labels from
        # a target metric to all metric matching the label, example:
        # self.label_joins = {
        #     'kube_pod_info': {
        #         'labels_to_match': ['pod'],
        #         'labels_to_get': ['node', 'host_ip']
        #     }
        # }
        config['label_joins'] = default_instance.get('label_joins', {})
        config['label_joins'].update(instance.get('label_joins', {}))

        # `_label_mapping` holds the additionals label info to add for a specific
        # label value, example:
        # self._label_mapping = {
        #     'pod': {
        #         'dd-agent-9s1l1': {
        #             "node": "yolo",
        #             "host_ip": "yey"
        #         }
        #     }
        # }
        config['_label_mapping'] = {}

        # `_active_label_mapping` holds a dictionary of label values found during the run
        # to cleanup the label_mapping of unused values, example:
        # self._active_label_mapping = {
        #     'pod': {
        #         'dd-agent-9s1l1': True
        #     }
        # }
        config['_active_label_mapping'] = {}

        # `_watched_labels` holds the sets of labels to watch for enrichment
        config['_watched_labels'] = {}

        config['_dry_run'] = True

        # Some metrics are ignored because they are duplicates or introduce a
        # very high cardinality. Metrics included in this list will be silently
        # skipped without a 'Unable to handle metric' debug line in the logs
        config['ignore_metrics'] = instance.get('ignore_metrics', default_instance.get('ignore_metrics', []))
        config['_ignored_metrics'] = set()

        # `_ignored_re` is a Pattern object used to match ignored metric patterns
        config['_ignored_re'] = None
        ignored_patterns = set()

        # Separate ignored metric names and ignored patterns in different sets for faster lookup later
        for metric in config['ignore_metrics']:
            if '*' in metric:
                ignored_patterns.add(translate(metric))
            else:
                config['_ignored_metrics'].add(metric)

        if ignored_patterns:
            config['_ignored_re'] = compile('|'.join(ignored_patterns))

        # Ignore metrics based on label keys or specific label values
        config['ignore_metrics_by_labels'] = instance.get(
            'ignore_metrics_by_labels', default_instance.get('ignore_metrics_by_labels', {})
        )

        # If you want to send the buckets as tagged values when dealing with histograms,
        # set send_histograms_buckets to True, set to False otherwise.
        config['send_histograms_buckets'] = is_affirmative(
            instance.get('send_histograms_buckets', default_instance.get('send_histograms_buckets', True))
        )

        # If you want the bucket to be non cumulative and to come with upper/lower bound tags
        # set non_cumulative_buckets to True, enabled when distribution metrics are enabled.
        config['non_cumulative_buckets'] = is_affirmative(
            instance.get('non_cumulative_buckets', default_instance.get('non_cumulative_buckets', False))
        )

        # Send histograms as datadog distribution metrics
        config['send_distribution_buckets'] = is_affirmative(
            instance.get('send_distribution_buckets', default_instance.get('send_distribution_buckets', False))
        )

        # Non cumulative buckets are mandatory for distribution metrics
        if config['send_distribution_buckets'] is True:
            config['non_cumulative_buckets'] = True

        # If you want to send `counter` metrics as monotonic counts, set this value to True.
        # Set to False if you want to instead send those metrics as `gauge`.
        config['send_monotonic_counter'] = is_affirmative(
            instance.get('send_monotonic_counter', default_instance.get('send_monotonic_counter', True))
        )

        # If you want `counter` metrics to be submitted as both gauges and monotonic counts. Set this value to True.
        config['send_monotonic_with_gauge'] = is_affirmative(
            instance.get('send_monotonic_with_gauge', default_instance.get('send_monotonic_with_gauge', False))
        )

        config['send_distribution_counts_as_monotonic'] = is_affirmative(
            instance.get(
                'send_distribution_counts_as_monotonic',
                default_instance.get('send_distribution_counts_as_monotonic', False),
            )
        )

        config['send_distribution_sums_as_monotonic'] = is_affirmative(
            instance.get(
                'send_distribution_sums_as_monotonic',
                default_instance.get('send_distribution_sums_as_monotonic', False),
            )
        )

        # If the `labels_mapper` dictionary is provided, the metrics labels names
        # in the `labels_mapper` will use the corresponding value as tag name
        # when sending the gauges.
        config['labels_mapper'] = default_instance.get('labels_mapper', {})
        config['labels_mapper'].update(instance.get('labels_mapper', {}))
        # Rename bucket "le" label to "upper_bound"
        config['labels_mapper']['le'] = 'upper_bound'

        # `exclude_labels` is an array of label names to exclude. Those labels
        # will just not be added as tags when submitting the metric.
        config['exclude_labels'] = default_instance.get('exclude_labels', []) + instance.get('exclude_labels', [])

        # `include_labels` is an array of label names to include. If these labels are not in
        # the `exclude_labels` list, then they are added as tags when submitting the metric.
        config['include_labels'] = default_instance.get('include_labels', []) + instance.get('include_labels', [])

        # `type_overrides` is a dictionary where the keys are prometheus metric names
        # and the values are a metric type (name as string) to use instead of the one
        # listed in the payload. It can be used to force a type on untyped metrics.
        # Note: it is empty in the parent class but will need to be
        # overloaded/hardcoded in the final check not to be counted as custom metric.
        config['type_overrides'] = default_instance.get('type_overrides', {})
        config['type_overrides'].update(instance.get('type_overrides', {}))

        # `_type_override_patterns` is a dictionary where we store Pattern objects
        # that match metric names as keys, and their corresponding metric type overrides as values.
        config['_type_override_patterns'] = {}

        with_wildcards = set()
        for metric, type in iteritems(config['type_overrides']):
            if '*' in metric:
                config['_type_override_patterns'][compile(translate(metric))] = type
                with_wildcards.add(metric)

        # cleanup metric names with wildcards from the 'type_overrides' dict
        for metric in with_wildcards:
            del config['type_overrides'][metric]

        # Some metrics are retrieved from different hosts and often
        # a label can hold this information, this transfers it to the hostname
        config['label_to_hostname'] = instance.get('label_to_hostname', default_instance.get('label_to_hostname', None))

        # In combination to label_as_hostname, allows to add a common suffix to the hostnames
        # submitted. This can be used for instance to discriminate hosts between clusters.
        config['label_to_hostname_suffix'] = instance.get(
            'label_to_hostname_suffix', default_instance.get('label_to_hostname_suffix', None)
        )

        # Add a 'health' service check for the prometheus endpoint
        config['health_service_check'] = is_affirmative(
            instance.get('health_service_check', default_instance.get('health_service_check', True))
        )

        # Can either be only the path to the certificate and thus you should specify the private key
        # or it can be the path to a file containing both the certificate & the private key
        config['ssl_cert'] = instance.get('ssl_cert', default_instance.get('ssl_cert', None))

        # Needed if the certificate does not include the private key
        #
        # /!\ The private key to your local certificate must be unencrypted.
        # Currently, Requests does not support using encrypted keys.
        config['ssl_private_key'] = instance.get('ssl_private_key', default_instance.get('ssl_private_key', None))

        # The path to the trusted CA used for generating custom certificates
        config['ssl_ca_cert'] = instance.get('ssl_ca_cert', default_instance.get('ssl_ca_cert', None))

        # Whether or not to validate SSL certificates
        config['ssl_verify'] = is_affirmative(instance.get('ssl_verify', default_instance.get('ssl_verify', True)))

        # Extra http headers to be sent when polling endpoint
        config['extra_headers'] = default_instance.get('extra_headers', {})
        config['extra_headers'].update(instance.get('extra_headers', {}))

        # Timeout used during the network request
        config['prometheus_timeout'] = instance.get(
            'prometheus_timeout', default_instance.get('prometheus_timeout', 10)
        )

        # Authentication used when polling endpoint
        config['username'] = instance.get('username', default_instance.get('username', None))
        config['password'] = instance.get('password', default_instance.get('password', None))

        # Custom tags that will be sent with each metric
        config['custom_tags'] = instance.get('tags', [])

        # Some tags can be ignored to reduce the cardinality.
        # This can be useful for cost optimization in containerized environments
        # when the openmetrics check is configured to collect custom metrics.
        # Even when the Agent's Tagger is configured to add low-cardinality tags only,
        # some tags can still generate unwanted metric contexts (e.g pod annotations as tags).
        ignore_tags = instance.get('ignore_tags', default_instance.get('ignore_tags', []))
        if ignore_tags:
            ignored_tags_re = compile('|'.join(set(ignore_tags)))
            config['custom_tags'] = [tag for tag in config['custom_tags'] if not ignored_tags_re.search(tag)]

        # Additional tags to be sent with each metric
        config['_metric_tags'] = []

        # List of strings to filter the input text payload on. If any line contains
        # one of these strings, it will be filtered out before being parsed.
        # INTERNAL FEATURE, might be removed in future versions
        config['_text_filter_blacklist'] = []

        # Whether or not to use the service account bearer token for authentication.
        # Can be explicitly set to true or false to send or not the bearer token.
        # If set to the `tls_only` value, the bearer token will be sent only to https endpoints.
        # If 'bearer_token_path' is not set, we use /var/run/secrets/kubernetes.io/serviceaccount/token
        # as a default path to get the token.
        bearer_token_auth = _get_setting('bearer_token_auth', False)
        if bearer_token_auth == 'tls_only':
            config['bearer_token_auth'] = config['prometheus_url'].startswith("https://")
        else:
            config['bearer_token_auth'] = is_affirmative(bearer_token_auth)

        # Can be used to get a service account bearer token from files
        # other than /var/run/secrets/kubernetes.io/serviceaccount/token
        # 'bearer_token_auth' should be enabled.
        config['bearer_token_path'] = instance.get('bearer_token_path', default_instance.get('bearer_token_path', None))

        # The service account bearer token to be used for authentication
        config['_bearer_token'] = self._get_bearer_token(config['bearer_token_auth'], config['bearer_token_path'])

        config['telemetry'] = is_affirmative(instance.get('telemetry', default_instance.get('telemetry', False)))

        # The metric name services use to indicate build information
        config['metadata_metric_name'] = instance.get(
            'metadata_metric_name', default_instance.get('metadata_metric_name')
        )

        # Map of metadata key names to label names
        config['metadata_label_map'] = instance.get(
            'metadata_label_map', default_instance.get('metadata_label_map', {})
        )

        config['_default_metric_transformers'] = {}
        if config['metadata_metric_name'] and config['metadata_label_map']:
            config['_default_metric_transformers'][config['metadata_metric_name']] = self.transform_metadata

        # Whether or not to enable flushing of the first value of monotonic counts
        config['_flush_first_value'] = False

        # Whether to use process_start_time_seconds to decide if counter-like values should  be flushed
        # on first scrape.
        config['use_process_start_time'] = is_affirmative(_get_setting('use_process_start_time', False))

        return config
def create_scraper_configuration ( self , instance = None ) : if 'openmetrics_endpoint' in instance : raise CheckException ( 'The setting `openmetrics_endpoint` is only available for Agent version 7 or later' ) # We can choose to create a default mixin configuration for an empty instance if instance is None : instance = { } # Supports new configuration options config = copy . deepcopy ( instance ) # Set the endpoint endpoint = instance . get ( 'prometheus_url' ) if instance and endpoint is None : raise CheckException ( "You have to define a prometheus_url for each prometheus instance" ) config [ 'prometheus_url' ] = endpoint # `NAMESPACE` is the prefix metrics will have. Need to be hardcoded in the # child check class. namespace = instance . get ( 'namespace' ) # Check if we have a namespace if instance and namespace is None : if self . default_namespace is None : raise CheckException ( "You have to define a namespace for each prometheus check" ) namespace = self . default_namespace config [ 'namespace' ] = namespace # Retrieve potential default instance settings for the namespace default_instance = self . default_instances . get ( namespace , { } ) def _get_setting ( name , default ) : return instance . get ( name , default_instance . get ( name , default ) ) # `metrics_mapper` is a dictionary where the keys are the metrics to capture # and the values are the corresponding metrics names to have in datadog. # Note: it is empty in the parent class but will need to be # overloaded/hardcoded in the final check not to be counted as custom metric. # Metrics are preprocessed if no mapping metrics_mapper = { } # We merge list and dictionaries from optional defaults & instance settings metrics = default_instance . get ( 'metrics' , [ ] ) + instance . get ( 'metrics' , [ ] ) for metric in metrics : if isinstance ( metric , string_types ) : metrics_mapper [ metric ] = metric else : metrics_mapper . update ( metric ) config [ 'metrics_mapper' ] = metrics_mapper # `_wildcards_re` is a Pattern object used to match metric wildcards config [ '_wildcards_re' ] = None wildcards = set ( ) for metric in config [ 'metrics_mapper' ] : if "*" in metric : wildcards . add ( translate ( metric ) ) if wildcards : config [ '_wildcards_re' ] = compile ( '|' . join ( wildcards ) ) # `prometheus_metrics_prefix` allows to specify a prefix that all # prometheus metrics should have. This can be used when the prometheus # endpoint we are scrapping allows to add a custom prefix to it's # metrics. config [ 'prometheus_metrics_prefix' ] = instance . get ( 'prometheus_metrics_prefix' , default_instance . get ( 'prometheus_metrics_prefix' , '' ) ) # `label_joins` holds the configuration for extracting 1:1 labels from # a target metric to all metric matching the label, example: # self.label_joins = { #     'kube_pod_info': { #         'labels_to_match': ['pod'], #         'labels_to_get': ['node', 'host_ip'] #     } # } config [ 'label_joins' ] = default_instance . get ( 'label_joins' , { } ) config [ 'label_joins' ] . update ( instance . get ( 'label_joins' , { } ) ) # `_label_mapping` holds the additionals label info to add for a specific # label value, example: # self._label_mapping = { #     'pod': { #         'dd-agent-9s1l1': { #             "node": "yolo", #             "host_ip": "yey" #         } #     } # } config [ '_label_mapping' ] = { } # `_active_label_mapping` holds a dictionary of label values found during the run # to cleanup the label_mapping of unused values, example: # self._active_label_mapping = { #     'pod': { #         'dd-agent-9s1l1': True #     } # } config [ '_active_label_mapping' ] = { } # `_watched_labels` holds the sets of labels to watch for enrichment config [ '_watched_labels' ] = { } config [ '_dry_run' ] = True # Some metrics are ignored because they are duplicates or introduce a # very high cardinality. Metrics included in this list will be silently # skipped without a 'Unable to handle metric' debug line in the logs config [ 'ignore_metrics' ] = instance . get ( 'ignore_metrics' , default_instance . get ( 'ignore_metrics' , [ ] ) ) config [ '_ignored_metrics' ] = set ( ) # `_ignored_re` is a Pattern object used to match ignored metric patterns config [ '_ignored_re' ] = None ignored_patterns = set ( ) # Separate ignored metric names and ignored patterns in different sets for faster lookup later for metric in config [ 'ignore_metrics' ] : if '*' in metric : ignored_patterns . add ( translate ( metric ) ) else : config [ '_ignored_metrics' ] . add ( metric ) if ignored_patterns : config [ '_ignored_re' ] = compile ( '|' . join ( ignored_patterns ) ) # Ignore metrics based on label keys or specific label values config [ 'ignore_metrics_by_labels' ] = instance . get ( 'ignore_metrics_by_labels' , default_instance . get ( 'ignore_metrics_by_labels' , { } ) ) # If you want to send the buckets as tagged values when dealing with histograms, # set send_histograms_buckets to True, set to False otherwise. config [ 'send_histograms_buckets' ] = is_affirmative ( instance . get ( 'send_histograms_buckets' , default_instance . get ( 'send_histograms_buckets' , True ) ) ) # If you want the bucket to be non cumulative and to come with upper/lower bound tags # set non_cumulative_buckets to True, enabled when distribution metrics are enabled. config [ 'non_cumulative_buckets' ] = is_affirmative ( instance . get ( 'non_cumulative_buckets' , default_instance . get ( 'non_cumulative_buckets' , False ) ) ) # Send histograms as datadog distribution metrics config [ 'send_distribution_buckets' ] = is_affirmative ( instance . get ( 'send_distribution_buckets' , default_instance . get ( 'send_distribution_buckets' , False ) ) ) # Non cumulative buckets are mandatory for distribution metrics if config [ 'send_distribution_buckets' ] is True : config [ 'non_cumulative_buckets' ] = True # If you want to send `counter` metrics as monotonic counts, set this value to True. # Set to False if you want to instead send those metrics as `gauge`. config [ 'send_monotonic_counter' ] = is_affirmative ( instance . get ( 'send_monotonic_counter' , default_instance . get ( 'send_monotonic_counter' , True ) ) ) # If you want `counter` metrics to be submitted as both gauges and monotonic counts. Set this value to True. config [ 'send_monotonic_with_gauge' ] = is_affirmative ( instance . get ( 'send_monotonic_with_gauge' , default_instance . get ( 'send_monotonic_with_gauge' , False ) ) ) config [ 'send_distribution_counts_as_monotonic' ] = is_affirmative ( instance . get ( 'send_distribution_counts_as_monotonic' , default_instance . get ( 'send_distribution_counts_as_monotonic' , False ) , ) ) config [ 'send_distribution_sums_as_monotonic' ] = is_affirmative ( instance . get ( 'send_distribution_sums_as_monotonic' , default_instance . get ( 'send_distribution_sums_as_monotonic' , False ) , ) ) # If the `labels_mapper` dictionary is provided, the metrics labels names # in the `labels_mapper` will use the corresponding value as tag name # when sending the gauges. config [ 'labels_mapper' ] = default_instance . get ( 'labels_mapper' , { } ) config [ 'labels_mapper' ] . update ( instance . get ( 'labels_mapper' , { } ) ) # Rename bucket "le" label to "upper_bound" config [ 'labels_mapper' ] [ 'le' ] = 'upper_bound' # `exclude_labels` is an array of label names to exclude. Those labels # will just not be added as tags when submitting the metric. config [ 'exclude_labels' ] = default_instance . get ( 'exclude_labels' , [ ] ) + instance . get ( 'exclude_labels' , [ ] ) # `include_labels` is an array of label names to include. If these labels are not in # the `exclude_labels` list, then they are added as tags when submitting the metric. config [ 'include_labels' ] = default_instance . get ( 'include_labels' , [ ] ) + instance . get ( 'include_labels' , [ ] ) # `type_overrides` is a dictionary where the keys are prometheus metric names # and the values are a metric type (name as string) to use instead of the one # listed in the payload. It can be used to force a type on untyped metrics. # Note: it is empty in the parent class but will need to be # overloaded/hardcoded in the final check not to be counted as custom metric. config [ 'type_overrides' ] = default_instance . get ( 'type_overrides' , { } ) config [ 'type_overrides' ] . update ( instance . get ( 'type_overrides' , { } ) ) # `_type_override_patterns` is a dictionary where we store Pattern objects # that match metric names as keys, and their corresponding metric type overrides as values. config [ '_type_override_patterns' ] = { } with_wildcards = set ( ) for metric , type in iteritems ( config [ 'type_overrides' ] ) : if '*' in metric : config [ '_type_override_patterns' ] [ compile ( translate ( metric ) ) ] = type with_wildcards . add ( metric ) # cleanup metric names with wildcards from the 'type_overrides' dict for metric in with_wildcards : del config [ 'type_overrides' ] [ metric ] # Some metrics are retrieved from different hosts and often # a label can hold this information, this transfers it to the hostname config [ 'label_to_hostname' ] = instance . get ( 'label_to_hostname' , default_instance . get ( 'label_to_hostname' , None ) ) # In combination to label_as_hostname, allows to add a common suffix to the hostnames # submitted. This can be used for instance to discriminate hosts between clusters. config [ 'label_to_hostname_suffix' ] = instance . get ( 'label_to_hostname_suffix' , default_instance . get ( 'label_to_hostname_suffix' , None ) ) # Add a 'health' service check for the prometheus endpoint config [ 'health_service_check' ] = is_affirmative ( instance . get ( 'health_service_check' , default_instance . get ( 'health_service_check' , True ) ) ) # Can either be only the path to the certificate and thus you should specify the private key # or it can be the path to a file containing both the certificate & the private key config [ 'ssl_cert' ] = instance . get ( 'ssl_cert' , default_instance . get ( 'ssl_cert' , None ) ) # Needed if the certificate does not include the private key # # /!\ The private key to your local certificate must be unencrypted. # Currently, Requests does not support using encrypted keys. config [ 'ssl_private_key' ] = instance . get ( 'ssl_private_key' , default_instance . get ( 'ssl_private_key' , None ) ) # The path to the trusted CA used for generating custom certificates config [ 'ssl_ca_cert' ] = instance . get ( 'ssl_ca_cert' , default_instance . get ( 'ssl_ca_cert' , None ) ) # Whether or not to validate SSL certificates config [ 'ssl_verify' ] = is_affirmative ( instance . get ( 'ssl_verify' , default_instance . get ( 'ssl_verify' , True ) ) ) # Extra http headers to be sent when polling endpoint config [ 'extra_headers' ] = default_instance . get ( 'extra_headers' , { } ) config [ 'extra_headers' ] . update ( instance . get ( 'extra_headers' , { } ) ) # Timeout used during the network request config [ 'prometheus_timeout' ] = instance . get ( 'prometheus_timeout' , default_instance . get ( 'prometheus_timeout' , 10 ) ) # Authentication used when polling endpoint config [ 'username' ] = instance . get ( 'username' , default_instance . get ( 'username' , None ) ) config [ 'password' ] = instance . get ( 'password' , default_instance . get ( 'password' , None ) ) # Custom tags that will be sent with each metric config [ 'custom_tags' ] = instance . get ( 'tags' , [ ] ) # Some tags can be ignored to reduce the cardinality. # This can be useful for cost optimization in containerized environments # when the openmetrics check is configured to collect custom metrics. # Even when the Agent's Tagger is configured to add low-cardinality tags only, # some tags can still generate unwanted metric contexts (e.g pod annotations as tags). ignore_tags = instance . get ( 'ignore_tags' , default_instance . get ( 'ignore_tags' , [ ] ) ) if ignore_tags : ignored_tags_re = compile ( '|' . join ( set ( ignore_tags ) ) ) config [ 'custom_tags' ] = [ tag for tag in config [ 'custom_tags' ] if not ignored_tags_re . search ( tag ) ] # Additional tags to be sent with each metric config [ '_metric_tags' ] = [ ] # List of strings to filter the input text payload on. If any line contains # one of these strings, it will be filtered out before being parsed. # INTERNAL FEATURE, might be removed in future versions config [ '_text_filter_blacklist' ] = [ ] # Whether or not to use the service account bearer token for authentication. # Can be explicitly set to true or false to send or not the bearer token. # If set to the `tls_only` value, the bearer token will be sent only to https endpoints. # If 'bearer_token_path' is not set, we use /var/run/secrets/kubernetes.io/serviceaccount/token # as a default path to get the token. bearer_token_auth = _get_setting ( 'bearer_token_auth' , False ) if bearer_token_auth == 'tls_only' : config [ 'bearer_token_auth' ] = config [ 'prometheus_url' ] . startswith ( "https://" ) else : config [ 'bearer_token_auth' ] = is_affirmative ( bearer_token_auth ) # Can be used to get a service account bearer token from files # other than /var/run/secrets/kubernetes.io/serviceaccount/token # 'bearer_token_auth' should be enabled. config [ 'bearer_token_path' ] = instance . get ( 'bearer_token_path' , default_instance . get ( 'bearer_token_path' , None ) ) # The service account bearer token to be used for authentication config [ '_bearer_token' ] = self . _get_bearer_token ( config [ 'bearer_token_auth' ] , config [ 'bearer_token_path' ] ) config [ 'telemetry' ] = is_affirmative ( instance . get ( 'telemetry' , default_instance . get ( 'telemetry' , False ) ) ) # The metric name services use to indicate build information config [ 'metadata_metric_name' ] = instance . get ( 'metadata_metric_name' , default_instance . get ( 'metadata_metric_name' ) ) # Map of metadata key names to label names config [ 'metadata_label_map' ] = instance . get ( 'metadata_label_map' , default_instance . get ( 'metadata_label_map' , { } ) ) config [ '_default_metric_transformers' ] = { } if config [ 'metadata_metric_name' ] and config [ 'metadata_label_map' ] : config [ '_default_metric_transformers' ] [ config [ 'metadata_metric_name' ] ] = self . transform_metadata # Whether or not to enable flushing of the first value of monotonic counts config [ '_flush_first_value' ] = False # Whether to use process_start_time_seconds to decide if counter-like values should  be flushed # on first scrape. config [ 'use_process_start_time' ] = is_affirmative ( _get_setting ( 'use_process_start_time' , False ) ) return config