-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: add smoke testing #296
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
24f04b9
feat: add smoke testing
kruskall 2d8ffa6
feat: add support for creating elastic cloud deployments
kruskall 59ecb41
fix: use provided aws region when retrieving lambda layers
kruskall d496d2d
Merge branch 'main' into feat/smoke-testing
kruskall 59bb7e3
feat: move to custom modules in the apm-server repository
kruskall 780c697
build: add terraform gitignore
kruskall 9a09893
refactor: rename ec_region to ess_region
kruskall 866790f
docs: update template description
kruskall 60974ba
fix: move to gcp-us-west1 / CFT region
kruskall 01626d6
refactor: rename ec deployment template to ess deployment template
kruskall eadce13
feat: add bash script to validate smoke testing output
kruskall cff7ae7
lint: runt terraform fmt
kruskall 6b149c1
Merge branch 'main' into feat/smoke-testing
kruskall bf8a168
fix: explicitly pass the region to the aws cli
kruskall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
exports.handler = async (event) => { | ||
const response = { | ||
statusCode: 200, | ||
body: JSON.stringify('Hello from Lambda!'), | ||
}; | ||
return response; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.terraform/ | ||
|
||
*.tfstate | ||
*.tfstate.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
provider "aws" { | ||
region = var.aws_region | ||
} | ||
|
||
module "ec_deployment" { | ||
source = "github.com/elastic/apm-server//testing/infra/terraform/modules/ec_deployment?depth=1" | ||
deployment_name_prefix = "apm-aws-lambda-smoke-testing" | ||
integrations_server = true | ||
apm_server_expvar = false | ||
apm_server_pprof = false | ||
region = var.ess_region | ||
deployment_template = var.ess_deployment_template | ||
} | ||
|
||
module "lambda_function" { | ||
source = "terraform-aws-modules/lambda/aws" | ||
|
||
function_name = "smoke-testing-test" | ||
description = "Example Lambda function for smoke testing" | ||
handler = "index.handler" | ||
runtime = "nodejs16.x" | ||
|
||
source_path = "../testdata/function/" | ||
|
||
layers = [ | ||
module.lambda_layer_local.lambda_layer_arn, | ||
"arn:aws:lambda:${var.aws_region}:267093732750:layer:elastic-apm-node-ver-3-38-0:1", | ||
] | ||
|
||
environment_variables = { | ||
NODE_OPTIONS = "-r elastic-apm-node/start" | ||
ELASTIC_APM_LOG_LEVEL = var.log_level | ||
ELASTIC_APM_LAMBDA_APM_SERVER = module.ec_deployment.apm_url | ||
ELASTIC_APM_SECRET_TOKEN = module.ec_deployment.apm_secret_token | ||
} | ||
|
||
tags = { | ||
Name = "my-lambda" | ||
} | ||
} | ||
|
||
module "lambda_layer_local" { | ||
source = "terraform-aws-modules/lambda/aws" | ||
|
||
create_layer = true | ||
|
||
layer_name = "apm-lambda-extension-smoke-testing" | ||
description = "AWS Lambda Extension Layer for Elastic APM - smoke testing" | ||
compatible_runtimes = ["nodejs16.x"] | ||
|
||
source_path = "../bin/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
output "elasticsearch_url" { | ||
value = module.ec_deployment.elasticsearch_url | ||
description = "The secure Elasticsearch URL" | ||
} | ||
|
||
output "elasticsearch_username" { | ||
value = module.ec_deployment.elasticsearch_username | ||
description = "The Elasticsearch username" | ||
sensitive = true | ||
} | ||
|
||
output "elasticsearch_password" { | ||
value = module.ec_deployment.elasticsearch_password | ||
description = "The Elasticsearch password" | ||
sensitive = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">=4.28.0" | ||
} | ||
ec = { | ||
source = "elastic/ec" | ||
version = ">=0.4.1" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
export TF_IN_AUTOMATION=1 | ||
export TF_CLI_ARGS=-no-color | ||
|
||
cleanup() { | ||
terraform destroy -auto-approve >> tf.log | ||
} | ||
|
||
trap "cleanup" EXIT | ||
|
||
echo "-> Creating the underlying infrastructure..." | ||
terraform init | tee tf.log | ||
terraform apply -auto-approve | tee -a tf.log | ||
|
||
echo "-> Calling the lambda function..." | ||
aws lambda invoke --region=eu-central-1 --function-name smoke-testing-test response.json | ||
aws lambda invoke --region=eu-central-1 --function-name smoke-testing-test response.json | ||
|
||
echo "-> Waiting for the agent documents to be indexed in Elasticsearch..." | ||
|
||
ES_HOST=$(terraform output -raw elasticsearch_url) | ||
ES_USER=$(terraform output -raw elasticsearch_username) | ||
ES_PASS=$(terraform output -raw elasticsearch_password) | ||
|
||
hits=0 | ||
attempts=0 | ||
while [ ${hits} -eq 0 ]; do | ||
# Check that ES has transaction documents on the GET endpoint. | ||
resp=$(curl -s -H 'Content-Type: application/json' -u ${ES_USER}:${ES_PASS} "${ES_HOST}/traces-apm-*/_search" -d '{ | ||
"query": { | ||
"match": { | ||
"agent.name": "nodejs" | ||
} | ||
} | ||
}') | ||
hits=$(echo ${resp} | jq '.hits.total.value') | ||
if [[ ${attempts} -ge 30 ]]; then | ||
echo "-> Didn't find any traces for the NodeJS agents after ${attempts} attempts" | ||
exit 1 | ||
fi | ||
let "attempts+=1" | ||
sleep 1 | ||
done | ||
|
||
echo "-> Smoke tests passed!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
variable "aws_region" { | ||
type = string | ||
description = "aws region" | ||
default = "eu-central-1" | ||
} | ||
|
||
variable "log_level" { | ||
type = string | ||
description = "lambda extension log level" | ||
default = "trace" | ||
} | ||
|
||
variable "ess_region" { | ||
type = string | ||
description = "ess region" | ||
default = "gcp-us-west2" | ||
} | ||
|
||
variable "ess_deployment_template" { | ||
type = string | ||
description = "Elastic Cloud deployment template" | ||
default = "gcp-compute-optimized" | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, we'll end up using the latest SNAPSHOT versions, they may be broken and cause the smoke tests to fail. If we want to avoid that, then we need to provide an expression for a released version, such as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ I've opened #307 to track this