checkmgr/metrics.go
func (cm *CheckManager) AddMetricTags(metricName string, tags []string, appendTags bool) bool {
	tagsUpdated := false

	if appendTags && len(tags) == 0 {
		return tagsUpdated
	}

	currentTags, exists := cm.metricTags[metricName]
	if !exists {
		foundMetric := false

		if cm.checkBundle != nil {
			for _, metric := range cm.checkBundle.Metrics {
				if metric.Name == metricName {
					foundMetric = true
					currentTags = metric.Tags
					break
				}
			}
		}

		if !foundMetric {
			currentTags = []string{}
		}
	}

	action := ""
	if appendTags {
		numNewTags := countNewTags(currentTags, tags)
		if numNewTags > 0 {
			action = "Added"
			currentTags = append(currentTags, tags...)
			tagsUpdated = true
		}
	} else {
		if len(tags) != len(currentTags) {
			action = "Set"
			currentTags = tags
			tagsUpdated = true
		} else {
			numNewTags := countNewTags(currentTags, tags)
			if numNewTags > 0 {
				action = "Set"
				currentTags = tags
				tagsUpdated = true
			}
		}
	}

	if tagsUpdated {
		cm.metricTags[metricName] = currentTags
	}

	if cm.Debug && action != "" {
		cm.Log.Printf("[DEBUG] %s metric tag(s) %s %v\n", action, metricName, tags)
	}

	return tagsUpdated
}
func (cm *CheckManager) AddMetricTags(metricName string, tags []string, appendTags bool) bool {
	tagsUpdated := false

	if appendTags && len(tags) == 0 {
		return tagsUpdated
	}

	currentTags, exists := cm.metricTags[metricName]
	if !exists {
		foundMetric := false

		if cm.checkBundle != nil {
			for _, metric := range cm.checkBundle.Metrics {
				if metric.Name == metricName {
					foundMetric = true
					currentTags = metric.Tags
					break
				}
			}
		}

		if !foundMetric {
			currentTags = []string{}
		}
	}

	action := ""
	if appendTags {
		numNewTags := countNewTags(currentTags, tags)
		if numNewTags > 0 {
			action = "Added"
			currentTags = append(currentTags, tags...)
			tagsUpdated = true
		}
	} else {
		if len(tags) != len(currentTags) {
			action = "Set"
			currentTags = tags
			tagsUpdated = true
		} else {
			numNewTags := countNewTags(currentTags, tags)
			if numNewTags > 0 {
				action = "Set"
				currentTags = tags
				tagsUpdated = true
			}
		}
	}

	if tagsUpdated {
		cm.metricTags[metricName] = currentTags
	}

	if cm.Debug && action != "" {
		cm.Log.Printf("[DEBUG] %s metric tag(s) %s %v\n", action, metricName, tags)
	}

	return tagsUpdated
}
// AddMetricTags updates check bundle metrics with tags