performance_test.yaml 4.3 KB

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