performance_test.yaml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. name: Performance Test Suite
  2. on:
  3. push:
  4. branches:
  5. - 'perf/**'
  6. schedule:
  7. - cron: '0 1 * * *'
  8. workflow_dispatch:
  9. inputs:
  10. ref:
  11. required: false
  12. jobs:
  13. prepare:
  14. runs-on: ubuntu-latest
  15. if: github.repository_owner == 'emqx'
  16. container: ghcr.io/emqx/emqx-builder/5.0-34:1.13.4-25.1.2-3-ubuntu20.04
  17. outputs:
  18. BENCH_ID: ${{ steps.prepare.outputs.BENCH_ID }}
  19. PACKAGE_FILE: ${{ steps.package_file.outputs.PACKAGE_FILE }}
  20. steps:
  21. - uses: actions/checkout@v3
  22. with:
  23. fetch-depth: 0
  24. ref: ${{ github.event.inputs.ref }}
  25. - name: Work around https://github.com/actions/checkout/issues/766
  26. run: |
  27. git config --global --add safe.directory "$GITHUB_WORKSPACE"
  28. - id: prepare
  29. run: |
  30. echo "EMQX_NAME=emqx" >> $GITHUB_ENV
  31. echo "CODE_PATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
  32. echo "BENCH_ID=$(date --utc +%F)/emqx-$(./pkg-vsn.sh emqx)" >> $GITHUB_OUTPUT
  33. - name: Build deb package
  34. run: |
  35. make ${EMQX_NAME}-pkg
  36. ./scripts/pkg-tests.sh ${EMQX_NAME}-pkg
  37. - name: Get package file name
  38. id: package_file
  39. run: |
  40. echo "PACKAGE_FILE=$(find _packages/emqx -name 'emqx-*.deb' | head -n 1 | xargs basename)" >> $GITHUB_OUTPUT
  41. - uses: actions/upload-artifact@v3
  42. with:
  43. name: emqx-ubuntu20.04
  44. path: _packages/emqx/${{ steps.package_file.outputs.PACKAGE_FILE }}
  45. tf_emqx_perf_test:
  46. runs-on: ubuntu-latest
  47. needs:
  48. - prepare
  49. env:
  50. TF_VAR_bench_id: ${{ needs.prepare.outputs.BENCH_ID }}
  51. TF_VAR_package_file: ${{ needs.prepare.outputs.PACKAGE_FILE }}
  52. TF_VAR_test_duration: 300
  53. TF_VAR_grafana_api_key: ${{ secrets.TF_EMQX_PERF_TEST_GRAFANA_API_KEY }}
  54. TF_AWS_REGION: eu-north-1
  55. steps:
  56. - name: Configure AWS Credentials
  57. uses: aws-actions/configure-aws-credentials@v2
  58. with:
  59. aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_PERF_TEST }}
  60. aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_PERF_TEST }}
  61. aws-region: eu-north-1
  62. - name: Checkout tf-emqx-performance-test
  63. uses: actions/checkout@v3
  64. with:
  65. repository: emqx/tf-emqx-performance-test
  66. path: tf-emqx-performance-test
  67. - uses: actions/download-artifact@v3
  68. with:
  69. name: emqx-ubuntu20.04
  70. path: tf-emqx-performance-test/
  71. - name: Setup Terraform
  72. uses: hashicorp/setup-terraform@v2
  73. with:
  74. terraform_wrapper: false
  75. - name: terraform init
  76. working-directory: ./tf-emqx-performance-test
  77. run: |
  78. terraform init
  79. - name: terraform apply
  80. working-directory: ./tf-emqx-performance-test
  81. run: |
  82. terraform apply -auto-approve
  83. - name: Wait for test results
  84. timeout-minutes: 30
  85. working-directory: ./tf-emqx-performance-test
  86. id: test-results
  87. run: |
  88. sleep $TF_VAR_test_duration
  89. until aws s3api head-object --bucket tf-emqx-performance-test --key "$TF_VAR_bench_id/DONE" > /dev/null 2>&1
  90. do
  91. printf '.'
  92. sleep 10
  93. done
  94. echo
  95. aws s3 cp "s3://tf-emqx-performance-test/$TF_VAR_bench_id/metrics.json" ./
  96. aws s3 cp "s3://tf-emqx-performance-test/$TF_VAR_bench_id/stats.json" ./
  97. echo MESSAGES_DELIVERED=$(cat metrics.json | jq '[.[]."messages.delivered"] | add') >> $GITHUB_OUTPUT
  98. echo MESSAGES_DROPPED=$(cat metrics.json | jq '[.[]."messages.dropped"] | add') >> $GITHUB_OUTPUT
  99. - name: Send notification to Slack
  100. if: success()
  101. uses: slackapi/slack-github-action@v1.23.0
  102. env:
  103. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  104. with:
  105. payload: |
  106. {"text": "EMQX performance test completed.\nMessages delivered: ${{ steps.test-results.outputs.MESSAGES_DELIVERED }}.\nMessages dropped: ${{ steps.test-results.outputs.MESSAGES_DROPPED }}.\nhttps://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}
  107. - name: terraform destroy
  108. if: always()
  109. working-directory: ./tf-emqx-performance-test
  110. run: |
  111. terraform destroy -auto-approve
  112. - uses: actions/upload-artifact@v3
  113. if: success()
  114. with:
  115. name: test-results
  116. path: "./tf-emqx-performance-test/*.json"
  117. - uses: actions/upload-artifact@v3
  118. if: always()
  119. with:
  120. name: terraform
  121. path: |
  122. ./tf-emqx-performance-test/.terraform
  123. ./tf-emqx-performance-test/*.tfstate