func()

in prometheus-to-sd/translator/metric_descriptor_cache.go [73:96]


func (cache *MetricDescriptorCache) ValidateMetricDescriptors(metrics map[string]*dto.MetricFamily, whitelisted []string) {
	// Perform cache operation only if cache was recently refreshed. This is done mostly from the optimization point
	// of view, we don't want to check all metric descriptors too often, as they should change rarely.
	if !cache.fresh {
		return
	}
	for _, metricFamily := range metrics {
		if !isMetricWhitelisted(metricFamily.GetName(), whitelisted) {
			continue
		}
		metricDescriptor, ok := cache.descriptors[metricFamily.GetName()]
		if !ok {
			continue
		}
		updatedMetricDescriptor := MetricFamilyToMetricDescriptor(cache.config, metricFamily, metricDescriptor)
		if descriptorLabelSetChanged(metricDescriptor, updatedMetricDescriptor) || descriptorMetricKindChanged(metricDescriptor, updatedMetricDescriptor) {
			cache.broken[metricFamily.GetName()] = true
			metricFamilyDropped.WithLabelValues(cache.config.SourceConfig.Component, metricFamily.GetName()).Set(1.0)
			glog.Warningf("Definition of the metric %s was changed and metric is not going to be pushed", metricFamily.GetName())
		} else {
			metricFamilyDropped.WithLabelValues(cache.config.SourceConfig.Component, metricFamily.GetName()).Set(0.0)
		}
	}
}