(self, metric, scraper_config, metric_transformers=None)
Handle a Prometheus metric according to the following flow:
        - search `scraper_config['metrics_mapper']` for a prometheus.metric to datadog.metric mapping
        - call check method with the same name as the metric
        - log info if none of the above worked

        `metric_transformers` is a dict of `<metric name>:<function to run when the metric name is encountered>`
Handle a Prometheus metric according to the following flow:
        - search `scraper_config['metrics_mapper']` for a prometheus.metric to datadog.metric mapping
        - call check method with the same name as the metric
        - log info if none of the above worked
Handle a Prometheus metric according to the following flow : - search scraper_config [ metrics_mapper ] for a prometheus . metric to datadog . metric mapping - call check method with the same name as the metric - log info if none of the above worked
def process_metric(self, metric, scraper_config, metric_transformers=None):
        """
        Handle a Prometheus metric according to the following flow:
        - search `scraper_config['metrics_mapper']` for a prometheus.metric to datadog.metric mapping
        - call check method with the same name as the metric
        - log info if none of the above worked

        `metric_transformers` is a dict of `<metric name>:<function to run when the metric name is encountered>`
        """
        # If targeted metric, store labels
        self._store_labels(metric, scraper_config)

        if scraper_config['ignore_metrics']:
            if metric.name in scraper_config['_ignored_metrics']:
                self._send_telemetry_counter(
                    self.TELEMETRY_COUNTER_METRICS_IGNORE_COUNT, len(metric.samples), scraper_config
                )
                return  # Ignore the metric

            if scraper_config['_ignored_re'] and scraper_config['_ignored_re'].search(metric.name):
                # Metric must be ignored
                scraper_config['_ignored_metrics'].add(metric.name)
                self._send_telemetry_counter(
                    self.TELEMETRY_COUNTER_METRICS_IGNORE_COUNT, len(metric.samples), scraper_config
                )
                return  # Ignore the metric

        self._send_telemetry_counter(self.TELEMETRY_COUNTER_METRICS_PROCESS_COUNT, len(metric.samples), scraper_config)

        if self._filter_metric(metric, scraper_config):
            return  # Ignore the metric

        # Filter metric to see if we can enrich with joined labels
        self._join_labels(metric, scraper_config)

        if scraper_config['_dry_run']:
            return

        try:
            self.submit_openmetric(scraper_config['metrics_mapper'][metric.name], metric, scraper_config)
        except KeyError:
            if metric_transformers is not None and metric.name in metric_transformers:
                try:
                    # Get the transformer function for this specific metric
                    transformer = metric_transformers[metric.name]
                    transformer(metric, scraper_config)
                except Exception as err:
                    self.log.warning('Error handling metric: %s - error: %s', metric.name, err)

                return
            # check for wildcards in transformers
            for transformer_name, transformer in iteritems(metric_transformers):
                if transformer_name.endswith('*') and metric.name.startswith(transformer_name[:-1]):
                    transformer(metric, scraper_config, transformer_name)

            # try matching wildcards
            if scraper_config['_wildcards_re'] and scraper_config['_wildcards_re'].search(metric.name):
                self.submit_openmetric(metric.name, metric, scraper_config)
                return

            self.log.debug(
                'Skipping metric `%s` as it is not defined in the metrics mapper, '
                'has no transformer function, nor does it match any wildcards.',
                metric.name,
            )
def process_metric ( self , metric , scraper_config , metric_transformers = None ) : # If targeted metric, store labels self . _store_labels ( metric , scraper_config ) if scraper_config [ 'ignore_metrics' ] : if metric . name in scraper_config [ '_ignored_metrics' ] : self . _send_telemetry_counter ( self . TELEMETRY_COUNTER_METRICS_IGNORE_COUNT , len ( metric . samples ) , scraper_config ) return # Ignore the metric if scraper_config [ '_ignored_re' ] and scraper_config [ '_ignored_re' ] . search ( metric . name ) : # Metric must be ignored scraper_config [ '_ignored_metrics' ] . add ( metric . name ) self . _send_telemetry_counter ( self . TELEMETRY_COUNTER_METRICS_IGNORE_COUNT , len ( metric . samples ) , scraper_config ) return # Ignore the metric self . _send_telemetry_counter ( self . TELEMETRY_COUNTER_METRICS_PROCESS_COUNT , len ( metric . samples ) , scraper_config ) if self . _filter_metric ( metric , scraper_config ) : return # Ignore the metric # Filter metric to see if we can enrich with joined labels self . _join_labels ( metric , scraper_config ) if scraper_config [ '_dry_run' ] : return try : self . submit_openmetric ( scraper_config [ 'metrics_mapper' ] [ metric . name ] , metric , scraper_config ) except KeyError : if metric_transformers is not None and metric . name in metric_transformers : try : # Get the transformer function for this specific metric transformer = metric_transformers [ metric . name ] transformer ( metric , scraper_config ) except Exception as err : self . log . warning ( 'Error handling metric: %s - error: %s' , metric . name , err ) return # check for wildcards in transformers for transformer_name , transformer in iteritems ( metric_transformers ) : if transformer_name . endswith ( '*' ) and metric . name . startswith ( transformer_name [ : - 1 ] ) : transformer ( metric , scraper_config , transformer_name ) # try matching wildcards if scraper_config [ '_wildcards_re' ] and scraper_config [ '_wildcards_re' ] . search ( metric . name ) : self . submit_openmetric ( metric . name , metric , scraper_config ) return self . log . debug ( 'Skipping metric `%s` as it is not defined in the metrics mapper, ' 'has no transformer function, nor does it match any wildcards.' , metric . name , )