From b348881f2217be7bb4f1336afd86eb45092258d1 Mon Sep 17 00:00:00 2001 From: Jeffrey Chien Date: Wed, 10 Jul 2024 14:37:59 -0400 Subject: [PATCH] Reduce logging for known non-convertible JMX metric units. (#1244) --- internal/cloudwatch/unit.go | 19 +++++++++++++++++++ internal/cloudwatch/unit_test.go | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/internal/cloudwatch/unit.go b/internal/cloudwatch/unit.go index 829ac604ff..7323a80095 100644 --- a/internal/cloudwatch/unit.go +++ b/internal/cloudwatch/unit.go @@ -10,6 +10,7 @@ import ( "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" + "github.com/aws/amazon-cloudwatch-agent/internal/util/collections" "github.com/aws/amazon-cloudwatch-agent/internal/util/unit" ) @@ -72,6 +73,20 @@ var scaledBaseUnits = map[types.StandardUnit]map[unit.MetricPrefix]types.Standar }, } +var knownNonConvertibleUnits = collections.NewSet( + // JMX/Tomcat units + "errors", + "threads", + "requests", + // JMX/Kafka units + "{messages}", + "{requests}", + "{partitions}", + "{operations}", + "{controllers}", + "{elections}", +) + // ToStandardUnit converts from the OTEL unit names to the corresponding names // supported by AWS CloudWatch. Some OTEL unit types are unsupported. func ToStandardUnit(unit string) (string, float64, error) { @@ -81,6 +96,10 @@ func ToStandardUnit(unit string) (string, float64, error) { func toStandardUnit(unit string) (types.StandardUnit, float64, error) { u := strings.ToLower(unit) + // silently convert to None + if knownNonConvertibleUnits.Contains(u) { + return types.StandardUnitNone, 1, nil + } if standardUnit, ok := standardUnits[u]; ok { return standardUnit, 1, nil } diff --git a/internal/cloudwatch/unit_test.go b/internal/cloudwatch/unit_test.go index 20ec570f9a..cb808f5d0b 100644 --- a/internal/cloudwatch/unit_test.go +++ b/internal/cloudwatch/unit_test.go @@ -68,3 +68,13 @@ func TestScaledUnits(t *testing.T) { assert.Equal(t, testCase.scale, scale) } } + +func TestKnownNonStandardUnits(t *testing.T) { + testCases := []string{"errors", "{requests}"} + for _, testCase := range testCases { + unit, scale, err := ToStandardUnit(testCase) + assert.NoError(t, err) + assert.Equal(t, "None", unit) + assert.EqualValues(t, 1, scale) + } +}