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 all 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
43 changes: 31 additions & 12 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 @@ -213,8 +218,8 @@ resource "kubernetes_daemonset" "service" {
}
}
port {
container_port = 4318
host_port = 4318
container_port = 4316
host_port = 4316
protocol = "TCP"
}
env {
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:4316/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:4316/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:4316/v1/traces --verbose; sleep 1; done"
]
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, "HostedIn.EKS.Cluster"},
Env: *env,
},
{
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMClientProducerTestName, "EKS.Cluster"},
Runner: &APMMetricsRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMClientProducerTestName, "HostedIn.EKS.Cluster"},
Env: *env,
},
{
Runner: &APMTracesRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMTracesTestName, env.EKSClusterName},
Env: *env,
},
}
Expand Down
20 changes: 10 additions & 10 deletions test/apm/default_test.go → test/apm/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (
"time"
)

const testRetryCount = 3
const testRetryCount = 6
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 @@ -34,7 +34,7 @@ func (t *APMRunner) Validate() status.TestGroupResult {
if testResult.Status == status.SUCCESSFUL {
break
}
time.Sleep(15 * time.Second)
time.Sleep(30 * time.Second)
}
testResults[i] = testResult
}
Expand All @@ -45,24 +45,24 @@ 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 ""
}

func GetInstructionsFromTestName(testName string) []dimension.Instruction {
switch testName{
switch testName {
case APMClientProducerTestName:
return metric.ClientProducerInstructions
case APMServerConsumerTestName:
Expand All @@ -72,4 +72,4 @@ func GetInstructionsFromTestName(testName string) []dimension.Instruction {
}
}

var _ test_runner.ITestRunner = (*APMRunner)(nil)
var _ test_runner.ITestRunner = (*APMMetricsRunner)(nil)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{
"key": "aws.deployment.name",
"value": {
"stringValue": "service-name"
"stringValue": "deployment-name"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
{
"key": "aws.span.kind",
"value": {
"stringValue": "CONSUMER"
"stringValue": "SERVER"
}
},
{
Expand Down
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