Skip to content

Commit

Permalink
Add Traces Test to High Cardinality Test Cases
Browse files Browse the repository at this point in the history
  • Loading branch information
majanjua-amzn committed Oct 31, 2023
1 parent 5aff0ec commit b717a65
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
"crypto/rand"
"encoding/binary"
"encoding/hex"
"fmt"
"time"
)

func main() {
var r [16]byte
epochNow := time.Now().Unix()
binary.BigEndian.PutUint32(r[0:4], uint32(epochNow))
rand.Read(r[4:])
fmt.Printf("%s", hex.EncodeToString(r[:]))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "k8s.namespace.name",
"value": {
"stringValue": "default"
}
},
{
"key": "k8s.pod.name",
"value": {
"stringValue": "pod-name"
}
},
{
"key": "aws.deployment.name",
"value": {
"stringValue": "deployment-name"
}
},
{
"key": "host.id",
"value": {
"stringValue": "i-00000000000000000"
}
}
]
},
"scopeSpans": [
{
"scope": {
"name": "app-signals-integration-test"
},
"spans": [
{
"traceId": "TRACE_ID",
"spanId": "EEE19B7EC3C1B174",
"parentSpanId": "EEE19B7EC3C1B173",
"name": "app-signals-integration-test-traces",
"startTimeUnixNano": START_TIME,
"endTimeUnixNano": START_TIME,
"kind": 2,
"attributes": [
{
"key": "aws.span.kind",
"value": {
"stringValue": "CLIENT"
}
},
{
"key": "aws.local.operation",
"value": {
"stringValue": "operation"
}
},
{
"key": "aws.local.service",
"value": {
"stringValue": "service-name"
}
},
{
"key": "aws.remote.operation",
"value": {
"stringValue": "remote-operation"
}
},
{
"key": "aws.remote.service",
"value": {
"stringValue": "service-name-remote"
}
},
{
"key": "aws.remote.target",
"value": {
"stringValue": "remote-target"
}
}
]
}
]
}
]
}
]
}
77 changes: 77 additions & 0 deletions test/app_signals/high_cardinality_drop/traces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build !windows

package app_signals

import (
"fmt"
"time"

"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/test/test_runner"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
)

const (
lookbackDuration = time.Duration(-5) * time.Minute
EKSClusterAnnotation = "HostedIn_EKS_Cluster"
)

var annotations = map[string]interface{}{
"aws_remote_target": "remote-target",
"aws_remote_operation": "remote-operation",
"aws_local_service": "service-name",
"aws_remote_service": "service-name-remote",
"HostedIn_K8s_Namespace": "default",
"aws_local_operation": "operation",
}

type AppSignalsTracesRunner struct {
test_runner.BaseTestRunner
testName string
clusterName string
}

func (t *AppSignalsTracesRunner) Validate() status.TestGroupResult {
testResults := status.TestResult{
Name: t.testName,
Status: status.FAILED,
}
timeNow := time.Now()
annotations[EKSClusterAnnotation] = t.clusterName
xrayFilter := awsservice.FilterExpression(annotations)
traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter)
if err != nil {
fmt.Printf("error getting trace ids: %v", err)
} else {
fmt.Printf("Trace IDs: %v\n", traceIds)
if len(traceIds) > 0 {
testResults.Status = status.SUCCESSFUL
}
}

return status.TestGroupResult{
Name: t.GetTestName(),
TestResults: []status.TestResult{testResults},
}
}

func (t *AppSignalsTracesRunner) GetTestName() string {
return t.testName
}

func (t *AppSignalsTracesRunner) GetAgentRunDuration() time.Duration {
return 3 * time.Minute
}

func (t *AppSignalsTracesRunner) GetMeasuredMetrics() []string {
return nil
}

func (e *AppSignalsTracesRunner) GetAgentConfigFileName() string {
return ""
}

var _ test_runner.ITestRunner = (*AppSignalsTracesRunner)(nil)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

package main

import (
"crypto/rand"
"encoding/binary"
"encoding/hex"
"fmt"
"time"
)

func main() {
var r [16]byte
epochNow := time.Now().Unix()
binary.BigEndian.PutUint32(r[0:4], uint32(epochNow))
rand.Read(r[4:])
fmt.Printf("%s", hex.EncodeToString(r[:]))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"resourceSpans": [
{
"resource": {
"attributes": [
{
"key": "k8s.namespace.name",
"value": {
"stringValue": "default"
}
},
{
"key": "k8s.pod.name",
"value": {
"stringValue": "pod-name"
}
},
{
"key": "aws.deployment.name",
"value": {
"stringValue": "deployment-name"
}
},
{
"key": "host.id",
"value": {
"stringValue": "i-00000000000000000"
}
}
]
},
"scopeSpans": [
{
"scope": {
"name": "app-signals-integration-test"
},
"spans": [
{
"traceId": "TRACE_ID",
"spanId": "EEE19B7EC3C1B174",
"parentSpanId": "EEE19B7EC3C1B173",
"name": "app-signals-integration-test-traces",
"startTimeUnixNano": START_TIME,
"endTimeUnixNano": START_TIME,
"kind": 2,
"attributes": [
{
"key": "aws.span.kind",
"value": {
"stringValue": "CLIENT"
}
},
{
"key": "aws.local.operation",
"value": {
"stringValue": "operation"
}
},
{
"key": "aws.local.service",
"value": {
"stringValue": "service-name"
}
},
{
"key": "aws.remote.operation",
"value": {
"stringValue": "remote-operation"
}
},
{
"key": "aws.remote.service",
"value": {
"stringValue": "service-name-remote"
}
},
{
"key": "aws.remote.target",
"value": {
"stringValue": "remote-target"
}
}
]
}
]
}
]
}
]
}
77 changes: 77 additions & 0 deletions test/app_signals/high_cardinality_keep/traces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build !windows

package app_signals

import (
"fmt"
"time"

"github.com/aws/amazon-cloudwatch-agent-test/test/status"
"github.com/aws/amazon-cloudwatch-agent-test/test/test_runner"
"github.com/aws/amazon-cloudwatch-agent-test/util/awsservice"
)

const (
lookbackDuration = time.Duration(-5) * time.Minute
EKSClusterAnnotation = "HostedIn_EKS_Cluster"
)

var annotations = map[string]interface{}{
"aws_remote_target": "remote-target",
"aws_remote_operation": "remote-operation",
"aws_local_service": "service-name",
"aws_remote_service": "service-name-remote",
"HostedIn_K8s_Namespace": "default",
"aws_local_operation": "operation",
}

type AppSignalsTracesRunner struct {
test_runner.BaseTestRunner
testName string
clusterName string
}

func (t *AppSignalsTracesRunner) Validate() status.TestGroupResult {
testResults := status.TestResult{
Name: t.testName,
Status: status.FAILED,
}
timeNow := time.Now()
annotations[EKSClusterAnnotation] = t.clusterName
xrayFilter := awsservice.FilterExpression(annotations)
traceIds, err := awsservice.GetTraceIDs(timeNow.Add(lookbackDuration), timeNow, xrayFilter)
if err != nil {
fmt.Printf("error getting trace ids: %v", err)
} else {
fmt.Printf("Trace IDs: %v\n", traceIds)
if len(traceIds) > 0 {
testResults.Status = status.SUCCESSFUL
}
}

return status.TestGroupResult{
Name: t.GetTestName(),
TestResults: []status.TestResult{testResults},
}
}

func (t *AppSignalsTracesRunner) GetTestName() string {
return t.testName
}

func (t *AppSignalsTracesRunner) GetAgentRunDuration() time.Duration {
return 3 * time.Minute
}

func (t *AppSignalsTracesRunner) GetMeasuredMetrics() []string {
return nil
}

func (e *AppSignalsTracesRunner) GetAgentConfigFileName() string {
return ""
}

var _ test_runner.ITestRunner = (*AppSignalsTracesRunner)(nil)
Loading

0 comments on commit b717a65

Please sign in to comment.