From ef8c0969ffeb38fe54bae5647d8f92be9bf87cfa Mon Sep 17 00:00:00 2001 From: Harry Date: Wed, 25 Sep 2024 17:39:37 -0700 Subject: [PATCH] Add CPU Architecture Input Option for Python EC2 --- .github/workflows/python-ec2-asg-test.yml | 15 +++++++++++++-- .github/workflows/python-ec2-canary.yml | 2 ++ .github/workflows/python-ec2-default-retry.yml | 6 ++++++ .github/workflows/python-ec2-default-test.yml | 13 ++++++++++++- terraform/python/ec2/asg/main.tf | 8 ++++---- terraform/python/ec2/asg/variables.tf | 4 ++++ terraform/python/ec2/default/main.tf | 8 ++++---- terraform/python/ec2/default/variables.tf | 4 ++++ .../python/ec2/asg/aws-sdk-call-trace.mustache | 2 +- .../python/ec2/asg/client-call-trace.mustache | 2 +- .../ec2/asg/outgoing-http-call-trace.mustache | 2 +- .../python/ec2/asg/remote-service-trace.mustache | 4 ++-- .../ec2/default/aws-sdk-call-trace.mustache | 2 +- .../python/ec2/default/client-call-trace.mustache | 2 +- .../ec2/default/outgoing-http-call-trace.mustache | 2 +- .../ec2/default/remote-service-trace.mustache | 4 ++-- 16 files changed, 59 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-ec2-asg-test.yml b/.github/workflows/python-ec2-asg-test.yml index 13c273dde..6882ad5fb 100644 --- a/.github/workflows/python-ec2-asg-test.yml +++ b/.github/workflows/python-ec2-asg-test.yml @@ -14,6 +14,11 @@ on: caller-workflow-name: required: true type: string + cpu-architecture: + description: "Permitted values: x86_64 or arm64" + required: false + type: string + default: "x86_64" staging-wheel-name: required: false default: 'aws-opentelemetry-distro' @@ -31,6 +36,7 @@ permissions: env: E2E_TEST_AWS_REGION: ${{ inputs.aws-region }} CALLER_WORKFLOW_NAME: ${{ inputs.caller-workflow-name }} + CPU_ARCHITECTURE: ${{ inputs.cpu-architecture }} ADOT_WHEEL_NAME: ${{ inputs.staging-wheel-name }} SAMPLE_APP_ZIP: s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/python-sample-app.zip E2E_TEST_ACCOUNT_ID: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }} @@ -52,7 +58,7 @@ jobs: run: echo "job-started=true" >> $GITHUB_OUTPUT - name: Generate testing id - run: echo TESTING_ID="${{ github.job }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV + run: echo TESTING_ID="${{ github.run_id }}-${{ github.run_number }}-${RANDOM}" >> $GITHUB_ENV - uses: actions/checkout@v4 with: @@ -107,7 +113,11 @@ jobs: # Reusing the adot-main-build-staging-jar bucket to store the python wheel file echo 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" >> $GITHUB_ENV else - echo GET_CW_AGENT_RPM_COMMAND="wget -O cw-agent.rpm https://amazoncloudwatch-agent-${{ env.E2E_TEST_AWS_REGION }}.s3.${{ env.E2E_TEST_AWS_REGION }}.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV + if [ "${{ env.CPU_ARCHITECTURE }}" = "x86_64" ]; then + echo GET_CW_AGENT_RPM_COMMAND="wget -O cw-agent.rpm https://amazoncloudwatch-agent-${{ inputs.aws-region }}.s3.${{ inputs.aws-region }}.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV + elif [ "${{ env.CPU_ARCHITECTURE }}" = "arm64" ]; then + echo GET_CW_AGENT_RPM_COMMAND="wget -O cw-agent.rpm https://amazoncloudwatch-agent-${{ inputs.aws-region }}.s3.${{ inputs.aws-region }}.amazonaws.com/amazon_linux/arm64/latest/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV + fi fi - name: Set up terraform @@ -144,6 +154,7 @@ jobs: -var="sample_app_zip=${{ env.SAMPLE_APP_ZIP }}" \ -var="get_cw_agent_rpm_command=${{ env.GET_CW_AGENT_RPM_COMMAND }}" \ -var="get_adot_wheel_command=${{ env.GET_ADOT_WHEEL_COMMAND }}" \ + -var="cpu_architecture=${{ env.CPU_ARCHITECTURE }}" \ || deployment_failed=$? if [ $deployment_failed -eq 1 ]; then diff --git a/.github/workflows/python-ec2-canary.yml b/.github/workflows/python-ec2-canary.yml index 0514d03e9..1493f8177 100644 --- a/.github/workflows/python-ec2-canary.yml +++ b/.github/workflows/python-ec2-canary.yml @@ -29,6 +29,7 @@ jobs: with: aws-region: ${{ matrix.aws-region }} caller-workflow-name: 'appsignals-python-e2e-ec2-canary-test' + cpu-architecture: 'x86_64' pypi: uses: ./.github/workflows/python-ec2-default-retry.yml @@ -37,3 +38,4 @@ jobs: aws-region: 'us-east-1' caller-workflow-name: 'appsignals-python-e2e-ec2-pypi-canary-test' otel-source: 'pypi' + cpu-architecture: 'x86_64' diff --git a/.github/workflows/python-ec2-default-retry.yml b/.github/workflows/python-ec2-default-retry.yml index 8d1fe393c..1288c1976 100644 --- a/.github/workflows/python-ec2-default-retry.yml +++ b/.github/workflows/python-ec2-default-retry.yml @@ -18,6 +18,10 @@ on: required: false default: 'aws-opentelemetry-distro' type: string + cpu-architecture: + required: false + type: string + default: "x86_64" otel-source: required: false type: string @@ -36,6 +40,7 @@ jobs: caller-workflow-name: ${{ inputs.caller-workflow-name }} staging-wheel-name: ${{ inputs.staging-wheel-name }} otel-source: ${{ inputs.otel-source }} + cpu-architecture: ${{ inputs.cpu-architecture }} python-ec2-default-attempt-2: needs: [ python-ec2-default-attempt-1 ] @@ -47,6 +52,7 @@ jobs: caller-workflow-name: ${{ inputs.caller-workflow-name }} staging-wheel-name: ${{ inputs.staging-wheel-name }} otel-source: ${{ inputs.otel-source }} + cpu-architecture: ${{ inputs.cpu-architecture }} publish-metric-attempt-1: needs: [ python-ec2-default-attempt-1, python-ec2-default-attempt-2 ] diff --git a/.github/workflows/python-ec2-default-test.yml b/.github/workflows/python-ec2-default-test.yml index 586861506..718d36e2a 100644 --- a/.github/workflows/python-ec2-default-test.yml +++ b/.github/workflows/python-ec2-default-test.yml @@ -14,6 +14,11 @@ on: caller-workflow-name: required: true type: string + cpu-architecture: + description: "Permitted values: x86_64 or arm64" + required: false + type: string + default: "x86_64" staging-wheel-name: required: false default: 'aws-opentelemetry-distro' @@ -35,6 +40,7 @@ permissions: env: E2E_TEST_AWS_REGION: ${{ inputs.aws-region }} CALLER_WORKFLOW_NAME: ${{ inputs.caller-workflow-name }} + CPU_ARCHITECTURE: ${{ inputs.cpu-architecture }} ADOT_WHEEL_NAME: ${{ inputs.staging-wheel-name }} OTEL_SOURCE: ${{ inputs.otel-source }} SAMPLE_APP_ZIP: s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/python-sample-app.zip @@ -116,7 +122,11 @@ jobs: # Reusing the adot-main-build-staging-jar bucket to store the python wheel file echo 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" >> $GITHUB_ENV else - echo GET_CW_AGENT_RPM_COMMAND="wget -O cw-agent.rpm https://amazoncloudwatch-agent-${{ env.E2E_TEST_AWS_REGION }}.s3.${{ env.E2E_TEST_AWS_REGION }}.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV + if [ "${{ env.CPU_ARCHITECTURE }}" = "x86_64" ]; then + echo GET_CW_AGENT_RPM_COMMAND="wget -O cw-agent.rpm https://amazoncloudwatch-agent-${{ inputs.aws-region }}.s3.${{ inputs.aws-region }}.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV + elif [ "${{ env.CPU_ARCHITECTURE }}" = "arm64" ]; then + echo GET_CW_AGENT_RPM_COMMAND="wget -O cw-agent.rpm https://amazoncloudwatch-agent-${{ inputs.aws-region }}.s3.${{ inputs.aws-region }}.amazonaws.com/amazon_linux/arm64/latest/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV + fi fi - name: Set up terraform @@ -153,6 +163,7 @@ jobs: -var="sample_app_zip=${{ env.SAMPLE_APP_ZIP }}" \ -var="get_cw_agent_rpm_command=${{ env.GET_CW_AGENT_RPM_COMMAND }}" \ -var="get_adot_wheel_command=${{ env.GET_ADOT_WHEEL_COMMAND }}" \ + -var="cpu_architecture=${{ env.CPU_ARCHITECTURE }}" \ || deployment_failed=$? if [ $deployment_failed -eq 1 ]; then diff --git a/terraform/python/ec2/asg/main.tf b/terraform/python/ec2/asg/main.tf index 90e54d0e8..f3ca95b41 100644 --- a/terraform/python/ec2/asg/main.tf +++ b/terraform/python/ec2/asg/main.tf @@ -53,7 +53,7 @@ data "aws_ami" "ami" { most_recent = true filter { name = "name" - values = ["al20*-ami-minimal-*-x86_64"] + values = ["al20*-ami-minimal-*-${var.cpu_architecture}"] } filter { name = "state" @@ -61,7 +61,7 @@ data "aws_ami" "ami" { } filter { name = "architecture" - values = ["x86_64"] + values = [var.cpu_architecture] } filter { name = "image-type" @@ -86,7 +86,7 @@ data "aws_ami" "ami" { resource "aws_launch_configuration" "launch_configuration" { image_id = data.aws_ami.ami.id - instance_type = "t3.micro" + instance_type = var.cpu_architecture == "x86_64" ? "t3.micro" : "t4g.micro" key_name = local.ssh_key_name associate_public_ip_address = true iam_instance_profile = "APP_SIGNALS_EC2_TEST_ROLE" @@ -172,7 +172,7 @@ resource "aws_autoscaling_group" "asg" { resource "aws_instance" "remote_service_instance" { ami = data.aws_ami.ami.id # Amazon Linux 2 (free tier) - instance_type = "t3.micro" + instance_type = var.cpu_architecture == "x86_64" ? "t3.micro" : "t4g.micro" key_name = local.ssh_key_name iam_instance_profile = "APP_SIGNALS_EC2_TEST_ROLE" vpc_security_group_ids = [aws_default_vpc.default.default_security_group_id] diff --git a/terraform/python/ec2/asg/variables.tf b/terraform/python/ec2/asg/variables.tf index e8d222901..2e6a19c76 100644 --- a/terraform/python/ec2/asg/variables.tf +++ b/terraform/python/ec2/asg/variables.tf @@ -39,4 +39,8 @@ variable "get_cw_agent_rpm_command" { variable "canary_type" { default = "python-ec2-asg" +} + +variable "cpu_architecture" { + default = "x86_64" } \ No newline at end of file diff --git a/terraform/python/ec2/default/main.tf b/terraform/python/ec2/default/main.tf index 8e2ddf821..ba5494d70 100644 --- a/terraform/python/ec2/default/main.tf +++ b/terraform/python/ec2/default/main.tf @@ -46,7 +46,7 @@ data "aws_ami" "ami" { most_recent = true filter { name = "name" - values = ["al20*-ami-minimal-*-x86_64"] + values = ["al20*-ami-minimal-*-${var.cpu_architecture}"] } filter { name = "state" @@ -54,7 +54,7 @@ data "aws_ami" "ami" { } filter { name = "architecture" - values = ["x86_64"] + values = [var.cpu_architecture] } filter { name = "image-type" @@ -79,7 +79,7 @@ data "aws_ami" "ami" { resource "aws_instance" "main_service_instance" { ami = data.aws_ami.ami.id # Amazon Linux 2 (free tier) - instance_type = "t3.small" + instance_type = var.cpu_architecture == "x86_64" ? "t3.micro" : "t4g.micro" key_name = local.ssh_key_name iam_instance_profile = "APP_SIGNALS_EC2_TEST_ROLE" vpc_security_group_ids = [aws_default_vpc.default.default_security_group_id] @@ -174,7 +174,7 @@ resource "null_resource" "main_service_setup" { resource "aws_instance" "remote_service_instance" { ami = data.aws_ami.ami.id # Amazon Linux 2 (free tier) - instance_type = "t3.small" + instance_type = var.cpu_architecture == "x86_64" ? "t3.micro" : "t4g.micro" key_name = local.ssh_key_name iam_instance_profile = "APP_SIGNALS_EC2_TEST_ROLE" vpc_security_group_ids = [aws_default_vpc.default.default_security_group_id] diff --git a/terraform/python/ec2/default/variables.tf b/terraform/python/ec2/default/variables.tf index 8d37e0bc3..c4b2910b8 100644 --- a/terraform/python/ec2/default/variables.tf +++ b/terraform/python/ec2/default/variables.tf @@ -39,4 +39,8 @@ variable "get_cw_agent_rpm_command" { variable "canary_type" { default = "python-ec2-default" +} + +variable "cpu_architecture" { + default = "x86_64" } \ No newline at end of file diff --git a/validator/src/main/resources/expected-data-template/python/ec2/asg/aws-sdk-call-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/asg/aws-sdk-call-trace.mustache index 34df28edf..7e5230b24 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/asg/aws-sdk-call-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/asg/aws-sdk-call-trace.mustache @@ -25,7 +25,7 @@ "otel.resource.ec2.tag.aws:autoscaling:groupName": "^{{platformInfo}}$", "otel.resource.host.id": "^{{instanceId}}$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.micro$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "otel.resource.host.name": "^{{privateDnsName}}$", "aws.span.kind": "^LOCAL_ROOT$" } diff --git a/validator/src/main/resources/expected-data-template/python/ec2/asg/client-call-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/asg/client-call-trace.mustache index 2dd3f6369..1d76ddbd8 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/asg/client-call-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/asg/client-call-trace.mustache @@ -8,7 +8,7 @@ "metadata": { "default": { "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.micro$" + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$" } }, "subsegments": [ diff --git a/validator/src/main/resources/expected-data-template/python/ec2/asg/outgoing-http-call-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/asg/outgoing-http-call-trace.mustache index 00e88902e..526b5a9a9 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/asg/outgoing-http-call-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/asg/outgoing-http-call-trace.mustache @@ -25,7 +25,7 @@ "otel.resource.host.id": "^{{instanceId}}$", "PlatformType": "^AWS::EC2$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.micro$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "otel.resource.host.name": "^{{privateDnsName}}$", "aws.span.kind": "^LOCAL_ROOT$" } diff --git a/validator/src/main/resources/expected-data-template/python/ec2/asg/remote-service-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/asg/remote-service-trace.mustache index 93297010f..d93baefde 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/asg/remote-service-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/asg/remote-service-trace.mustache @@ -25,7 +25,7 @@ "otel.resource.ec2.tag.aws:autoscaling:groupName": "^{{platformInfo}}$", "otel.resource.host.id": "^{{instanceId}}$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.micro$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "otel.resource.host.name": "^{{privateDnsName}}$", "aws.span.kind": "^LOCAL_ROOT$" } @@ -76,7 +76,7 @@ "EC2.InstanceId": "^i-[A-Za-z0-9]{17}$", "PlatformType": "^AWS::EC2$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.micro$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "aws.span.kind": "^LOCAL_ROOT$" } } diff --git a/validator/src/main/resources/expected-data-template/python/ec2/default/aws-sdk-call-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/default/aws-sdk-call-trace.mustache index 87290c1fd..75050a440 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/default/aws-sdk-call-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/default/aws-sdk-call-trace.mustache @@ -22,7 +22,7 @@ "EC2.InstanceId": "^{{instanceId}}$", "PlatformType": "^AWS::EC2$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.small$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "aws.span.kind": "^LOCAL_ROOT$" } }, diff --git a/validator/src/main/resources/expected-data-template/python/ec2/default/client-call-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/default/client-call-trace.mustache index b43b46f0e..27afa67bc 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/default/client-call-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/default/client-call-trace.mustache @@ -8,7 +8,7 @@ "metadata": { "default": { "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.small$" + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$" } }, "subsegments": [ diff --git a/validator/src/main/resources/expected-data-template/python/ec2/default/outgoing-http-call-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/default/outgoing-http-call-trace.mustache index 602349411..9f44d4c1b 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/default/outgoing-http-call-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/default/outgoing-http-call-trace.mustache @@ -22,7 +22,7 @@ "EC2.InstanceId": "^{{instanceId}}$", "PlatformType": "^AWS::EC2$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.small$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "aws.span.kind": "^LOCAL_ROOT$" } }, diff --git a/validator/src/main/resources/expected-data-template/python/ec2/default/remote-service-trace.mustache b/validator/src/main/resources/expected-data-template/python/ec2/default/remote-service-trace.mustache index 3e87c72a9..05a40a8b8 100644 --- a/validator/src/main/resources/expected-data-template/python/ec2/default/remote-service-trace.mustache +++ b/validator/src/main/resources/expected-data-template/python/ec2/default/remote-service-trace.mustache @@ -22,7 +22,7 @@ "EC2.InstanceId": "^{{instanceId}}$", "PlatformType": "^AWS::EC2$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.small$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "aws.span.kind": "^LOCAL_ROOT$" } }, @@ -71,7 +71,7 @@ "EC2.InstanceId": "^i-[A-Za-z0-9]{17}$", "PlatformType": "^AWS::EC2$", "otel.resource.host.image.id": "^{{instanceAmi}}$", - "otel.resource.host.type": "^t3.small$", + "otel.resource.host.type": "^([a-z0-9]+\\.[a-z0-9]+)$", "aws.span.kind": "^LOCAL_ROOT$" } }