def _join_labels(self, metric, scraper_config):
    if (not scraper_config['label_joins']):
        return
    label_mapping = scraper_config['_label_mapping']
    active_label_mapping = scraper_config['_active_label_mapping']
    watched = scraper_config['_watched_labels']
    sets = watched['sets']
    keys = watched['keys']
    singles = watched['singles']
    for sample in metric.samples:
        sample_labels = sample[self.SAMPLE_LABELS]
        sample_labels_keys = sample_labels.keys()
        if ('*' in singles):
            active_label_mapping.setdefault('*', {})['*'] = True
            if (('*' in label_mapping) and ('*' in label_mapping['*'])):
                sample_labels.update(label_mapping['*']['*'])
        matching_single_labels = singles.intersection(sample_labels_keys)
        for label in matching_single_labels:
            mapping_key = label
            mapping_value = sample_labels[label]
            active_label_mapping.setdefault(mapping_key, {})[mapping_value] = True
            if ((mapping_key in label_mapping) and (mapping_value in label_mapping[mapping_key])):
                sample_labels.update(label_mapping[mapping_key][mapping_value])
        for (key, mapping_key) in iteritems(keys):
            if (mapping_key in matching_single_labels):
                continue
            matching_labels = sets[key]
            if matching_labels.issubset(sample_labels_keys):
                matching_values = [sample_labels[l] for l in matching_labels]
                mapping_value = ','.join(matching_values)
                active_label_mapping.setdefault(mapping_key, {})[mapping_value] = True
                if ((mapping_key in label_mapping) and (mapping_value in label_mapping[mapping_key])):
                    sample_labels.update(label_mapping[mapping_key][mapping_value])
def _join_labels(self, metric, scraper_config):
    if (not scraper_config['label_joins']):
        return
    label_mapping = scraper_config['_label_mapping']
    active_label_mapping = scraper_config['_active_label_mapping']
    watched = scraper_config['_watched_labels']
    sets = watched['sets']
    keys = watched['keys']
    singles = watched['singles']
    for sample in metric.samples:
        sample_labels = sample[self.SAMPLE_LABELS]
        sample_labels_keys = sample_labels.keys()
        if ('*' in singles):
            active_label_mapping.setdefault('*', {})['*'] = True
            if (('*' in label_mapping) and ('*' in label_mapping['*'])):
                sample_labels.update(label_mapping['*']['*'])
        matching_single_labels = singles.intersection(sample_labels_keys)
        for label in matching_single_labels:
            mapping_key = label
            mapping_value = sample_labels[label]
            active_label_mapping.setdefault(mapping_key, {})[mapping_value] = True
            if ((mapping_key in label_mapping) and (mapping_value in label_mapping[mapping_key])):
                sample_labels.update(label_mapping[mapping_key][mapping_value])
        for (key, mapping_key) in iteritems(keys):
            if (mapping_key in matching_single_labels):
                continue
            matching_labels = sets[key]
            if matching_labels.issubset(sample_labels_keys):
                matching_values = [sample_labels[l] for l in matching_labels]
                mapping_value = ','.join(matching_values)
                active_label_mapping.setdefault(mapping_key, {})[mapping_value] = True
                if ((mapping_key in label_mapping) and (mapping_value in label_mapping[mapping_key])):
                    sample_labels.update(label_mapping[mapping_key][mapping_value])