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

Add EKS integration testing for APM Traces #327

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
collectd.org v0.5.0
github.com/DataDog/datadog-go v4.8.3+incompatible
github.com/aws/aws-sdk-go v1.44.262
github.com/aws/aws-sdk-go-v2 v1.18.0
github.com/aws/aws-sdk-go-v2 v1.19.1
github.com/aws/aws-sdk-go-v2/config v1.18.10
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.0
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.21
Expand All @@ -22,6 +22,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ecs v1.23.2
github.com/aws/aws-sdk-go-v2/service/s3 v1.30.1
github.com/aws/aws-sdk-go-v2/service/ssm v1.33.0
github.com/aws/aws-sdk-go-v2/service/xray v1.16.15
github.com/cenkalti/backoff/v4 v4.2.0
github.com/google/uuid v1.3.0
github.com/mitchellh/mapstructure v1.5.0
Expand All @@ -39,8 +40,8 @@ require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.10 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.36 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.30 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.28 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.18 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.13.20 // indirect
Expand Down
11 changes: 8 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ github.com/aws/aws-sdk-go-v2 v1.16.16/go.mod h1:SwiyXi/1zTUZ6KIAmLK5V5ll8SiURNUY
github.com/aws/aws-sdk-go-v2 v1.17.1/go.mod h1:JLnGeGONAyi2lWXI1p0PCIOIy333JMVK1U7Hf0aRFLw=
github.com/aws/aws-sdk-go-v2 v1.17.3/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2 v1.17.4/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2 v1.18.0 h1:882kkTpSFhdgYRKVZ/VCgf7sd0ru57p2JCxz4/oN5RY=
github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2 v1.19.1 h1:STs0lbbpXu3byTPcnRLghs2DH0yk9qKDo27TyyJSKsM=
github.com/aws/aws-sdk-go-v2 v1.19.1/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 h1:dK82zF6kkPeCo8J1e+tGx4JdvDIQzj7ygIoLg8WMuGs=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10/go.mod h1:VeTZetY5KRJLuD/7fkQXMU6Mw7H5m/KP2J5Iy9osMno=
github.com/aws/aws-sdk-go-v2/config v1.18.10 h1:Znce11DWswdh+5kOsIp+QaNfY9igp1QUN+fZHCKmeCI=
Expand All @@ -26,14 +27,16 @@ github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.23/go.mod h1:2DFxAQ9pfI
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25/go.mod h1:Zb29PYkf42vVYQY6pvSyJCJcFHlPIiY+YKdPtwnvMkY=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.27/go.mod h1:a1/UpzeyBBerajpnP5nGZa9mGzsBn5cOKxm6NWQsvoI=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.28/go.mod h1:3lwChorpIM/BhImY/hy+Z6jekmN92cXGPI1QJasVPYY=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 h1:kG5eQilShqmJbv11XL1VpyDbaEJzWxd4zRiCG30GSn4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33/go.mod h1:7i0PF1ME/2eUPFcjkVIwq+DOygHEoK92t5cDqNgYbIw=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.36 h1:kbk81RlPoC6e4co7cQx2FAvH9TgbzxIqCqiosAFiB+w=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.36/go.mod h1:T8Jsn/uNL/AFOXrVYQ1YQaN1r9gN34JU1855/Lyjv+o=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.17/go.mod h1:pRwaTYCJemADaqCbUAxltMoHKata7hmB5PjEXeu0kfg=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.19/go.mod h1:6Q0546uHDp421okhmmGfbxzq2hBqbXFNpi4k+Q1JnQA=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.21/go.mod h1:+Gxn8jYn5k9ebfHEqlhrMirFjSW0v0C9fI+KN5vk2kE=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.22/go.mod h1:EqK7gVrIGAHyZItrD1D8B0ilgwMD1GiWAmbU4u/JHNk=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 h1:vFQlirhuM8lLlpI7imKOMsjdQLuN9CPi+k44F/OFVsk=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27/go.mod h1:UrHnn3QV/d0pBZ6QBAEQcqFLf8FAzLmoUfPVIueOvoM=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.30 h1:lMl8S5SB8jNCB+Sty2Em4lnu3IJytceHQd7qbmfqKL0=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.30/go.mod h1:v3GSCnFxbHzt9dlWBqvA1K1f9lmWuf4ztupZBCAIVs4=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.28 h1:KeTxcGdNnQudb46oOl4d90f2I33DF/c6q3RnZAmvQdQ=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.28/go.mod h1:yRZVr/iT0AqyHeep00SZ4YfBAKojXz08w3XMBscdi0c=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.18 h1:H/mF2LNWwX00lD6FlYfKpLLZgUW7oIzCBkig78x4Xok=
Expand Down Expand Up @@ -75,6 +78,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.0 h1:Jfly6mRxk2ZOSlbCvZfKNS7T
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.0/go.mod h1:TZSH7xLO7+phDtViY/KUp9WGCJMQkLJ/VpgkTFd5gh8=
github.com/aws/aws-sdk-go-v2/service/sts v1.18.2 h1:J/4wIaGInCEYCGhTSruxCxeoA5cy91a+JT7cHFKFSHQ=
github.com/aws/aws-sdk-go-v2/service/sts v1.18.2/go.mod h1:+lGbb3+1ugwKrNTWcf2RT05Xmp543B06zDFTwiTLp7I=
github.com/aws/aws-sdk-go-v2/service/xray v1.16.15 h1:wpFgy/pHHhe+GJ6JX1DiXU7g/FW6E1lFQWVZAhIig3U=
github.com/aws/aws-sdk-go-v2/service/xray v1.16.15/go.mod h1:6n4KNI08QuLLxpmRzr4kHFBiLYrc02OTIz8cnDOm3Dc=
github.com/aws/smithy-go v1.13.3/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/smithy-go v1.13.4/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8=
Expand Down
39 changes: 29 additions & 10 deletions terraform/eks/daemon/apm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ resource "aws_eks_node_group" "this" {
aws_iam_role_policy_attachment.node_AmazonEC2ContainerRegistryReadOnly,
aws_iam_role_policy_attachment.node_AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.node_AmazonEKSWorkerNodePolicy,
aws_iam_role_policy_attachment.node_CloudWatchAgentServerPolicy
aws_iam_role_policy_attachment.node_CloudWatchAgentServerPolicy,
aws_iam_role_policy_attachment.node_AWSXRayDaemonWriteAccess
]
}

Expand Down Expand Up @@ -99,6 +100,10 @@ resource "aws_iam_role_policy_attachment" "node_CloudWatchAgentServerPolicy" {
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
role = aws_iam_role.node_role.name
}
resource "aws_iam_role_policy_attachment" "node_AWSXRayDaemonWriteAccess" {
policy_arn = "arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess"
role = aws_iam_role.node_role.name
}

# TODO: these security groups be created once and then reused
# EKS Cluster Security Group
Expand Down Expand Up @@ -321,22 +326,22 @@ resource "kubernetes_daemonset" "service" {

container {
name = "apm-client"
image = "public.ecr.aws/amazonlinux/amazonlinux:latest"
image = "public.ecr.aws/docker/library/golang:latest"
image_pull_policy = "Always"
resources {
limits = {
"cpu" : "50m",
"memory" : "50Mi"
"memory" : "300Mi"
}
requests = {
"cpu" : "50m",
"memory" : "50Mi"
"memory" : "300Mi"
}
}
command = [
"/bin/sh",
"-c",
"while true; do echo '${data.template_file.server_consumer.rendered}' | sed -e \"s/START_TIME/$(date +%s%N)/\" > server_consumer.json; curl -H 'Content-Type: application/json' -d @server_consumer.json -i http://127.0.0.1:4318/v1/metrics --verbose --http0.9; echo '${data.template_file.client_producer.rendered}' | sed -e \"s/START_TIME/$(date +%s%N)/\" > client_producer.json; curl -H 'Content-Type: application/json' -d @client_producer.json -i http://127.0.0.1:4318/v1/metrics --verbose --http0.9; sleep 1; done"
"while true; echo '${data.template_file.traceid_generator.rendered}' > traceid_generator.go && chmod +x traceid_generator.go; export START_TIME=$(date +%s%N); export TRACE_ID=$(go run ./traceid_generator.go); do echo '${data.template_file.server_consumer.rendered}' | sed -e \"s/START_TIME/$START_TIME/\" > server_consumer.json; curl -H 'Content-Type: application/json' -d @server_consumer.json -i http://127.0.0.1:4318/v1/metrics --verbose; echo '${data.template_file.client_producer.rendered}' | sed -e \"s/START_TIME/$START_TIME/\" > client_producer.json; curl -H 'Content-Type: application/json' -d @client_producer.json -i http://127.0.0.1:4318/v1/metrics --verbose; echo '${data.template_file.traces.rendered}' | sed -e \"s/START_TIME/$START_TIME/\" | sed -e \"s/TRACE_ID/$TRACE_ID/\" > traces.json; curl -H 'Content-Type: application/json' -d @traces.json -i http://127.0.0.1:4318/v1/traces --verbose; sleep 1; done"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what this is doing, but I think it's still hard to follow. Can we build the generator?

nit: There has to be a better way to mount the files you need to run in this container instead of the template rendering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ideally we can build the generator bin, and mount it on a volume along with the other json files. The templating comes from the metric tests which I've borrowed.

I could try to spend some time to make this cleaner and easier to follow

]
env {
name = "HOST_IP"
Expand Down Expand Up @@ -378,9 +383,11 @@ resource "kubernetes_daemonset" "service" {
# Template Files
##########################################
locals {
cwagent_config = "../../../../${var.test_dir}/resources/config.json"
server_consumer = "../../../../${var.test_dir}/resources/server_consumer.json"
client_producer = "../../../../${var.test_dir}/resources/client_producer.json"
cwagent_config = "../../../../${var.test_dir}/resources/config.json"
server_consumer = "../../../../${var.test_dir}/resources/metrics/server_consumer.json"
client_producer = "../../../../${var.test_dir}/resources/metrics/client_producer.json"
traces = "../../../../${var.test_dir}/resources/traces/traces.json"
traceid_generator = "../../../../${var.test_dir}/resources/traceid_generator.go"
}

data "template_file" "cwagent_config" {
Expand Down Expand Up @@ -415,6 +422,18 @@ data "template_file" "client_producer" {
}
}

data "template_file" "traces" {
template = file(local.traces)
vars = {
}
}
Comment on lines +425 to +429
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Use local_file instead of template_file if it isn't templating anything.

Suggested change
data "template_file" "traces" {
template = file(local.traces)
vars = {
}
}
data "local_file" "traces" {
filename = local.traces
}


data "template_file" "traceid_generator" {
template = file(local.traceid_generator)
vars = {
}
}

resource "kubernetes_service_account" "cwagentservice" {
depends_on = [kubernetes_namespace.namespace]
metadata {
Expand Down Expand Up @@ -487,9 +506,9 @@ resource "null_resource" "validator" {
]
provisioner "local-exec" {
command = <<-EOT
echo "Validating EKS metrics/logs for AMF"
echo "Validating EKS metrics/traces for APM"
cd ../../../..
go test ${var.test_dir} -eksClusterName=${aws_eks_cluster.this.name} -computeType=EKS -v -eksDeploymentStrategy=DAEMON
go test ${var.test_dir} -timeout 1h -eksClusterName=${aws_eks_cluster.this.name} -computeType=EKS -v -eksDeploymentStrategy=DAEMON
EOT
}
}
9 changes: 7 additions & 2 deletions test/apm/apm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
const (
APMServerConsumerTestName = "APM-Server-Consumer"
APMClientProducerTestName = "APM-Client-Producer"
APMTracesTestName = "APM-Traces"
)

type APMTestSuite struct {
Expand Down Expand Up @@ -52,11 +53,15 @@ func getEksTestRunners(env *environment.MetaData) []*test_runner.EKSTestRunner {

eksTestRunners = []*test_runner.EKSTestRunner{
{
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMServerConsumerTestName, "EKS.Cluster"},
Runner: &APMMetricsRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMServerConsumerTestName, "EKS.Cluster"},
Env: *env,
},
{
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMClientProducerTestName, "EKS.Cluster"},
Runner: &APMMetricsRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMClientProducerTestName, "EKS.Cluster"},
Env: *env,
},
{
Runner: &APMTracesRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMTracesTestName, env.EKSClusterName},
Env: *env,
},
}
Expand Down
14 changes: 7 additions & 7 deletions test/apm/default_test.go → test/apm/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (
const testRetryCount = 3
const namespace = "AWS/APM"

type APMRunner struct {
type APMMetricsRunner struct {
test_runner.BaseTestRunner
testName string
dimensionKey string
}

func (t *APMRunner) Validate() status.TestGroupResult {
func (t *APMMetricsRunner) Validate() status.TestGroupResult {
metricsToFetch := t.GetMeasuredMetrics()
testResults := make([]status.TestResult, len(metricsToFetch))
instructions := GetInstructionsFromTestName(t.testName)
Expand All @@ -45,19 +45,19 @@ func (t *APMRunner) Validate() status.TestGroupResult {
}
}

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

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

func (t *APMRunner) GetMeasuredMetrics() []string {
func (t *APMMetricsRunner) GetMeasuredMetrics() []string {
return metric.APMMetricNames
}

func (e *APMRunner) GetAgentConfigFileName() string {
func (e *APMMetricsRunner) GetAgentConfigFileName() string {
return ""
}

Expand All @@ -72,4 +72,4 @@ func GetInstructionsFromTestName(testName string) []dimension.Instruction {
}
}

var _ test_runner.ITestRunner = (*APMRunner)(nil)
var _ test_runner.ITestRunner = (*APMMetricsRunner)(nil)
17 changes: 17 additions & 0 deletions test/apm/resources/traceid_generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

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

func main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that this is probably to avoid dependencies, but https://github.com/open-telemetry/opentelemetry-go-contrib/tree/main/propagators/aws/xray provides an ID generator, which is what customers would be using as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice! I can look into this

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[:]))
}
90 changes: 90 additions & 0 deletions test/apm/resources/traces/traces.json
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": "apm-integration-test"
},
"spans": [
{
"traceId": "TRACE_ID",
"spanId": "EEE19B7EC3C1B174",
"parentSpanId": "EEE19B7EC3C1B173",
"name": "apm-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"
}
}
]
}
]
}
]
}
]
}
Loading