Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Application Signals] Improve metric schema for EKS, Native K8s, EC2 #1179

Merged
merged 12 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/appsignals-e2e-ec2-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:
GET_ADOT_JAR_COMMAND: "wget -O adot.jar https://github.com/aws-observability/aws-otel-java-instrumentation/releases/latest/download/aws-opentelemetry-agent.jar"
GET_CW_AGENT_RPM_COMMAND: "aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/integration-test/binary/${{ github.sha }}/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm ./cw-agent.rpm"
METRIC_NAMESPACE: AppSignals
LOG_GROUP_NAME: /aws/appsignals/generic
LOG_GROUP_NAME: /aws/application-signals/data

jobs:
e2e-ec2-test:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/appsignals-e2e-eks-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ env:
SAMPLE_APP_FRONTEND_SERVICE_IMAGE: ${{ secrets.APP_SIGNALS_E2E_SAMPLE_APP_FRONTEND_SVC_IMG }}
SAMPLE_APP_REMOTE_SERVICE_IMAGE: ${{ secrets.APP_SIGNALS_E2E_SAMPLE_APP_REMOTE_SVC_IMG }}
METRIC_NAMESPACE: AppSignals
LOG_GROUP_NAME: /aws/appsignals/eks
LOG_GROUP_NAME: /aws/application-signals/data
ECR_INTEGRATION_TEST_REPO: "cwagent-integration-test"

jobs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,36 @@ A replacements section defines a matching against the dimensions of incoming met
## AWS AppSignals Processor Configuration Example

```yaml
awsappsignals:
awsapplicationsignals:
resolvers: ["eks"]
rules:
- selectors:
- dimension: Operation
match: "POST *"
match: "POST *"
- dimension: RemoteService
match: "*"
action: keep
rule_name: "keep01"
match: "*"
action: keep
rule_name: "keep01"
- selectors:
- dimension: Operation
match: "GET *"
match: "GET *"
- dimension: RemoteService
match: "*"
action: keep
rule_name: "keep02"
match: "*"
action: keep
rule_name: "keep02"
- selectors:
- dimension: Operation
match: "POST *"
action: drop
rule_name: "drop01"
match: "POST *"
action: drop
rule_name: "drop01"
- selectors:
- dimension: Operation
match: "*"
replacements:
- target_dimension: RemoteOperation
value: "This is a test string"
action: replace
rule_name: "replace01"
match: "*"
replacements:
- target_dimension: RemoteOperation
value: "This is a test string"
action: replace
rule_name: "replace01"
```

## Amazon CloudWatch Agent Configuration Example
Expand Down
43 changes: 43 additions & 0 deletions plugins/processors/awsapplicationsignals/common/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package common

const (
MetricAttributeLocalService = "Service"
MetricAttributeLocalOperation = "Operation"
MetricAttributeEnvironment = "Environment"
MetricAttributeRemoteService = "RemoteService"
MetricAttributeRemoteEnvironment = "RemoteEnvironment"
MetricAttributeRemoteOperation = "RemoteOperation"
MetricAttributeRemoteResourceIdentifier = "RemoteResourceIdentifier"
MetricAttributeRemoteResourceType = "RemoteResourceType"
)

const (
AttributeEKSClusterName = "EKS.Cluster"
AttributeK8SClusterName = "K8s.Cluster"
AttributeK8SNamespace = "K8s.Namespace"
AttributeEC2AutoScalingGroup = "EC2.AutoScalingGroup"
AttributeEC2InstanceId = "EC2.InstanceId"
AttributeHost = "Host"
AttributePlatformType = "PlatformType"
AttributeTelemetrySDK = "Telemetry.SDK"
AttributeTelemetryAgent = "Telemetry.Agent"
AttributeTelemetrySource = "Telemetry.Source"
)

const (
AttributeTmpReserved = "aws.tmp.reserved"
)

var IndexableMetricAttributes = []string{
MetricAttributeLocalService,
MetricAttributeLocalOperation,
MetricAttributeEnvironment,
MetricAttributeRemoteService,
MetricAttributeRemoteEnvironment,
MetricAttributeRemoteOperation,
MetricAttributeRemoteResourceIdentifier,
MetricAttributeRemoteResourceType,
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"errors"
"time"

"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/rules"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/rules"
)

type Config struct {
Expand Down Expand Up @@ -63,6 +63,8 @@ func (cfg *Config) Validate() error {
return errors.New("name must not be empty for k8s resolver")
}
case PlatformEC2, PlatformGeneric:
case PlatformECS:
return errors.New("ecs resolver is not supported")
default:
return errors.New("unknown resolver")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const (
PlatformK8s = "k8s"
// PlatformEC2 Amazon EC2 platform
PlatformEC2 = "ec2"
// PlatformECS Amazon ECS
PlatformECS = "ecs"
)

type Resolver struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package awsappsignals
package awsapplicationsignals

import (
"context"
Expand All @@ -12,7 +12,7 @@ import (
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"

appsignalsconfig "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/config"
appsignalsconfig "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/config"
)

const (
Expand Down Expand Up @@ -89,12 +89,12 @@ func createMetricsProcessor(
func createProcessor(
params processor.CreateSettings,
cfg component.Config,
) (*awsappsignalsprocessor, error) {
) (*awsapplicationsignalsprocessor, error) {
pCfg, ok := cfg.(*appsignalsconfig.Config)
if !ok {
return nil, errors.New("could not initialize awsappsignalsprocessor")
return nil, errors.New("could not initialize awsapplicationsignalsprocessor")
}
ap := &awsappsignalsprocessor{logger: params.Logger, config: pCfg}
ap := &awsapplicationsignalsprocessor{logger: params.Logger, config: pCfg}

return ap, nil
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package awsappsignals
package awsapplicationsignals

import (
"path/filepath"
Expand All @@ -12,8 +12,8 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap/confmaptest"

"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/config"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/rules"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/config"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/rules"
)

var expectedRules = []rules.Rule{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package attributes

const (
// aws attributes
AWSSpanKind = "aws.span.kind"
AWSLocalService = "aws.local.service"
AWSLocalEnvironment = "aws.local.environment"
AWSLocalOperation = "aws.local.operation"
AWSRemoteService = "aws.remote.service"
AWSRemoteOperation = "aws.remote.operation"
AWSRemoteEnvironment = "aws.remote.environment"
AWSRemoteTarget = "aws.remote.target"
AWSRemoteResourceIdentifier = "aws.remote.resource.identifier"
AWSRemoteResourceType = "aws.remote.resource.type"
AWSHostedInEnvironment = "aws.hostedin.environment"

// resource detection processor attributes
ResourceDetectionHostId = "host.id"
ResourceDetectionHostName = "host.name"
ResourceDetectionASG = "ec2.tag.aws:autoscaling:groupName"
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ import (
"context"
"fmt"
"sort"
"strings"
"sync"
"time"

"go.opentelemetry.io/collector/pdata/pcommon"
"go.uber.org/zap"

"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/common"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/config"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/common"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/config"
)

const (
Expand All @@ -29,17 +28,16 @@ const (
)

var awsDeclaredMetricAttributes = []string{
common.HostedInAttributeClusterName,
common.HostedInAttributeK8SNamespace,
common.HostedInAttributeEnvironment,
common.AttributeEKSClusterName,
common.AttributeK8SNamespace,
common.MetricAttributeEnvironment,
common.MetricAttributeLocalService,
common.MetricAttributeLocalOperation,
common.MetricAttributeRemoteService,
common.MetricAttributeRemoteOperation,
common.MetricAttributeRemoteTarget,
common.MetricAttributeRemoteNamespace,
common.HostedInAttributeK8SClusterName,
common.HostedInAttributeEC2Environment,
common.MetricAttributeRemoteResourceIdentifier,
common.MetricAttributeRemoteEnvironment,
common.AttributeK8SClusterName,
}

type Limiter interface {
Expand Down Expand Up @@ -338,7 +336,7 @@ func (s *service) admitMetricData(metric *MetricData) bool {

func (s *service) rollupMetricData(attributes pcommon.Map) {
for _, indexAttr := range awsDeclaredMetricAttributes {
if strings.HasPrefix(indexAttr, "HostedIn.") || (indexAttr == common.MetricAttributeLocalService) || (indexAttr == common.MetricAttributeRemoteService) {
if (indexAttr == common.MetricAttributeEnvironment) || (indexAttr == common.MetricAttributeLocalService) || (indexAttr == common.MetricAttributeRemoteService) {
continue
}
if indexAttr == common.MetricAttributeLocalOperation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@ import (
"fmt"
"math/rand"
"strconv"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.uber.org/zap"

"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/common"
awsappsignalsconfig "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsappsignals/config"
"github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/common"
awsapplicationsignalsconfig "github.com/aws/amazon-cloudwatch-agent/plugins/processors/awsapplicationsignals/config"
)

var emptyResourceAttributes = pcommon.NewMap()
var logger, _ = zap.NewDevelopment()

func TestAdmitAndRollup(t *testing.T) {
config := &awsappsignalsconfig.LimiterConfig{
config := &awsapplicationsignalsconfig.LimiterConfig{
Threshold: 2,
Disabled: false,
LogDroppedMetrics: false,
RotationInterval: awsappsignalsconfig.DefaultRotationInterval,
RotationInterval: awsapplicationsignalsconfig.DefaultRotationInterval,
}
config.Validate()

Expand All @@ -42,7 +41,9 @@ func TestAdmitAndRollup(t *testing.T) {
admittedAttributes[uniqKey.AsString()] = attr
} else {
for _, indexedAttrKey := range awsDeclaredMetricAttributes {
if strings.HasPrefix(indexedAttrKey, "HostedIn.") || indexedAttrKey == "Service" || indexedAttrKey == "RemoteService" {
if indexedAttrKey == common.MetricAttributeEnvironment ||
indexedAttrKey == common.MetricAttributeLocalService ||
indexedAttrKey == common.MetricAttributeRemoteService {
continue
}
attrValue, _ := attr.Get(indexedAttrKey)
Expand All @@ -60,11 +61,11 @@ func TestAdmitAndRollup(t *testing.T) {
}

func TestAdmitByTopK(t *testing.T) {
config := awsappsignalsconfig.LimiterConfig{
config := awsapplicationsignalsconfig.LimiterConfig{
Threshold: 100,
Disabled: false,
LogDroppedMetrics: false,
RotationInterval: awsappsignalsconfig.DefaultRotationInterval,
RotationInterval: awsapplicationsignalsconfig.DefaultRotationInterval,
}
config.Validate()

Expand All @@ -90,11 +91,11 @@ func TestAdmitByTopK(t *testing.T) {
}

func TestAdmitLowCardinalityAttributes(t *testing.T) {
config := awsappsignalsconfig.LimiterConfig{
config := awsapplicationsignalsconfig.LimiterConfig{
Threshold: 10,
Disabled: false,
LogDroppedMetrics: false,
RotationInterval: awsappsignalsconfig.DefaultRotationInterval,
RotationInterval: awsapplicationsignalsconfig.DefaultRotationInterval,
}
config.Validate()

Expand All @@ -110,11 +111,11 @@ func TestAdmitLowCardinalityAttributes(t *testing.T) {
}

func TestAdmitReservedMetrics(t *testing.T) {
config := awsappsignalsconfig.LimiterConfig{
config := awsapplicationsignalsconfig.LimiterConfig{
Threshold: 10,
Disabled: false,
LogDroppedMetrics: false,
RotationInterval: awsappsignalsconfig.DefaultRotationInterval,
RotationInterval: awsapplicationsignalsconfig.DefaultRotationInterval,
}
config.Validate()

Expand All @@ -141,7 +142,7 @@ func TestAdmitReservedMetrics(t *testing.T) {
func TestClearStaleService(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())

config := awsappsignalsconfig.LimiterConfig{
config := awsapplicationsignalsconfig.LimiterConfig{
Threshold: 10,
Disabled: false,
LogDroppedMetrics: false,
Expand All @@ -167,7 +168,7 @@ func TestClearStaleService(t *testing.T) {
}

func TestInheritanceAfterRotation(t *testing.T) {
config := awsappsignalsconfig.LimiterConfig{
config := awsapplicationsignalsconfig.LimiterConfig{
Threshold: 10,
Disabled: false,
LogDroppedMetrics: true,
Expand Down
Loading
Loading