diff --git a/.github/workflows/fastPeformanceTest.yml b/.github/workflows/fastPeformanceTest.yml new file mode 100644 index 0000000000..7f1342d458 --- /dev/null +++ b/.github/workflows/fastPeformanceTest.yml @@ -0,0 +1,275 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: MIT + +name: Fast Performance Test +env: + PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }} + TERRAFORM_AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + TERRAFORM_AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + S3_INTEGRATION_BUCKET: ${{ secrets.S3_INTEGRATION_BUCKET }} + KEY_NAME: ${{ secrets.KEY_NAME }} + VPC_SECURITY_GROUPS_IDS: ${{ secrets.VPC_SECURITY_GROUPS_IDS }} + IAM_ROLE: ${{ secrets.IAM_ROLE }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + PASSPHRASE: ${{ secrets.PASSPHRASE }} + GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }} + GPG_TTY: $(tty) + ECR_INTEGRATION_TEST_REPO: "cwagent-integration-test" + +on: + push: + branches: + - workflow + + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + MakeBinary: + name: 'MakeBinary' + runs-on: ubuntu-latest + steps: + # Set up building environment, patch the dev repo code on dispatch events. + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ~1.18.3 + + - name: Install rpm + run: sudo apt install rpm + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: 'true' + + - name: Cache go + id: cached_go + uses: actions/cache@v2 + env: + cache-name: cached_go_modules + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: v1-go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.sum') }} + + - name: Cache binaries + id: cached_binaries + uses: actions/cache@v2 + with: + key: "cached_binaries_${{ github.sha }}" + path: go.mod + + - name: Build Binaries + if: steps.cached_binaries.outputs.cache-hit != 'true' + run: make build package-rpm package-deb package-win package-darwin + + - uses: olafurpg/setup-gpg@v3 + + - name: Sign packages + if: steps.cached_binaries.outputs.cache-hit != 'true' + run: | + echo "${GPG_PRIVATE_KEY}" | gpg --batch --import - + for f in $(find build/bin/); do if [ ! -d $f ]; then echo "Signing file $f" && echo "${PASSPHRASE}" | gpg --detach-sign --passphrase-fd 0 --batch --default-key "${GPG_KEY_NAME}" $f ; fi ; done + + - name: Upload to s3 + if: steps.cached_binaries.outputs.cache-hit != 'true' + run: aws s3 cp build/bin s3://${S3_INTEGRATION_BUCKET}/integration-test/binary/${{ github.sha }} --recursive + + GenerateTestMatrix: + name: 'GenerateTestMatrix' + runs-on: ubuntu-latest + outputs: + ec2_linux_matrix: ${{ steps.set-matrix.outputs.ec2_linux_matrix }} + ec2_performance_matrix: ${{steps.set-matrix.outputs.ec2_performance_matrix}} + ec2_windows_matrix: ${{ steps.set-matrix.outputs.ec2_windows_matrix }} + ecs_fargate_matrix: ${{ steps.set-matrix.outputs.ecs_fargate_matrix }} + steps: + - uses: actions/checkout@v2 + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ~1.18.3 + + - name: Generate matrix + id: set-matrix + run: | + go run --tags=generator integration/generator/test_case_generator.go + echo "::set-output name=ec2_linux_matrix::$(echo $(cat integration/generator/resources/ec2_linux_complete_test_matrix.json))" + echo "::set-output name=ec2_performance_matrix::$(echo $(cat integration/generator/resources/ec2_performance_complete_test_matrix.json))" + echo "::set-output name=ec2_windows_matrix::$(echo $(cat integration/generator/resources/ec2_windows_complete_test_matrix.json))" + echo "::set-output name=ecs_fargate_matrix::$(echo $(cat integration/generator/resources/ecs_fargate_complete_test_matrix.json))" + + - name: Echo test plan matrix + run: | + echo ${{ steps.set-matrix.outputs.ec2_linux_matrix }} + echo ${{ steps.set-matrix.outputs.ec2_performance_matrix}} + echo ${{ steps.set-matrix.outputs.ec2_windows_matrix }} + echo ${{ steps.set-matrix.outputs.ecs_fargate_matrix }} + - name: Echo performance matrix + run: | + echo ${{ steps.set-matrix.outputs.ec2_performance_matrix}} + + StartLocalStack: + name: 'StartLocalStack' + runs-on: ubuntu-latest + defaults: + run: + working-directory: integration/terraform/ec2/localstack + outputs: + local_stack_host_name: ${{ steps.localstack.outputs.local_stack_host_name }} + steps: + - uses: actions/checkout@v2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Verify Terraform version + run: terraform --version + + - name: Terraform init + run: terraform init + + - name: Terraform apply + id: localstack + run: > + echo run terraform and execute test code && + terraform apply --auto-approve + -var="ssh_key=${PRIVATE_KEY}" + -var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" + -var="github_sha=${GITHUB_SHA}" + -var="s3_bucket=${S3_INTEGRATION_BUCKET}" + -var="vpc_security_group_ids=${VPC_SECURITY_GROUPS_IDS}" + -var="key_name=${KEY_NAME}" + -var="iam_instance_profile=${IAM_ROLE}" && + LOCAL_STACK_HOST_NAME=$(terraform output -raw public_dns) && + echo $LOCAL_STACK_HOST_NAME && + echo "::set-output name=local_stack_host_name::$LOCAL_STACK_HOST_NAME" && + aws s3 cp terraform.tfstate s3://${S3_INTEGRATION_BUCKET}/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate + + StopLocalStack: + name: 'StopLocalStack' + runs-on: ubuntu-latest + if: ${{ always() }} + needs: [StartLocalStack, PerformanceTrackingTest] + defaults: + run: + working-directory: integration/terraform/ec2/localstack + steps: + - uses: actions/checkout@v2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Copy state + run: aws s3 cp s3://${S3_INTEGRATION_BUCKET}/integration-test/local-stack-terraform-state/${GITHUB_SHA}/terraform.tfstate . + + - name: Verify Terraform version + run: terraform --version + + - name: Terraform init + run: terraform init + + - name: Terraform destroy + run: terraform destroy --auto-approve + + PerformanceTrackingTest: + name: "PerformanceTrackingTest" + needs: [MakeBinary, StartLocalStack, GenerateTestMatrix] + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + arrays: ${{ fromJson(needs.GenerateTestMatrix.outputs.ec2_performance_matrix) }} + steps: + - uses: actions/checkout@v2 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Cache if success + id: performance-tracking + uses: actions/cache@v2 + with: + path: go.mod + key: performance-tracking-test-${{ github.sha }} + + - name: Echo Test Info + run: echo run performance-tracking + - name: Verify Terraform version + run: terraform --version + - name: Get SHA + id: sha + run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" + - name: Get git date + id: sha_date + run: echo "::set-output name=sha_date::$(git show -s --format=%ct ${{ steps.sha.outputs.sha_short }} )" + - name: Check env + run: echo "SHA ${{ steps.sha.outputs.sha_short }} | Date ${{ steps.sha_date.outputs.sha_date }} " + # + - name: Terraform apply + if: steps.ec2-linux-integration-test.outputs.cache-hit != 'true' + uses: nick-invision/retry@v2 + with: + max_attempts: 1 + timeout_minutes: 30 + retry_wait_seconds: 5 + command: | + cd integration/terraform/ec2/linux + terraform init + if terraform apply --auto-approve \ + -var="ssh_key=${PRIVATE_KEY}" -var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \ + -var="github_sha=${GITHUB_SHA}" -var="install_agent=${{ matrix.arrays.installAgentCommand }}" \ + -var="user=${{ matrix.arrays.username }}" \ + -var="ami=${{ matrix.arrays.ami }}" \ + -var="ca_cert_path=${{ matrix.arrays.caCertPath }}" \ + -var="arc=${{ matrix.arrays.arc }}" \ + -var="binary_name=${{ matrix.arrays.binaryName }}" \ + -var="local_stack_host_name=${{ needs.StartLocalStack.outputs.local_stack_host_name }}" \ + -var="s3_bucket=${S3_INTEGRATION_BUCKET}" \ + -var="vpc_security_group_ids=${VPC_SECURITY_GROUPS_IDS}" \ + -var="key_name=${KEY_NAME}" \ + -var="sha=${GITHUB_SHA}" \ + -var="sha_date=${{ steps.sha_date.outputs.sha_date }}" \ + -var="test_name=cw-integ-test-${{ matrix.arrays.os }}" \ + -var="iam_instance_profile=${IAM_ROLE}" \ + -var="performance_number_of_logs=${{ matrix.arrays.performance_number_of_logs}}"\ + -var="test_dir=${{ matrix.arrays.test_dir }}" ; then terraform destroy -auto-approve + else + terraform destroy -auto-approve && exit 1 + fi + + #This is here just in case workflow cancel + - name: Terraform destroy + if: ${{ cancelled() && steps.ec2-linux-integration-test.outputs.cache-hit != 'true' }} + uses: nick-invision/retry@v2 + with: + max_attempts: 1 + timeout_minutes: 8 + retry_wait_seconds: 5 + command: cd integration/terraform/ec2/linux && terraform destroy --auto-approve diff --git a/.github/workflows/integrationTest.yml b/.github/workflows/integrationTest.yml index ef0d24ee5a..61d2d54a9b 100644 --- a/.github/workflows/integrationTest.yml +++ b/.github/workflows/integrationTest.yml @@ -400,6 +400,8 @@ jobs: matrix: arrays: ${{ fromJson(needs.GenerateTestMatrix.outputs.ec2_linux_matrix) }} steps: + - name: TEMP TEST LOOKUP + run: echo "${{ matrix.arrays.test_dir}}" - uses: actions/checkout@v2 - name: Configure AWS Credentials @@ -687,3 +689,4 @@ jobs: timeout_minutes: 8 retry_wait_seconds: 5 command: cd integration/terraform/ec2/linux && terraform destroy --auto-approve + diff --git a/.github/workflows/releaseTest.yml b/.github/workflows/releaseTest.yml new file mode 100644 index 0000000000..4938c6b37d --- /dev/null +++ b/.github/workflows/releaseTest.yml @@ -0,0 +1,52 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: MIT + +name: Fast Performance Test +env: + PRIVATE_KEY: ${{ secrets.AWS_PRIVATE_KEY }} + TERRAFORM_AWS_ACCESS_KEY_ID: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + TERRAFORM_AWS_SECRET_ACCESS_KEY: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + S3_INTEGRATION_BUCKET: ${{ secrets.S3_INTEGRATION_BUCKET }} + KEY_NAME: ${{ secrets.KEY_NAME }} + VPC_SECURITY_GROUPS_IDS: ${{ secrets.VPC_SECURITY_GROUPS_IDS }} + IAM_ROLE: ${{ secrets.IAM_ROLE }} + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} + PASSPHRASE: ${{ secrets.PASSPHRASE }} + GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }} + GPG_TTY: $(tty) + ECR_INTEGRATION_TEST_REPO: "cwagent-integration-test" + +on: + release: + types: [created] + + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref_name }} + cancel-in-progress: true + +jobs: + UpdatePerformanceMetrics: + name: "UpdatePerformanceMetrics" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ~1.18.3 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.TERRAFORM_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.TERRAFORM_AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + + - name: Run Golang Update Function + run: | + cd integration/test/performancetest + export IS_RELEASE=true + export SHA=$GITHUB_SHA + go test -run TestUpdateCommit -p 1 -v --tags=integration \ No newline at end of file diff --git a/go.sum b/go.sum index a83633fd1c..1fd61ec142 100644 --- a/go.sum +++ b/go.sum @@ -228,6 +228,8 @@ github.com/aws/aws-sdk-go-v2 v1.13.0/go.mod h1:L6+ZpqHaLbAaxsqV0L4cvxZY7QupWJB4f github.com/aws/aws-sdk-go-v2 v1.16.2/go.mod h1:ytwTPBG6fXTZLxxeeCCWj2/EMYp/xDUgX+OET6TLNNU= github.com/aws/aws-sdk-go-v2 v1.16.5 h1:Ah9h1TZD9E2S1LzHpViBO3Jz9FPL5+rmflmb8hXirtI= github.com/aws/aws-sdk-go-v2 v1.16.5/go.mod h1:Wh7MEsmEApyL5hrWzpDkba4gwAPc5/piwLVLFnCxp48= +github.com/aws/aws-sdk-go-v2 v1.16.7 h1:zfBwXus3u14OszRxGcqCDS4MfMCv10e8SMJ2r8Xm0Ns= +github.com/aws/aws-sdk-go-v2 v1.16.7/go.mod h1:6CpKuLXg2w7If3ABZCl/qZ6rEgwtjZTn4eAf4RcEyuw= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1 h1:SdK4Ppk5IzLs64ZMvr6MrSficMtjY2oS0WOORXTlxwU= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.1/go.mod h1:n8Bs1ElDD2wJ9kCRTczA83gYbBmjSwZp3umc6zF4EeM= github.com/aws/aws-sdk-go-v2/config v1.8.3/go.mod h1:4AEiLtAb8kLs7vgw2ZV3p2VZ1+hBavOc84hqxVNpCyw= @@ -238,6 +240,10 @@ github.com/aws/aws-sdk-go-v2/credentials v1.11.2 h1:RQQ5fzclAKJyY5TvF+fkjJEwzK4h github.com/aws/aws-sdk-go-v2/credentials v1.11.2/go.mod h1:j8YsY9TXTm31k4eFhspiQicfXPLZ0gYXA50i4gxPE8g= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.9.4 h1:EoyeSOfbSuKh+bQIDoZaVJjON6PF+dsSn5w1RhIpMD0= github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.9.4/go.mod h1:bfCL7OwZS6owS06pahfGxhcgpLWj2W1sQASoYRuenag= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.9.6 h1:vlEfSyZ2pZjOZe7zsPIAFem17w2HeeFULk7TPVWoDR4= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.9.6/go.mod h1:+/KXTIzLmrjdlQVgiE14/jhy9GyDZnmMGQoykod99Lw= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.4.12 h1:sH0SffGPiNpvYCCfEF0dN0K9OC72KXBjW4HmiFvMVf0= +github.com/aws/aws-sdk-go-v2/feature/dynamodb/expression v1.4.12/go.mod h1:0vvQ0FQRjyNB8EIkRdwT9tduJbkUdh00SnmuKnZRYLA= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.6.0/go.mod h1:gqlclDEZp4aqJOancXK6TN24aKhT0W0Ae9MHk3wzTMM= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.3 h1:LWPg5zjHV9oz/myQr4wMs0gi4CjnDN/ILmyZUFYXZsU= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.3/go.mod h1:uk1vhHHERfSVCUnqSqz8O48LBYDSC+k6brng09jcMOk= @@ -246,10 +252,14 @@ github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.4/go.mod h1:XHgQ7Hz2WY2 github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.9/go.mod h1:AnVH5pvai0pAF4lXRq0bmhbes1u9R8wTE+g+183bZNM= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.12 h1:Zt7DDk5V7SyQULUUwIKzsROtVzp/kVvcz15uQx/Tkow= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.12/go.mod h1:Afj/U8svX6sJ77Q+FPWMzabJ9QjbwP32YlopgKALUpg= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.14 h1:2C0pYHcUBmdzPj+EKNC4qj97oK6yjrUhc1KoSodglvk= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.14/go.mod h1:kdjrMwHwrC3+FsKhNcCMJ7tUVj/8uSD5CZXeQ4wV6fM= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.2.0/go.mod h1:BsCSJHx5DnDXIrOcqB8KN1/B+hXLG/bi4Y6Vjcx/x9E= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.3/go.mod h1:ssOhaLpRlh88H3UmEcsBoVKq309quMvm3Ds8e9d4eJM= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.6 h1:eeXdGVtXEe+2Jc49+/vAzna3FAQnUD4AagAw8tzbmfc= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.6/go.mod h1:FwpAKI+FBPIELJIdmQzlLtRe8LQSOreMcM2wBsPMvvc= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.8 h1:2J+jdlBJWEmTyAwC82Ym68xCykIvnSnIN18b8xHGlcc= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.8/go.mod h1:ZIV8GYoC6WLBW5KGs+o4rsc65/ozd+eQ0L31XF5VDwk= github.com/aws/aws-sdk-go-v2/internal/ini v1.2.4/go.mod h1:ZcBrrI3zBKlhGFNYWvju0I3TR93I7YIgAfy82Fh4lcQ= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.10 h1:by9P+oy3P/CwggN4ClnW2D4oL91QV7pBzBICi1chZvQ= github.com/aws/aws-sdk-go-v2/internal/ini v1.3.10/go.mod h1:8DcYQcz0+ZJaSxANlHIsbbi6S+zMwjwdDqwW3r9AzaE= @@ -261,19 +271,23 @@ github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.18.1 h1:8PHGmLw1QbTdXfgEpXclO github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.18.1/go.mod h1:Z+8JhhltQDM1vIHvEtQLr1wVVAqQVLpvCDMVqYBrwr8= github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.15.4 h1:mBqjBKtZzvAc9j7gU+FEHbhTKSr02iqMOdQIL/7GZ78= github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs v1.15.4/go.mod h1:R49Py2lGoKH7bCpwhjN9l7MfR/PU6zHXn1tCRR8cwOs= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.7 h1:Ls6kDGWNr3wxE8JypXgTTonHpQ1eRVCGNqaFHY2UASw= -github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.7/go.mod h1:+v2jeT4/39fCXUQ0ZfHQHMMiJljnmiuj16F03uAd9DY= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.9 h1:QTPDno4J5TyfpPi3dqCZpD+y7wbHtHhUQwnNGUHUGvg= +github.com/aws/aws-sdk-go-v2/service/dynamodb v1.15.9/go.mod h1:Req/32OLRbXpPX5TxHkwf2Ln9qclJCV6n1S7v0v+FWo= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.13.7 h1:o2HKntJx3vr3y11NK58RA6tYKZKQo5PWWt/bs0rWR0U= github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.13.7/go.mod h1:FAVtDKEl/8WxRDQ33e2fz16RO1t4zeEwWIU5kR29xXs= +github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.13.9 h1:5wt4xEuHFV6ymSb19N0+T9iPYs9TqzHW2Sz4p3bKAlA= +github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.13.9/go.mod h1:Meb0gqL2SgBbh3xHtcak5GPJDZ1QGwRcGPEo7w1G2vg= github.com/aws/aws-sdk-go-v2/service/ec2 v1.29.0 h1:7jk4NfzDnnSbaR9E4mOBWRZXQThq5rsqjlDC+uu9dsI= github.com/aws/aws-sdk-go-v2/service/ec2 v1.29.0/go.mod h1:HoTu0hnXGafTpKIZQ60jw0ybhhCH1QYf20oL7GEJFdg= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.1/go.mod h1:GeUru+8VzrTXV/83XyMJ80KpH8xO89VPoUileyNQ+tc= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.2 h1:T/ywkX1ed+TsZVQccu/8rRJGxKZF/t0Ivgrb4MHTSeo= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.2/go.mod h1:RnloUnyZ4KN9JStGY1LuQ7Wzqh7V0f8FinmRdHYtuaA= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.3 h1:4n4KCtv5SUoT5Er5XV41huuzrCqepxlW3SDI9qHQebc= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.3/go.mod h1:gkb2qADY+OHaGLKNTYxMaQNacfeyQpZ4csDTQMeFmcw= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.3 h1:I0dcwWitE752hVSMrsLCxqNQ+UdEp3nACx2bYNMQq+k= github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.3/go.mod h1:Seb8KNmD6kVTjwRjVEgOT5hPin6sq+v4C2ycJQDwuH8= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.6 h1:JGrc3+kkyr848/wpG2+kWuzHK3H4Fyxj2jnXj8ijQ/Y= -github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.6/go.mod h1:zwvTysbXES8GDwFcwCPB8NkC+bCdio1abH+E+BRe/xg= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.8 h1:x4I8/XPnHOV+1BzZfaqRb8QfrY6AK7bKmEbHVwyctXo= +github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.8/go.mod h1:xfchFk5f70DzZZaH/QYaqMLF+PDH/fg7gGbkIeeaMJM= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.3.2/go.mod h1:72HRZDLMtmVQiLG2tLfQcaWLCssELvGl+Zf2WVxMmR8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.7.0/go.mod h1:K/qPe6AP2TGYv4l6n7c88zh9jWBDf6nHhvg1fx/EWfU= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.3 h1:Gh1Gpyh01Yvn7ilO/b/hr01WgNpaszfbKMUgqM186xQ= @@ -300,6 +314,8 @@ github.com/aws/smithy-go v1.10.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiA github.com/aws/smithy-go v1.11.2/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM= github.com/aws/smithy-go v1.11.3 h1:DQixirEFM9IaKxX1olZ3ke3nvxRS2xMDteKIDWxozW8= github.com/aws/smithy-go v1.11.3/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= +github.com/aws/smithy-go v1.12.0 h1:gXpeZel/jPoWQ7OEmLIgCUnhkFftqNfwWUwAHSlp1v0= +github.com/aws/smithy-go v1.12.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA= github.com/aws/telegraf v0.10.2-0.20220502160831-c20ebe67c5ef h1:O53nKbZm2XpdudUywNdqbohwUxje9k4vE0xRXWeIVbE= github.com/aws/telegraf v0.10.2-0.20220502160831-c20ebe67c5ef/go.mod h1:6maU8S0L0iMSa0ZvH5b2W7dBX1xjK0D5ONAqe7WTqXc= github.com/aws/telegraf/patches/gopsutil/v3 v3.0.0-20220502160831-c20ebe67c5ef h1:iiO0qNErnQgaU6mJY+PRlwnoHp+s9VTk2Ax1A8KRoG4= diff --git a/integration/generator/resources/ec2_performance_test_matrix.json b/integration/generator/resources/ec2_performance_test_matrix.json new file mode 100644 index 0000000000..357095c196 --- /dev/null +++ b/integration/generator/resources/ec2_performance_test_matrix.json @@ -0,0 +1,32 @@ +[ + { + "os": "al2", + "username": "ec2-user", + "installAgentCommand": "rpm -U ./amazon-cloudwatch-agent.rpm", + "ami": "cloudwatch-agent-integration-test-al2*", + "caCertPath": "/etc/ssl/certs/ca-bundle.crt", + "arc": "amd64", + "binaryName": "amazon-cloudwatch-agent.rpm", + "performance_number_of_logs": "10" + }, + { + "os": "al2", + "username": "ec2-user", + "installAgentCommand": "rpm -U ./amazon-cloudwatch-agent.rpm", + "ami": "cloudwatch-agent-integration-test-al2*", + "caCertPath": "/etc/ssl/certs/ca-bundle.crt", + "arc": "amd64", + "binaryName": "amazon-cloudwatch-agent.rpm", + "performance_number_of_logs": "100" + }, + { + "os": "al2", + "username": "ec2-user", + "installAgentCommand": "rpm -U ./amazon-cloudwatch-agent.rpm", + "ami": "cloudwatch-agent-integration-test-al2*", + "caCertPath": "/etc/ssl/certs/ca-bundle.crt", + "arc": "amd64", + "binaryName": "amazon-cloudwatch-agent.rpm", + "performance_number_of_logs": "1000" + } +] \ No newline at end of file diff --git a/integration/generator/test_case_generator.go b/integration/generator/test_case_generator.go index 456c0e5f08..146bc09193 100644 --- a/integration/generator/test_case_generator.go +++ b/integration/generator/test_case_generator.go @@ -26,6 +26,9 @@ var osToTestDirMap = map[string][]string{ "./integration/test/metrics_number_dimension", }, // @TODO add real tests + "ec2_performance":{ + "./integration/test/performancetest", + }, "ec2_windows": {""}, "ec2_mac": {}, "ecs_fargate": { diff --git a/integration/terraform/ec2/linux/main.tf b/integration/terraform/ec2/linux/main.tf index b32eb7b9f1..3eaa48a554 100644 --- a/integration/terraform/ec2/linux/main.tf +++ b/integration/terraform/ec2/linux/main.tf @@ -46,6 +46,7 @@ resource "null_resource" "integration_test" { # Prepare Integration Test provisioner "remote-exec" { inline = [ + "echo sha ${var.sha}", "cloud-init status --wait", "echo clone and install agent", "git clone ${var.github_repo}", @@ -80,10 +81,11 @@ resource "null_resource" "integration_test" { "export PATH=$PATH:/snap/bin:/usr/local/go/bin", "echo run integration test", "cd ~/amazon-cloudwatch-agent", - "go test ./integration/test/sanity -p 1 -v --tags=integration", - "export SHA=${var.github_sha}", - "export SHA_DATE=${var.github_sha_date}", - "go test ${var.test_dir} -p 1 -v --tags=integration" + "echo run sanity test && go test ./integration/test/sanity -p 1 -v --tags=integration", + "export SHA=${var.sha}", + "export SHA_DATE=${var.sha_date}", + "export PERFORMANCE_NUMBER_OF_LOGS=${var.performance_number_of_logs}", + "go test ${var.test_dir} -p 1 -timeout 30m -v --tags=integration " ] connection { type = "ssh" diff --git a/integration/terraform/ec2/linux/variables.tf b/integration/terraform/ec2/linux/variables.tf index aff2297d60..68c14423de 100644 --- a/integration/terraform/ec2/linux/variables.tf +++ b/integration/terraform/ec2/linux/variables.tf @@ -82,4 +82,16 @@ variable "github_repo" { variable "github_sha_date"{ type = string default = "" +} +variable "sha" { + type = string + default = "" +} +variable "sha_date"{ + type = string + default = "" +} +variable "performance_number_of_logs"{ + type = string + default = "" } \ No newline at end of file diff --git a/integration/test/performancetest/demo.txt b/integration/test/performancetest/demo.txt new file mode 100644 index 0000000000..3ee6fbe414 --- /dev/null +++ b/integration/test/performancetest/demo.txt @@ -0,0 +1 @@ +commitCount=5 \ No newline at end of file diff --git a/integration/test/performancetest/performance_test.go b/integration/test/performancetest/performance_test.go index 1968b16083..811441cadd 100644 --- a/integration/test/performancetest/performance_test.go +++ b/integration/test/performancetest/performance_test.go @@ -8,6 +8,8 @@ import( "time" "log" "context" + "fmt" + "os" "github.com/aws/amazon-cloudwatch-agent/integration/test" ) @@ -16,7 +18,6 @@ const ( configOutputPath = "/opt/aws/amazon-cloudwatch-agent/bin/config.json" agentRuntimeMinutes = 5 //20min desired but 5mins for testing purposes DynamoDBDataBase = "CWAPerformanceMetrics" - ) func TestPerformance(t *testing.T) { @@ -27,7 +28,7 @@ func TestPerformance(t *testing.T) { test.CopyFile(configPath, configOutputPath) test.StartAgent(configOutputPath, true) - + fmt.Println("N_Logs",os.Getenv("PERFORMANCE_NUMBER_OF_LOGS")) agentRunDuration := agentRuntimeMinutes * time.Minute //let agent run before collecting performance metrics on it time.Sleep(agentRunDuration) @@ -54,6 +55,20 @@ func TestPerformance(t *testing.T) { } _, err = dynamoDB.SendItem(data) if err !=nil{ - t.Fatalf("Error: couldnt upload metric data to table") + t.Fatalf("Error: couldnt upload metric data to table %s",err) } -} \ No newline at end of file +} +func TestUpdateCommit(t*testing.T){ + if(os.Getenv("IS_RELEASE") ==""){ + t.Skip("") + } + fmt.Println("Updating Release Commit",os.Getenv(SHA_ENV)) + dynamoDB := InitializeTransmitterAPI("CWAPerformanceMetrics") //add cwa version here + testHash := os.Getenv(SHA_ENV) + if dynamoDB == nil{ + t.Fatalf("Error: generating dynamo table") + return + } + + dynamoDB.UpdateReleaseTag(testHash) +} diff --git a/integration/test/performancetest/transmitter.go b/integration/test/performancetest/transmitter.go index 863aba9d6a..e9c67aafc7 100644 --- a/integration/test/performancetest/transmitter.go +++ b/integration/test/performancetest/transmitter.go @@ -5,13 +5,14 @@ import ( "encoding/json" "errors" "fmt" + "os" + "time" + "strconv" + "log" + "strings" "log" "math" - "os" "sort" - "strconv" - "time" - "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue" @@ -26,6 +27,8 @@ const ( COMMIT_DATE= "CommitDate" SHA_ENV = "SHA" SHA_DATE_ENV = "SHA_DATE" + NUMBER_OF_LOGS_MONITORED = "NumberOfLogsMonitored" + TPS = "TPS" ) type TransmitterAPI struct { dynamoDbClient *dynamodb.Client @@ -101,6 +104,10 @@ func (transmitter *TransmitterAPI) CreateTable() error { AttributeName: aws.String("CommitDate"), AttributeType: types.ScalarAttributeTypeN, }, + { + AttributeName: aws.String("Hash"), + AttributeType: types.ScalarAttributeTypeS, + }, }, KeySchema: []types.KeySchemaElement{ { @@ -112,7 +119,28 @@ func (transmitter *TransmitterAPI) CreateTable() error { KeyType: types.KeyTypeRange, }, }, - + GlobalSecondaryIndexes: []types.GlobalSecondaryIndex{ + { + IndexName: aws.String("Hash-index"), + KeySchema: []types.KeySchemaElement{ + { + AttributeName: aws.String("Hash"), + KeyType: types.KeyTypeHash, + }, + { + AttributeName: aws.String("CommitDate"), + KeyType: types.KeyTypeRange, + }, + }, + Projection: &types.Projection{ + ProjectionType : "ALL", + }, + ProvisionedThroughput: &types.ProvisionedThroughput{ + ReadCapacityUnits: aws.Int64(10), + WriteCapacityUnits: aws.Int64(10), + }, + }, + }, ProvisionedThroughput: &types.ProvisionedThroughput{ ReadCapacityUnits: aws.Int64(10), WriteCapacityUnits: aws.Int64(10), @@ -191,14 +219,55 @@ Param: data []byte is the data collected by data collector func (transmitter *TransmitterAPI) SendItem(data []byte) (string, error) { // return nil packet, err := transmitter.Parser(data) + var sentItem string if err != nil { return "", err } - // fmt.Printf("%+v",packet) - sentItem, err := transmitter.AddItem(packet) + // check if hash exists + itemList,err := transmitter.Query(packet[HASH].(string)) + + if err!=nil { + return "",err + } + fmt.Println(itemList,packet[HASH].(string)) + if len(itemList)==0{ // if doesnt exit addItem + sentItem, err = transmitter.AddItem(packet) + return sentItem, err + } + + // item already exist so update + //temp solution VVVVVV + testSettings := fmt.Sprintf("%s-%s",os.Getenv("PERFORMANCE_NUMBER_OF_LOGS"),"10") + fmt.Println("The test is",testSettings) + item := itemList[0]["Results"].(map[string]interface{}) + _,isPresent := item[testSettings] // check if we already had this test + if isPresent{ // no diff + return "",errors.New("Nothing to update") + } + testSettingValue, err := attributevalue.MarshalMap(packet["Results"].(map[string]map[string]Metric)[testSettings]) + fmt.Println("test value",testSettingValue) + if err !=nil{ + fmt.Println(err) + } + tempResults := make(map[string]interface{}) + for attribute,value := range item{ + _, isPresent := packet["Results"].(map[string]map[string]Metric)[attribute] + if(isPresent){continue} + tempResults[attribute] = value + + } + + tempResults[testSettings] = testSettingValue + results, _ := attributevalue.MarshalMap(tempResults) + newAttributes := map[string]types.AttributeValue{ + "Results" : &types.AttributeValueMemberM{ + Value: results, + }, + } + + transmitter.UpdateItem(packet[HASH].(string),newAttributes) return sentItem, err } - func (transmitter *TransmitterAPI) Parser(data []byte) (map[string]interface{}, error) { dataHolder := collectorData{} err := json.Unmarshal(data, &dataHolder) @@ -207,17 +276,96 @@ func (transmitter *TransmitterAPI) Parser(data []byte) (map[string]interface{}, } packet := make(map[string]interface{}) packet[PARTITION_KEY] = time.Now().Year() - packet[HASH] = os.Getenv(SHA_ENV) //fmt.Sprintf("%d", time.Now().UnixNano()) + packet[HASH] = os.Getenv(SHA_ENV) //fmt.Sprintf("%d", time.Now().UnixNano()) packet[COMMIT_DATE],_ = strconv.Atoi(os.Getenv(SHA_DATE_ENV)) - + packet["isRelease"] = false + testSettings := fmt.Sprintf("%s-%s",os.Getenv("PERFORMANCE_NUMBER_OF_LOGS"),"10") + testMetricResults := make(map[string]Metric) for _, rawMetricData := range dataHolder { metric := CalcStats(rawMetricData.Values) - - packet[rawMetricData.Label] = metric + testMetricResults[rawMetricData.Label] = metric } + packet["Results"] = map[string]map[string]Metric{ testSettings: testMetricResults} return packet, nil } +func (transmitter * TransmitterAPI) UpdateItem(hash string,targetAttributes map[string]types.AttributeValue) error{ + var err error + fmt.Println("Updating:",hash) + item,err := transmitter.Query(hash) // O(1) bcs of global sec. idx. + if len(item) ==0{ + return errors.New("ERROR: Hash is not found in dynamo") + } + commitDate := fmt.Sprintf("%d",int(item[0]["CommitDate"].(float64))) + year := fmt.Sprintf("%d",int(item[0]["Year"].(float64))) + expressionAttributeValues := make(map[string]types.AttributeValue) + expression := "" + n_expression := len(targetAttributes) + i :=0 + for attribute, value := range targetAttributes{ + expressionName := ":" +strings.ToLower(attribute) + expression = fmt.Sprintf("set %s = %s",attribute,expressionName) + expressionAttributeValues[expressionName] = value + if(n_expression -1 >i){ + expression += "and" + } + i++ + } + fmt.Println(expression) + _, err = transmitter.dynamoDbClient.UpdateItem(context.TODO(), &dynamodb.UpdateItemInput{ + TableName: aws.String(transmitter.DataBaseName), + Key: map[string]types.AttributeValue{ + "Year": &types.AttributeValueMemberN{Value: year}, + "CommitDate": &types.AttributeValueMemberN{Value: commitDate }, + }, + UpdateExpression: aws.String(expression), + ExpressionAttributeValues: expressionAttributeValues, + }) + + if err != nil { + panic(err) + } + return err +} +/* +UpdateReleaseTag() +Desc: This function takes in a commit hash and updates the release value to true +Param: commit hash in terms of string +*/ +func (transmitter * TransmitterAPI) UpdateReleaseTag(hash string) error{ + attributes := map[string]types.AttributeValue{ + "isRelease":&types.AttributeValueMemberBOOL{Value: true}, + } + err := transmitter.UpdateItem(hash,attributes) + return err +} + + +func (transmitter* TransmitterAPI) Query(hash string) ([]map[string]interface{}, error) { + var err error + var packets []map[string]interface{} + out, err := transmitter.dynamoDbClient.Query(context.TODO(), &dynamodb.QueryInput{ + TableName: aws.String(transmitter.DataBaseName), + IndexName: aws.String("Hash-index"), + KeyConditionExpression: aws.String("#hash = :hash"), + ExpressionAttributeValues: map[string]types.AttributeValue{ + ":hash": &types.AttributeValueMemberS{Value: hash}, + }, + ExpressionAttributeNames: map[string]string{ + "#hash": "Hash", + }, + ScanIndexForward: aws.Bool(true), // true or false to sort by "date" Sort/Range key ascending or descending + }) + if err != nil { + panic(err) + } + // fmt.Println(out.Items) + attributevalue.UnmarshalListOfMaps(out.Items,&packets) + return packets, err +} + + + //CalcStats takes in an array of data and returns the average, min, max, p99, and stdev of the data in a Metric struct func CalcStats(data []float64) Metric {