(self, m_name, metric, cache, scraper_config, labels=None)
Takes a metric object, a metric name, and a cache dict where it will store
        container_name --> (value, tags) so that _process_limit_metric can compute usage_pct
        it also submit said value and tags as a gauge.
Takes a metric object, a metric name, and a cache dict where it will store
        container_name --> (value, tags) so that _process_limit_metric can compute usage_pct
        it also submit said value and tags as a gauge.
Takes a metric object a metric name and a cache dict where it will store container_name -- > ( value tags ) so that _process_limit_metric can compute usage_pct it also submit said value and tags as a gauge .
def _process_usage_metric(self, m_name, metric, cache, scraper_config, labels=None):
        """
        Takes a metric object, a metric name, and a cache dict where it will store
        container_name --> (value, tags) so that _process_limit_metric can compute usage_pct
        it also submit said value and tags as a gauge.
        """
        if labels is None:
            labels = []

        # track containers that still exist in the cache
        seen_keys = {k: False for k in cache}

        samples = self._sum_values_by_context(metric, self._get_entity_id_if_container_metric)
        for c_id, sample in iteritems(samples):
            c_name = self._get_container_label(sample[self.SAMPLE_LABELS], 'name')
            if not c_name:
                continue
            pod_uid = self._get_pod_uid(sample[self.SAMPLE_LABELS])
            if self.pod_list_utils.is_excluded(c_id, pod_uid):
                continue

            tags = tagger.tag(replace_container_rt_prefix(c_id), tagger.HIGH)
            if not tags:
                continue
            tags += scraper_config['custom_tags']

            # FIXME we are forced to do that because the Kubelet PodList isn't updated
            # for static pods, see https://github.com/kubernetes/kubernetes/pull/59948
            pod = self._get_pod_by_metric_label(sample[self.SAMPLE_LABELS])
            if pod is not None and is_static_pending_pod(pod):
                pod_tags = tagger.tag('kubernetes_pod_uid://%s' % pod["metadata"]["uid"], tagger.HIGH)
                if not pod_tags:
                    continue
                tags += pod_tags
                tags += self._get_kube_container_name(sample[self.SAMPLE_LABELS])
                tags = list(set(tags))

            for label in labels:
                value = sample[self.SAMPLE_LABELS].get(label)
                if value:
                    tags.append('%s:%s' % (label, value))

            val = sample[self.SAMPLE_VALUE]
            cache[c_name] = (val, tags)
            seen_keys[c_name] = True
            self.gauge(m_name, val, tags)

        # purge the cache
        for k, seen in iteritems(seen_keys):
            if not seen:
                del cache[k]
def _process_usage_metric ( self , m_name , metric , cache , scraper_config , labels = None ) : if labels is None : labels = [ ] # track containers that still exist in the cache seen_keys = { k : False for k in cache } samples = self . _sum_values_by_context ( metric , self . _get_entity_id_if_container_metric ) for c_id , sample in iteritems ( samples ) : c_name = self . _get_container_label ( sample [ self . SAMPLE_LABELS ] , 'name' ) if not c_name : continue pod_uid = self . _get_pod_uid ( sample [ self . SAMPLE_LABELS ] ) if self . pod_list_utils . is_excluded ( c_id , pod_uid ) : continue tags = tagger . tag ( replace_container_rt_prefix ( c_id ) , tagger . HIGH ) if not tags : continue tags += scraper_config [ 'custom_tags' ] # FIXME we are forced to do that because the Kubelet PodList isn't updated # for static pods, see https://github.com/kubernetes/kubernetes/pull/59948 pod = self . _get_pod_by_metric_label ( sample [ self . SAMPLE_LABELS ] ) if pod is not None and is_static_pending_pod ( pod ) : pod_tags = tagger . tag ( 'kubernetes_pod_uid://%s' % pod [ "metadata" ] [ "uid" ] , tagger . HIGH ) if not pod_tags : continue tags += pod_tags tags += self . _get_kube_container_name ( sample [ self . SAMPLE_LABELS ] ) tags = list ( set ( tags ) ) for label in labels : value = sample [ self . SAMPLE_LABELS ] . get ( label ) if value : tags . append ( '%s:%s' % ( label , value ) ) val = sample [ self . SAMPLE_VALUE ] cache [ c_name ] = ( val , tags ) seen_keys [ c_name ] = True self . gauge ( m_name , val , tags ) # purge the cache for k , seen in iteritems ( seen_keys ) : if not seen : del cache [ k ]