Skip to content

Commit

Permalink
Rename and group application signals attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bjrara committed Aug 1, 2024
1 parent 91b71a7 commit 2396d12
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 79 deletions.
56 changes: 34 additions & 22 deletions plugins/processors/awsapplicationsignals/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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, "-")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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{
Expand All @@ -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",
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 8 additions & 8 deletions plugins/processors/awsapplicationsignals/rules/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions plugins/processors/awsapplicationsignals/rules/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2396d12

Please sign in to comment.