From 2396d12769576b548754ff7f04434d2c44bb9434 Mon Sep 17 00:00:00 2001 From: Mengyi Zhou Date: Thu, 11 Jul 2024 15:21:15 -0700 Subject: [PATCH] Rename and group application signals attributes --- .../awsapplicationsignals/common/types.go | 56 +++++++++++-------- .../cardinalitycontrol/metrics_limiter.go | 24 ++++---- .../metrics_limiter_test.go | 10 ++-- .../normalizer/attributesnormalizer.go | 48 ++++++++-------- .../internal/prune/metric_pruner.go | 2 +- .../internal/prune/metric_pruner_test.go | 2 +- .../awsapplicationsignals/rules/common.go | 16 +++--- .../rules/common_test.go | 12 ++-- 8 files changed, 91 insertions(+), 79 deletions(-) diff --git a/plugins/processors/awsapplicationsignals/common/types.go b/plugins/processors/awsapplicationsignals/common/types.go index 66fd86ae37..438fb7c4fc 100644 --- a/plugins/processors/awsapplicationsignals/common/types.go +++ b/plugins/processors/awsapplicationsignals/common/types.go @@ -3,42 +3,54 @@ package common +// Metric attribute used as CloudWatch metric dimension. const ( - MetricAttributeLocalService = "Service" - MetricAttributeLocalOperation = "Operation" - MetricAttributeEnvironment = "Environment" - MetricAttributeRemoteService = "RemoteService" - MetricAttributeRemoteEnvironment = "RemoteEnvironment" - MetricAttributeRemoteOperation = "RemoteOperation" - MetricAttributeRemoteResourceIdentifier = "RemoteResourceIdentifier" - MetricAttributeRemoteResourceType = "RemoteResourceType" - MetricAttributeRemoteDbUser = "RemoteDbUser" + CWMetricAttributeLocalService = "Service" + CWMetricAttributeLocalOperation = "Operation" + CWMetricAttributeEnvironment = "Environment" + CWMetricAttributeRemoteService = "RemoteService" + CWMetricAttributeRemoteEnvironment = "RemoteEnvironment" + CWMetricAttributeRemoteOperation = "RemoteOperation" + CWMetricAttributeRemoteResourceIdentifier = "RemoteResourceIdentifier" + CWMetricAttributeRemoteResourceType = "RemoteResourceType" ) +// Platform attribute used as CloudWatch EMF log field and X-Ray trace annotation. const ( + AttributePlatformType = "PlatformType" AttributeEKSClusterName = "EKS.Cluster" AttributeK8SClusterName = "K8s.Cluster" AttributeK8SNamespace = "K8s.Namespace" + AttributeK8SWorkload = "K8s.Workload" + AttributeK8SPod = "K8s.Pod" AttributeEC2AutoScalingGroup = "EC2.AutoScalingGroup" AttributeEC2InstanceId = "EC2.InstanceId" AttributeHost = "Host" - AttributePlatformType = "PlatformType" - AttributeTelemetrySDK = "Telemetry.SDK" - AttributeTelemetryAgent = "Telemetry.Agent" - AttributeTelemetrySource = "Telemetry.Source" +) + +// Telemetry attributes used as CloudWatch EMF log fields. +const ( + MetricAttributeTelemetrySDK = "Telemetry.SDK" + MetricAttributeTelemetryAgent = "Telemetry.Agent" + MetricAttributeTelemetrySource = "Telemetry.Source" +) + +// Resource attributes used as CloudWatch EMF log fields. +const ( + MetricAttributeRemoteDbUser = "RemoteDbUser" ) const ( AttributeTmpReserved = "aws.tmp.reserved" ) -var IndexableMetricAttributes = []string{ - MetricAttributeLocalService, - MetricAttributeLocalOperation, - MetricAttributeEnvironment, - MetricAttributeRemoteService, - MetricAttributeRemoteEnvironment, - MetricAttributeRemoteOperation, - MetricAttributeRemoteResourceIdentifier, - MetricAttributeRemoteResourceType, +var CWMetricAttributes = []string{ + CWMetricAttributeLocalService, + CWMetricAttributeLocalOperation, + CWMetricAttributeEnvironment, + CWMetricAttributeRemoteService, + CWMetricAttributeRemoteEnvironment, + CWMetricAttributeRemoteOperation, + CWMetricAttributeRemoteResourceIdentifier, + CWMetricAttributeRemoteResourceType, } diff --git a/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter.go b/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter.go index 3b2efda288..b32171041b 100644 --- a/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter.go +++ b/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter.go @@ -29,15 +29,15 @@ const ( var awsDeclaredMetricAttributes = []string{ common.AttributeEKSClusterName, - common.AttributeK8SNamespace, - common.MetricAttributeEnvironment, - common.MetricAttributeLocalService, - common.MetricAttributeLocalOperation, - common.MetricAttributeRemoteService, - common.MetricAttributeRemoteOperation, - common.MetricAttributeRemoteResourceIdentifier, - common.MetricAttributeRemoteEnvironment, common.AttributeK8SClusterName, + common.AttributeK8SNamespace, + common.CWMetricAttributeEnvironment, + common.CWMetricAttributeLocalService, + common.CWMetricAttributeLocalOperation, + common.CWMetricAttributeRemoteService, + common.CWMetricAttributeRemoteOperation, + common.CWMetricAttributeRemoteResourceIdentifier, + common.CWMetricAttributeRemoteEnvironment, } type Limiter interface { @@ -141,7 +141,7 @@ func (m *MetricsLimiter) Admit(metricName string, attributes, resourceAttributes } func (m *MetricsLimiter) filterAWSDeclaredAttributes(attributes, resourceAttributes pcommon.Map) (map[string]string, string, bool) { - svcNameAttr, exists := attributes.Get(common.MetricAttributeLocalService) + svcNameAttr, exists := attributes.Get(common.CWMetricAttributeLocalService) if !exists { return nil, "", false } @@ -336,12 +336,12 @@ func (s *service) admitMetricData(metric *MetricData) bool { func (s *service) rollupMetricData(attributes pcommon.Map) { for _, indexAttr := range awsDeclaredMetricAttributes { - if (indexAttr == common.MetricAttributeEnvironment) || (indexAttr == common.MetricAttributeLocalService) || (indexAttr == common.MetricAttributeRemoteService) { + if (indexAttr == common.CWMetricAttributeEnvironment) || (indexAttr == common.CWMetricAttributeLocalService) || (indexAttr == common.CWMetricAttributeRemoteService) { continue } - if indexAttr == common.MetricAttributeLocalOperation { + if indexAttr == common.CWMetricAttributeLocalOperation { attributes.PutStr(indexAttr, UnprocessedServiceOperationValue) - } else if indexAttr == common.MetricAttributeRemoteOperation { + } else if indexAttr == common.CWMetricAttributeRemoteOperation { attributes.PutStr(indexAttr, UnprocessedRemoteServiceOperationValue) } else { attributes.PutStr(indexAttr, "-") diff --git a/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter_test.go b/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter_test.go index e7b14e4978..3e08c7f3fd 100644 --- a/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter_test.go +++ b/plugins/processors/awsapplicationsignals/internal/cardinalitycontrol/metrics_limiter_test.go @@ -41,15 +41,15 @@ func TestAdmitAndRollup(t *testing.T) { admittedAttributes[uniqKey.AsString()] = attr } else { for _, indexedAttrKey := range awsDeclaredMetricAttributes { - if indexedAttrKey == common.MetricAttributeEnvironment || - indexedAttrKey == common.MetricAttributeLocalService || - indexedAttrKey == common.MetricAttributeRemoteService { + if indexedAttrKey == common.CWMetricAttributeEnvironment || + indexedAttrKey == common.CWMetricAttributeLocalService || + indexedAttrKey == common.CWMetricAttributeRemoteService { continue } attrValue, _ := attr.Get(indexedAttrKey) - if indexedAttrKey == common.MetricAttributeLocalOperation { + if indexedAttrKey == common.CWMetricAttributeLocalOperation { assert.Equal(t, UnprocessedServiceOperationValue, attrValue.AsString()) - } else if indexedAttrKey == common.MetricAttributeRemoteOperation { + } else if indexedAttrKey == common.CWMetricAttributeRemoteOperation { assert.Equal(t, UnprocessedRemoteServiceOperationValue, attrValue.AsString()) } else { assert.Equal(t, "-", attrValue.AsString()) diff --git a/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go b/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go index d5f98f67e6..5a63743d81 100644 --- a/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go +++ b/plugins/processors/awsapplicationsignals/internal/normalizer/attributesnormalizer.go @@ -31,15 +31,15 @@ type attributesNormalizer struct { } var attributesRenamingForMetric = map[string]string{ - attr.AWSLocalService: common.MetricAttributeLocalService, - attr.AWSLocalOperation: common.MetricAttributeLocalOperation, - attr.AWSLocalEnvironment: common.MetricAttributeEnvironment, - attr.AWSRemoteService: common.MetricAttributeRemoteService, - attr.AWSRemoteOperation: common.MetricAttributeRemoteOperation, - attr.AWSRemoteEnvironment: common.MetricAttributeRemoteEnvironment, - attr.AWSRemoteTarget: common.MetricAttributeRemoteResourceIdentifier, - attr.AWSRemoteResourceIdentifier: common.MetricAttributeRemoteResourceIdentifier, - attr.AWSRemoteResourceType: common.MetricAttributeRemoteResourceType, + attr.AWSLocalService: common.CWMetricAttributeLocalService, + attr.AWSLocalOperation: common.CWMetricAttributeLocalOperation, + attr.AWSLocalEnvironment: common.CWMetricAttributeEnvironment, + attr.AWSRemoteService: common.CWMetricAttributeRemoteService, + attr.AWSRemoteOperation: common.CWMetricAttributeRemoteOperation, + attr.AWSRemoteEnvironment: common.CWMetricAttributeRemoteEnvironment, + attr.AWSRemoteTarget: common.CWMetricAttributeRemoteResourceIdentifier, + attr.AWSRemoteResourceIdentifier: common.CWMetricAttributeRemoteResourceIdentifier, + attr.AWSRemoteResourceType: common.CWMetricAttributeRemoteResourceType, attr.AWSRemoteDbUser: common.MetricAttributeRemoteDbUser, } @@ -48,12 +48,12 @@ var resourceAttributesRenamingForTrace = map[string]string{ // see the code references from upstream: // * https://github.com/open-telemetry/opentelemetry-operator/blob/0e39ee77693146e0924da3ca474a0fe14dc30b3a/pkg/instrumentation/sdk.go#L245 // * https://github.com/open-telemetry/opentelemetry-operator/blob/0e39ee77693146e0924da3ca474a0fe14dc30b3a/pkg/instrumentation/sdk.go#L305C43-L305C43 - semconv.AttributeK8SDeploymentName: "K8s.Workload", - semconv.AttributeK8SStatefulSetName: "K8s.Workload", - semconv.AttributeK8SDaemonSetName: "K8s.Workload", - semconv.AttributeK8SJobName: "K8s.Workload", - semconv.AttributeK8SCronJobName: "K8s.Workload", - semconv.AttributeK8SPodName: "K8s.Pod", + semconv.AttributeK8SDeploymentName: common.AttributeK8SWorkload, + semconv.AttributeK8SStatefulSetName: common.AttributeK8SWorkload, + semconv.AttributeK8SDaemonSetName: common.AttributeK8SWorkload, + semconv.AttributeK8SJobName: common.AttributeK8SWorkload, + semconv.AttributeK8SCronJobName: common.AttributeK8SWorkload, + semconv.AttributeK8SPodName: common.AttributeK8SPod, } var attributesRenamingForTrace = map[string]string{ @@ -65,12 +65,12 @@ var copyMapForMetric = map[string]string{ // see the code referecnes from upstream: // * https://github.com/open-telemetry/opentelemetry-operator/blob/0e39ee77693146e0924da3ca474a0fe14dc30b3a/pkg/instrumentation/sdk.go#L245 // * https://github.com/open-telemetry/opentelemetry-operator/blob/0e39ee77693146e0924da3ca474a0fe14dc30b3a/pkg/instrumentation/sdk.go#L305C43-L305C43 - semconv.AttributeK8SDeploymentName: "K8s.Workload", - semconv.AttributeK8SStatefulSetName: "K8s.Workload", - semconv.AttributeK8SDaemonSetName: "K8s.Workload", - semconv.AttributeK8SJobName: "K8s.Workload", - semconv.AttributeK8SCronJobName: "K8s.Workload", - semconv.AttributeK8SPodName: "K8s.Pod", + semconv.AttributeK8SDeploymentName: common.AttributeK8SWorkload, + semconv.AttributeK8SStatefulSetName: common.AttributeK8SWorkload, + semconv.AttributeK8SDaemonSetName: common.AttributeK8SWorkload, + semconv.AttributeK8SJobName: common.AttributeK8SWorkload, + semconv.AttributeK8SCronJobName: common.AttributeK8SWorkload, + semconv.AttributeK8SPodName: common.AttributeK8SPod, semconv.AttributeAWSLogGroupNames: "aws.log.group.names", } @@ -165,8 +165,8 @@ func (n *attributesNormalizer) normalizeTelemetryAttributes(attributes, resource sdkVersion = sdkAutoVersion mode = instrumentationModeAuto } - attributes.PutStr(common.AttributeTelemetrySDK, fmt.Sprintf("%s,%s,%s,%s", sdkName, sdkVersion, sdkLang, mode)) - attributes.PutStr(common.AttributeTelemetryAgent, fmt.Sprintf("CWAgent/%s", version.Number())) + attributes.PutStr(common.MetricAttributeTelemetrySDK, fmt.Sprintf("%s,%s,%s,%s", sdkName, sdkVersion, sdkLang, mode)) + attributes.PutStr(common.MetricAttributeTelemetryAgent, fmt.Sprintf("CWAgent/%s", version.Number())) var telemetrySource string if val, ok := attributes.Get(attr.AWSSpanKind); ok { @@ -182,7 +182,7 @@ func (n *attributesNormalizer) normalizeTelemetryAttributes(attributes, resource case "LOCAL_ROOT": telemetrySource = "LocalRootSpan" } - attributes.PutStr(common.AttributeTelemetrySource, telemetrySource) + attributes.PutStr(common.MetricAttributeTelemetrySource, telemetrySource) attributes.Remove(attr.AWSSpanKind) } } diff --git a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner.go b/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner.go index 5fcca636d4..2cb9485ada 100644 --- a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner.go +++ b/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner.go @@ -15,7 +15,7 @@ type MetricPruner struct { } func (p *MetricPruner) ShouldBeDropped(attributes pcommon.Map) (bool, error) { - for _, attributeKey := range common.IndexableMetricAttributes { + for _, attributeKey := range common.CWMetricAttributes { if val, ok := attributes.Get(attributeKey); ok { if !isAsciiPrintable(val.Str()) { return true, errors.New("Metric attribute " + attributeKey + " must contain only ASCII characters.") diff --git a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner_test.go b/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner_test.go index 4a14c5e9a7..998d5092e0 100644 --- a/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner_test.go +++ b/plugins/processors/awsapplicationsignals/internal/prune/metric_pruner_test.go @@ -44,7 +44,7 @@ func TestMetricPrunerWithIndexableAttribute(t *testing.T) { p := &MetricPruner{} for _, tt := range tests { attributes := pcommon.NewMap() - attributes.PutStr(common.MetricAttributeLocalService, tt.val) + attributes.PutStr(common.CWMetricAttributeLocalService, tt.val) t.Run(tt.name, func(t *testing.T) { got, _ := p.ShouldBeDropped(attributes) if got != tt.want { diff --git a/plugins/processors/awsapplicationsignals/rules/common.go b/plugins/processors/awsapplicationsignals/rules/common.go index 8e432f20d1..0eba48173f 100644 --- a/plugins/processors/awsapplicationsignals/rules/common.go +++ b/plugins/processors/awsapplicationsignals/rules/common.go @@ -49,14 +49,14 @@ type ActionItem struct { } var traceKeyMap = map[string]string{ - common.MetricAttributeLocalService: attributes.AWSLocalService, - common.MetricAttributeEnvironment: attributes.AWSLocalEnvironment, - common.MetricAttributeLocalOperation: attributes.AWSLocalOperation, - common.MetricAttributeRemoteService: attributes.AWSRemoteService, - common.MetricAttributeRemoteEnvironment: attributes.AWSRemoteEnvironment, - common.MetricAttributeRemoteOperation: attributes.AWSRemoteOperation, - common.MetricAttributeRemoteResourceIdentifier: attributes.AWSRemoteResourceIdentifier, - common.MetricAttributeRemoteResourceType: attributes.AWSRemoteResourceType, + common.CWMetricAttributeLocalService: attributes.AWSLocalService, + common.CWMetricAttributeEnvironment: attributes.AWSLocalEnvironment, + common.CWMetricAttributeLocalOperation: attributes.AWSLocalOperation, + common.CWMetricAttributeRemoteService: attributes.AWSRemoteService, + common.CWMetricAttributeRemoteEnvironment: attributes.AWSRemoteEnvironment, + common.CWMetricAttributeRemoteOperation: attributes.AWSRemoteOperation, + common.CWMetricAttributeRemoteResourceIdentifier: attributes.AWSRemoteResourceIdentifier, + common.CWMetricAttributeRemoteResourceType: attributes.AWSRemoteResourceType, } func GetAllowListAction(action string) (AllowListAction, error) { diff --git a/plugins/processors/awsapplicationsignals/rules/common_test.go b/plugins/processors/awsapplicationsignals/rules/common_test.go index 40dade4386..5a9d5262ce 100644 --- a/plugins/processors/awsapplicationsignals/rules/common_test.go +++ b/plugins/processors/awsapplicationsignals/rules/common_test.go @@ -31,15 +31,15 @@ func generateAttributesWithEnv(service string, operation string, environment str attributes.PutStr(attr.AWSRemoteEnvironment, remoteEnvironment) } } else { - attributes.PutStr(common.MetricAttributeLocalService, service) - attributes.PutStr(common.MetricAttributeLocalOperation, operation) + attributes.PutStr(common.CWMetricAttributeLocalService, service) + attributes.PutStr(common.CWMetricAttributeLocalOperation, operation) if environment != "" { - attributes.PutStr(common.MetricAttributeEnvironment, environment) + attributes.PutStr(common.CWMetricAttributeEnvironment, environment) } - attributes.PutStr(common.MetricAttributeRemoteService, remoteService) - attributes.PutStr(common.MetricAttributeRemoteOperation, remoteOperation) + attributes.PutStr(common.CWMetricAttributeRemoteService, remoteService) + attributes.PutStr(common.CWMetricAttributeRemoteOperation, remoteOperation) if remoteEnvironment != "" { - attributes.PutStr(common.MetricAttributeRemoteEnvironment, remoteEnvironment) + attributes.PutStr(common.CWMetricAttributeRemoteEnvironment, remoteEnvironment) } } return attributes