// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: MIT package prometheus import ( "github.com/aws/amazon-cloudwatch-agent/translator" "github.com/aws/amazon-cloudwatch-agent/translator/jsonconfig/mergeJsonRule" "github.com/aws/amazon-cloudwatch-agent/translator/jsonconfig/mergeJsonUtil" parent "github.com/aws/amazon-cloudwatch-agent/translator/translate/logs/metrics_collected" ) const SectionKey = "prometheus" type Rule translator.Rule var ChildRule = map[string]Rule{} type Prometheus struct { } func GetCurPath() string { curPath := parent.GetCurPath() + SectionKey + "/" return curPath } func RegisterRule(fieldname string, r Rule) { ChildRule[fieldname] = r } func (p *Prometheus) ApplyRule(input interface{}) (returnKey string, returnVal interface{}) { im := input.(map[string]interface{}) result := map[string]map[string]interface{}{} inputs := map[string]interface{}{} promScaper := map[string]interface{}{} //Check if this plugin exist in the input instance //If not, not process if _, ok := im[SectionKey]; !ok { returnKey = "" returnVal = "" } else { for _, rule := range ChildRule { if key, val := rule.ApplyRule(im[SectionKey]); key != "" { promScaper[key] = val } } inputs[SectionKey] = []interface{}{promScaper} result["inputs"] = inputs returnKey = SectionKey returnVal = result } return } var MergeRuleMap = map[string]mergeJsonRule.MergeRule{} func (p *Prometheus) Merge(source map[string]interface{}, result map[string]interface{}) { mergeJsonUtil.MergeMap(source, result, SectionKey, MergeRuleMap, GetCurPath()) } func init() { k := new(Prometheus) parent.MergeRuleMap[SectionKey] = k parent.RegisterLinuxRule(SectionKey, k) parent.RegisterWindowsRule(SectionKey, k) }