func SetMetricPathForOneInput()

in translator/setMetricPath.go [92:164]


func SetMetricPathForOneInput(result map[string]interface{}, sectionKey, inputPlugin string, processorPlugins []string) {
	routingTagVal := sectionKey + linkedCharacter + inputPlugin
	if i, ok := result[inputPluginKey]; ok {
		inputs := i.(map[string]interface{})
		for k, v := range inputs {
			if k != inputPlugin {
				continue
			}
			inputArray := v.([]interface{})
			for _, inputIntf := range inputArray {
				input := inputIntf.(map[string]interface{})
				if val, ok := input[tagKey]; ok {
					tags := val.(map[string]interface{})
					tags[routingTagKey] = routingTagVal
				} else {
					input[tagKey] = map[string]interface{}{routingTagKey: routingTagVal}
				}
			}

		}
	}

	if p, ok := result[processorPluginKey]; ok {
		processors := p.(map[string]interface{})
		for k, v := range processors {
			if !contains(processorPlugins, k) {
				continue
			}
			processorArray := v.([]interface{})
			for _, processorIntf := range processorArray {
				processor := processorIntf.(map[string]interface{})
				if val, ok := processor[tagPassKey]; ok {
					tagPass := val.(map[string][]string)
					if tags, ok := tagPass[routingTagKey]; ok {
						tagPass[routingTagKey] = append(tags, routingTagVal)
					} else {
						tagPass[routingTagKey] = []string{routingTagVal}
					}
				} else {
					processor[tagPassKey] = map[string][]string{routingTagKey: {routingTagVal}}
				}
			}
		}
	}

	if o, ok := result[outputPluginKey]; ok {
		outputs := o.(map[string]interface{})
		for _, v := range outputs {
			outputArray := v.([]interface{})
			for _, outputIntf := range outputArray {
				output := outputIntf.(map[string]interface{})
				if val, ok := output[tagPassKey]; ok {
					tagPass := val.(map[string][]string)
					if tags, ok := tagPass[routingTagKey]; ok {
						tagPass[routingTagKey] = append(tags, routingTagVal)
					} else {
						tagPass[routingTagKey] = []string{routingTagVal}
					}
				} else {
					output[tagPassKey] = map[string][]string{routingTagKey: {routingTagVal}}
				}
				if val, ok := output[tagExcludeKey]; ok {
					tagExclude := val.([]string)
					if !contains(tagExclude, routingTagKey) {
						output[tagExcludeKey] = append(tagExclude, routingTagKey)
					}
				} else {
					output[tagExcludeKey] = []string{routingTagKey}
				}
			}
		}
	}
}