in translator/translate/logs/metrics_collected/metrics_collected.go [48:110]
func (c *CollectMetrics) ApplyRule(input interface{}) (returnKey string, returnVal interface{}) {
im := input.(map[string]interface{})
result := map[string]map[string]interface{}{}
inputs := map[string]interface{}{}
processors := map[string]interface{}{}
var targetRuleMap map[string]Rule
switch translator.GetTargetPlatform() {
case config.OS_TYPE_LINUX:
targetRuleMap = linuxMetricCollectRule
case config.OS_TYPE_DARWIN:
targetRuleMap = darwinMetricCollectRule
case config.OS_TYPE_WINDOWS:
targetRuleMap = windowsMetricCollectRule
default:
// NOTE: we should panic but now there are many unit tests not setting the global var
targetRuleMap = linuxMetricCollectRule
//panic("unknown target platform " + translator.GetTargetPlatform())
}
//Check if this plugin exist in the input instance
//If not, not process
if _, ok := im[SectionKey]; !ok {
returnKey = ""
returnVal = ""
} else {
//If yes, process it
featureInited := false // kubernetes, ecs, prometheus are mutually exclusive, use this flag to ensure only one feature could be turned on.
for _, rule := range getOrderedRules(targetRuleMap) {
key, val := rule.ApplyRule(im[SectionKey])
if key == "kubernetes" || key == "ecs" || key == "prometheus" {
if featureInited {
translator.AddErrorMessages(GetCurPath(), "Feature kubernetes, ecs, prometheus are mutually exclusive")
return
} else {
featureInited = true
}
if result, ok := val.(map[string]map[string]interface{}); ok {
if tmpInputs, ok := result["inputs"]; ok {
for k, v := range tmpInputs {
inputs[k] = v
}
}
if tmpProcessors, ok := result["processors"]; ok {
for k, v := range tmpProcessors {
processors[k] = v
}
}
}
} else {
if key != "" {
inputs[key] = val
}
}
}
}
result["inputs"] = inputs
result["processors"] = processors
returnKey = SectionKey
returnVal = result
return
}