From f40a693e95206d7bfc89c3547e0d76c23b96c9c3 Mon Sep 17 00:00:00 2001 From: Paramadon Date: Fri, 7 Jun 2024 10:54:42 -0400 Subject: [PATCH] adding to unit test --- .../config/sampleSchema/validEthtoolConfig.json | 5 ++++- .../metrics/metrics_collect/ethtool/ethtool.go | 11 ++++------- translator/translate/metrics/util/commonconfigutil.go | 9 ++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/translator/config/sampleSchema/validEthtoolConfig.json b/translator/config/sampleSchema/validEthtoolConfig.json index 29d88d7cb4..5da205e7b5 100644 --- a/translator/config/sampleSchema/validEthtoolConfig.json +++ b/translator/config/sampleSchema/validEthtoolConfig.json @@ -12,7 +12,10 @@ "pps_allowance_exceeded", "conntrack_allowance_exceeded", "linklocal_allowance_exceeded" - ] + ], + "append_dimensions": { + "name":"sampleName" + } } }, "append_dimensions": { diff --git a/translator/translate/metrics/metrics_collect/ethtool/ethtool.go b/translator/translate/metrics/metrics_collect/ethtool/ethtool.go index ecc962143e..1f2179a847 100644 --- a/translator/translate/metrics/metrics_collect/ethtool/ethtool.go +++ b/translator/translate/metrics/metrics_collect/ethtool/ethtool.go @@ -5,6 +5,7 @@ package ethtool import ( "github.com/aws/amazon-cloudwatch-agent/translator" + "github.com/aws/amazon-cloudwatch-agent/translator/translate/agent" parent "github.com/aws/amazon-cloudwatch-agent/translator/translate/metrics/metrics_collect" "github.com/aws/amazon-cloudwatch-agent/translator/translate/metrics/util" ) @@ -17,18 +18,13 @@ var ChildRule = map[string]translator.Rule{} // "metrics_include": [ // "bw_in_allowance_exceeded", // "bw_out_allowance_exceeded" -// ] +// ], // "append_dimensions":{ // key:value // } // } const SectionKey_Ethtool = "ethtool" -func GetCurPath() string { - curPath := parent.GetCurPath() + SectionKey_Ethtool + "/" - return curPath -} - func RegisterRule(fieldname string, r translator.Rule) { ChildRule[fieldname] = r } @@ -54,7 +50,8 @@ func (n *Ethtool) ApplyRule(input interface{}) (returnKey string, returnVal inte returnKey = SectionKey_Ethtool returnVal = resArr //Process tags - util.ProcessAppendDimension(m[SectionKey_Ethtool].(map[string]interface{}), SectionKey_Ethtool, GetCurPath(), result) + isHighResolution := util.IsHighResolution(agent.Global_Config.Interval) + util.ProcessAppendDimensions(m, SectionKey_Ethtool, isHighResolution, result) } return } diff --git a/translator/translate/metrics/util/commonconfigutil.go b/translator/translate/metrics/util/commonconfigutil.go index 1125fd5f8c..e2132d6172 100755 --- a/translator/translate/metrics/util/commonconfigutil.go +++ b/translator/translate/metrics/util/commonconfigutil.go @@ -47,14 +47,13 @@ func ProcessLinuxCommonConfig(input interface{}, pluginName string, path string, } else { return false } - ProcessAppendDimension(inputMap, pluginName, path, result) - return true -} -func ProcessAppendDimension(inputMap map[string]interface{}, pluginName string, path string, result map[string]interface{}) { isHighResolution := IsHighResolution(agent.Global_Config.Interval) // Set input plugin specific interval + ProcessAppendDimensions(inputMap, pluginName, isHighResolution, result) + return true +} +func ProcessAppendDimensions(inputMap map[string]interface{}, pluginName string, isHighResolution bool, result map[string]interface{}) { isHighResolution = setTimeInterval(inputMap, result, isHighResolution, pluginName) - // Set append_dimensions as tags if val, ok := inputMap[Append_Dimensions_Key]; ok { result[Append_Dimensions_Mapped_Key] = util.FilterReservedKeys(val)