|  | 
|  | 1 | +## Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | 
|  | 2 | +## SPDX-License-Identifier: Apache-2.0 | 
|  | 3 | + | 
|  | 4 | +# This is a reusable workflow for running the Enablement test for App Signals. | 
|  | 5 | +# It is meant to be called from another workflow. | 
|  | 6 | +# Read more about reusable workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview | 
|  | 7 | +name: Node Lambda Use Case | 
|  | 8 | +on: | 
|  | 9 | +  workflow_call: | 
|  | 10 | +    inputs: | 
|  | 11 | +      aws-region: | 
|  | 12 | +        required: true | 
|  | 13 | +        type: string | 
|  | 14 | +      caller-workflow-name: | 
|  | 15 | +        required: true | 
|  | 16 | +        type: string | 
|  | 17 | +      staging-instrumentation-name: | 
|  | 18 | +        required: false | 
|  | 19 | +        default: '@aws/aws-distro-opentelemetry-node-autoinstrumentation' | 
|  | 20 | +        type: string | 
|  | 21 | +    outputs: | 
|  | 22 | +      job-started: | 
|  | 23 | +        value: ${{ jobs.node-lambda-default.outputs.job-started }} | 
|  | 24 | +      validation-result: | 
|  | 25 | +        value: ${{ jobs.node-lambda-default.outputs.validation-result }} | 
|  | 26 | + | 
|  | 27 | +permissions: | 
|  | 28 | +  id-token: write | 
|  | 29 | +  contents: read | 
|  | 30 | + | 
|  | 31 | +env: | 
|  | 32 | +  E2E_TEST_AWS_REGION: ${{ inputs.aws-region }} | 
|  | 33 | +  CALLER_WORKFLOW_NAME: ${{ inputs.caller-workflow-name }} | 
|  | 34 | +  E2E_TEST_ACCOUNT_ID: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }} | 
|  | 35 | +  E2E_TEST_ROLE_NAME: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }} | 
|  | 36 | +  METRIC_NAMESPACE: ApplicationSignals | 
|  | 37 | +  LOG_GROUP_NAME: /aws/application-signals/data | 
|  | 38 | +  TEST_RESOURCES_FOLDER: ${GITHUB_WORKSPACE} | 
|  | 39 | + | 
|  | 40 | +jobs: | 
|  | 41 | +  node-lambda-default: | 
|  | 42 | +    runs-on: ubuntu-latest | 
|  | 43 | +    timeout-minutes: 30 | 
|  | 44 | +    outputs: | 
|  | 45 | +      job-started: ${{ steps.job-started.outputs.job-started }} | 
|  | 46 | +      validation-result: ${{ steps.validation-result.outputs.validation-result }} | 
|  | 47 | +    steps: | 
|  | 48 | +      - name: Check if the job started | 
|  | 49 | +        id: job-started | 
|  | 50 | +        run: echo "job-started=true" >> $GITHUB_OUTPUT | 
|  | 51 | + | 
|  | 52 | +      - name: Generate testing id | 
|  | 53 | +        run: echo TESTING_ID="${{ github.job }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV | 
|  | 54 | + | 
|  | 55 | +      - uses: actions/checkout@v4 | 
|  | 56 | +        with: | 
|  | 57 | +          repository: 'aws-observability/aws-application-signals-test-framework' | 
|  | 58 | +          ref: ${{ env.CALLER_WORKFLOW_NAME == 'main-build' && 'main' || github.ref }} | 
|  | 59 | +          fetch-depth: 0 | 
|  | 60 | + | 
|  | 61 | +      # We initialize Gradlew Daemon early on during the workflow because sometimes initialization | 
|  | 62 | +      # fails due to transient issues. If it fails here, then we will try again later before the validators | 
|  | 63 | +      - name: Initiate Gradlew Daemon | 
|  | 64 | +        id: initiate-gradlew | 
|  | 65 | +        uses: ./.github/workflows/actions/execute_and_retry | 
|  | 66 | +        continue-on-error: true | 
|  | 67 | +        with: | 
|  | 68 | +          command: "./gradlew :validator:build" | 
|  | 69 | +          cleanup: "./gradlew clean" | 
|  | 70 | +          max_retry: 3 | 
|  | 71 | +          sleep_time: 60 | 
|  | 72 | + | 
|  | 73 | +      - name: Configure AWS Credentials | 
|  | 74 | +        uses: aws-actions/configure-aws-credentials@v4 | 
|  | 75 | +        with: | 
|  | 76 | +          role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }} | 
|  | 77 | +          aws-region: us-east-1 | 
|  | 78 | + | 
|  | 79 | +      - name: Retrieve account | 
|  | 80 | +        uses: aws-actions/aws-secretsmanager-get-secrets@v1 | 
|  | 81 | +        with: | 
|  | 82 | +          secret-ids: | 
|  | 83 | +            ACCOUNT_ID, region-account/${{ env.E2E_TEST_AWS_REGION }} | 
|  | 84 | + | 
|  | 85 | +      # If the workflow is running as a canary, then we want to log in to the aws account in the appropriate region | 
|  | 86 | +      - name: Configure AWS Credentials | 
|  | 87 | +        if: ${{ github.event.repository.name == 'aws-application-signals-test-framework' }} | 
|  | 88 | +        uses: aws-actions/configure-aws-credentials@v4 | 
|  | 89 | +        with: | 
|  | 90 | +          role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }} | 
|  | 91 | +          aws-region: ${{ env.E2E_TEST_AWS_REGION }} | 
|  | 92 | + | 
|  | 93 | +      - name: Set Lambda Layer artifact directory path | 
|  | 94 | +        run: echo ARTIFACTS_DIR="${{ github.workspace }}/lambda_artifacts" >> $GITHUB_ENV | 
|  | 95 | + | 
|  | 96 | +      - name: Download Lambda Layer and Function artifacts | 
|  | 97 | +        run: | | 
|  | 98 | +          aws s3 cp s3://adot-autoinstrumentation-node-staging/layer-${{ github.run_id }}.zip ${{ env.ARTIFACTS_DIR }}/layer.zip | | 
|  | 99 | +          aws s3 cp s3://adot-autoinstrumentation-node-staging/function-${{ github.run_id }}.zip ${{ env.ARTIFACTS_DIR }}/function.zip | 
|  | 100 | +
 | 
|  | 101 | +      - name: Set up terraform | 
|  | 102 | +        uses: ./.github/workflows/actions/execute_and_retry | 
|  | 103 | +        with: | 
|  | 104 | +          command: "wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg" | 
|  | 105 | +          post-command: 'echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list | 
|  | 106 | +              && sudo apt update && sudo apt install terraform' | 
|  | 107 | +          sleep_time: 60 | 
|  | 108 | + | 
|  | 109 | +      - name: Initiate Terraform | 
|  | 110 | +        uses: ./.github/workflows/actions/execute_and_retry | 
|  | 111 | +        with: | 
|  | 112 | +          command: "cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/node/lambda/lambda && terraform init && terraform validate" | 
|  | 113 | +          cleanup: "rm -rf .terraform && rm -rf .terraform.lock.hcl" | 
|  | 114 | +          max_retry: 6 | 
|  | 115 | +          sleep_time: 60 | 
|  | 116 | + | 
|  | 117 | +      - name: Get terraform Lambda function name | 
|  | 118 | +        shell: bash | 
|  | 119 | +        run: | | 
|  | 120 | +          echo TERRAFORM_LAMBDA_FUNCTION_NAME="AdotLambdaNodeJsSampleApp-${{ github.run_id }}"| | 
|  | 121 | +          tee --append $GITHUB_ENV | 
|  | 122 | +      - name: Apply terraform | 
|  | 123 | +        uses: ./.github/workflows/actions/execute_and_retry | 
|  | 124 | +        with: | 
|  | 125 | +          command: 'cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/node/lambda/lambda && terraform apply -auto-approve  | 
|  | 126 | +          -var="sdk_layer_name=AWSOpenTelemetryDistroJs-${{ github.run_id }}"  | 
|  | 127 | +          -var="function_name=${{env.TERRAFORM_LAMBDA_FUNCTION_NAME}}" -var="layer_artifacts_directory=${{ env.ARTIFACTS_DIR }}"' | 
|  | 128 | +          max_retry: 6 | 
|  | 129 | +          sleep_time: 60 | 
|  | 130 | +      - name: Extract endpoint | 
|  | 131 | +        id: extract-endpoint | 
|  | 132 | +        shell: bash | 
|  | 133 | +        run: cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/node/lambda/lambda && echo API_GATEWAY_URL=$(terraform output -raw api-gateway-url) >> $GITHUB_ENV | 
|  | 134 | +      - name: Send request to endpoint | 
|  | 135 | +        shell: bash | 
|  | 136 | +        run: sleep 30s; curl -sS ${{ env.API_GATEWAY_URL }} | 
|  | 137 | + | 
|  | 138 | +      # Validation for pulse telemetry data | 
|  | 139 | +      - name: Validate generated EMF logs | 
|  | 140 | +        id: log-validation | 
|  | 141 | +        run: ./gradlew validator:run --args='-c node/lambda/log-validation.yml | 
|  | 142 | +          --testing-id ${{ env.TESTING_ID }} | 
|  | 143 | +          --endpoint http://${{ env.API_GATEWAY_URL }} | 
|  | 144 | +          --region ${{ inputs.aws-region }} | 
|  | 145 | +          --account-id ${{ env.ACCOUNT_ID }} | 
|  | 146 | +          --metric-namespace ${{ env.METRIC_NAMESPACE }} | 
|  | 147 | +          --log-group ${{ env.LOG_GROUP_NAME }} | 
|  | 148 | +          --service-name ${{ env.TERRAFORM_LAMBDA_FUNCTION_NAME }} | 
|  | 149 | +          --rollup' | 
|  | 150 | + | 
|  | 151 | +      - name: Validate generated metrics | 
|  | 152 | +        id: metric-validation | 
|  | 153 | +        if: (success() || steps.log-validation.outcome == 'failure') && !cancelled() | 
|  | 154 | +        run: ./gradlew validator:run --args='-c node/lambda/metric-validation.yml | 
|  | 155 | +          --testing-id ${{ env.TESTING_ID }} | 
|  | 156 | +          --endpoint http://${{ env.API_GATEWAY_URL }} | 
|  | 157 | +          --region ${{ inputs.aws-region }} | 
|  | 158 | +          --account-id ${{ env.ACCOUNT_ID }} | 
|  | 159 | +          --metric-namespace ${{ env.METRIC_NAMESPACE }} | 
|  | 160 | +          --log-group ${{ env.LOG_GROUP_NAME }} | 
|  | 161 | +          --service-name ${{ env.TERRAFORM_LAMBDA_FUNCTION_NAME }} | 
|  | 162 | +          --rollup' | 
|  | 163 | + | 
|  | 164 | +      - name: Validate generated traces | 
|  | 165 | +        id: trace-validation | 
|  | 166 | +        if: (success() || steps.log-validation.outcome == 'failure' || steps.metric-validation.outcome == 'failure') && !cancelled() | 
|  | 167 | +        run: ./gradlew validator:run --args='-c node/lambda/trace-validation.yml | 
|  | 168 | +          --testing-id ${{ env.TESTING_ID }} | 
|  | 169 | +          --endpoint http://${{ env.API_GATEWAY_URL }} | 
|  | 170 | +          --region ${{ inputs.aws-region }} | 
|  | 171 | +          --account-id ${{ env.ACCOUNT_ID }} | 
|  | 172 | +          --metric-namespace ${{ env.METRIC_NAMESPACE }} | 
|  | 173 | +          --log-group ${{ env.LOG_GROUP_NAME }} | 
|  | 174 | +          --service-name ${{ env.TERRAFORM_LAMBDA_FUNCTION_NAME }} | 
|  | 175 | +          --rollup' | 
|  | 176 | + | 
|  | 177 | +      - name: Refresh AWS Credentials | 
|  | 178 | +        if: ${{ always() && github.event.repository.name == 'aws-application-signals-test-framework' }} | 
|  | 179 | +        uses: aws-actions/configure-aws-credentials@v4 | 
|  | 180 | +        with: | 
|  | 181 | +          role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }} | 
|  | 182 | +          aws-region: ${{ env.E2E_TEST_AWS_REGION }} | 
|  | 183 | + | 
|  | 184 | +      - name: Save test results | 
|  | 185 | +        if: always() | 
|  | 186 | +        id: validation-result | 
|  | 187 | +        run: | | 
|  | 188 | +          if [ "${{ steps.log-validation.outcome }}" = "success" ] && [ "${{ steps.metric-validation.outcome }}" = "success" ] && [ "${{ steps.trace-validation.outcome }}" = "success" ]; then | 
|  | 189 | +            echo "validation-result=success" >> $GITHUB_OUTPUT | 
|  | 190 | +          else | 
|  | 191 | +            echo "validation-result=failure" >> $GITHUB_OUTPUT | 
|  | 192 | +          fi | 
|  | 193 | +
 | 
|  | 194 | +      # Clean up Procedures | 
|  | 195 | +      - name: Terraform destroy | 
|  | 196 | +        if: always() | 
|  | 197 | +        continue-on-error: true | 
|  | 198 | +        run: | | 
|  | 199 | +          cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/node/lambda/lambda && terraform destroy -auto-approve \ | 
|  | 200 | +          -var="sdk_layer_name=AWSOpenTelemetryDistroJs-${{ github.run_id }}" \ | 
|  | 201 | +          -var="function_name=${{env.TERRAFORM_LAMBDA_FUNCTION_NAME}}" \ | 
|  | 202 | +          -var="layer_artifacts_directory=${{ env.ARTIFACTS_DIR }}" | 
0 commit comments