auto trigger standalone workflow from the branch #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: benchmarks-standalone | |
on: | |
push: | |
branches: | |
- inject-build-pgo-profile | |
workflow_dispatch: | |
inputs: | |
benchmarkAgents: | |
description: 'Set the number of agents to send data to the APM Server' | |
required: false | |
type: string | |
benchmarkRun: | |
description: 'Set the expression that matches the benchmark scenarios to run' | |
required: false | |
type: string | |
env: | |
PNG_REPORT_FILE: out.png | |
BENCHMARK_CPU_OUT: default.pgo | |
BENCHMARK_RESULT: benchmark-result.txt | |
WORKING_DIRECTORY: testing/benchmark-standalone | |
permissions: | |
contents: read | |
jobs: | |
benchmarks: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: ${{ env.WORKING_DIRECTORY }} | |
permissions: | |
contents: write | |
id-token: write | |
pull-requests: write | |
env: | |
SSH_KEY: ./id_rsa_terraform | |
TF_VAR_private_key: ./id_rsa_terraform | |
TF_VAR_public_key: ./id_rsa_terraform.pub | |
TF_VAR_BUILD_ID: ${{ github.run_id }} | |
TF_VAR_ENVIRONMENT: ci | |
TF_VAR_REPO: ${{ github.repository }} | |
GOBENCH_TAGS: branch=${{ github.head_ref || github.ref }},commit=${{ github.sha }},target_branch=${{ github.base_ref }} | |
GOBENCH_PASSWORD: ${{ secrets.GOBENCH_PASSWORD }} | |
GOBENCH_USERNAME: ${{ secrets.GOBENCH_USERNAME }} | |
GOBENCH_HOST: ${{ secrets.GOBENCH_HOST }} | |
# temporarily override to get faster feedback | |
BENCHMARK_WARMUP_TIME: 1m | |
BENCHMARK_COUNT: 2 | |
BENCHMARK_TIME: 1m | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'go.mod' | |
- uses: rlespinasse/github-slug-action@797d68864753cbceedc271349d402da4590e6302 | |
- name: Set up env | |
run: | | |
SLUGGED_BRANCH_NAME=${{ env.GITHUB_HEAD_REF_SLUG || env.GITHUB_REF_SLUG }} | |
CREATED_AT=$(date +%s) | |
echo "TF_VAR_BRANCH=${SLUGGED_BRANCH_NAME}" >> "$GITHUB_ENV" | |
echo "TF_VAR_CREATED_AT=${CREATED_AT}" >> "$GITHUB_ENV" | |
echo "USER=benchci-$SLUGGED_BRANCH_NAME-$CREATED_AT" >> "$GITHUB_ENV" | |
if [ ! -z "${{ inputs.benchmarkAgents }}" ]; then | |
echo "BENCHMARK_AGENTS=${{ inputs.benchmarkAgents }}" >> "$GITHUB_ENV" | |
fi | |
if [ ! -z "${{ inputs.benchmarkRun }}" ]; then | |
echo "BENCHMARK_RUN=${{ inputs.benchmarkRun }}" >> "$GITHUB_ENV" | |
fi | |
- name: Log in to the Elastic Container registry | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0 | |
with: | |
registry: ${{ secrets.ELASTIC_DOCKER_REGISTRY }} | |
username: ${{ secrets.ELASTIC_DOCKER_USERNAME }} | |
password: ${{ secrets.ELASTIC_DOCKER_PASSWORD }} | |
- uses: elastic/oblt-actions/google/auth@v1 | |
- uses: elastic/oblt-actions/aws/auth@v1 | |
with: | |
role-duration-seconds: 18000 # 5 hours | |
- uses: google-github-actions/get-secretmanager-secrets@95a0b09b8348ef3d02c68c6ba5662a037e78d713 # v2.1.4 | |
with: | |
export_to_environment: true | |
secrets: |- | |
EC_API_KEY:elastic-observability/elastic-cloud-observability-team-pro-api-key | |
- uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.3.7 | |
terraform_wrapper: false | |
- name: Build APM Server | |
run: cd ../.. && make build/apm-server-linux-amd64 | |
- name: Build moxy | |
run: make moxy | |
- name: Build apmbench | |
run: make apmbench | |
- name: Spin up benchmark environment | |
id: deploy | |
run: make init apply | |
- name: Run benchmarks autotuned | |
if: ${{ inputs.benchmarkAgents == '' }} | |
run: make run-benchmark-autotuned | |
- name: Run benchmarks self tuned | |
if: ${{ inputs.benchmarkAgents != '' }} | |
run: make run-benchmark | |
# Results are only indexed and uploaded if the run happens on the main branch. | |
- name: Index benchmarks result | |
run: make index-benchmark-results | |
- name: Download PNG | |
run: >- | |
${{ github.workspace }}/.ci/scripts/download-png-from-kibana.sh | |
${{ secrets.KIBANA_BENCH_ENDPOINT }} | |
${{ secrets.KIBANA_BENCH_USERNAME }} | |
${{ secrets.KIBANA_BENCH_PASSWORD }} | |
$PNG_REPORT_FILE | |
- name: Upload PNG | |
uses: actions/upload-artifact@v4 | |
with: | |
name: kibana-png-report | |
path: ${{ env.WORKING_DIRECTORY }}/${{ env.PNG_REPORT_FILE }} | |
if-no-files-found: error | |
- name: Upload PNG to AWS S3 | |
id: s3-upload-png | |
env: | |
AWS_DEFAULT_REGION: us-east-1 | |
run: | | |
DEST_NAME="github-run-id-${{ github.run_id }}.png" | |
aws s3 --debug cp ${{ env.PNG_REPORT_FILE }} s3://elastic-apm-server-benchmark-reports/${DEST_NAME} | |
echo "png_report_url=https://elastic-apm-server-benchmark-reports.s3.amazonaws.com/${DEST_NAME}" >> "$GITHUB_OUTPUT" | |
- name: Upload benchmark result | |
uses: actions/upload-artifact@v4 | |
with: | |
name: benchmark-result | |
path: ${{ env.WORKING_DIRECTORY }}/${{ env.BENCHMARK_RESULT }} | |
if-no-files-found: error | |
# The next section injects CPU profile collected by apmbench into the build. | |
# By copying the profile, uploading it to the artifacts and pushing it | |
# via a PR to update default.pgo. | |
- name: Copy CPU profile | |
run: make cp-cpuprof | |
- name: Upload CPU profile | |
uses: actions/upload-artifact@v4 | |
with: | |
name: cpu-profile | |
path: ${{ env.WORKING_DIRECTORY }}/${{ env.BENCHMARK_CPU_OUT }} | |
if-no-files-found: error | |
- name: Open PGO PR | |
run: | | |
cd "${{ github.workspace }}" | |
mv "$PROFILE_PATH" x-pack/apm-server/default.pgo | |
git config user.email "apm@elastic.co" | |
git config user.name "APM Server" | |
git fetch origin main | |
git checkout main | |
BRANCH="update-pgo-$(date +%s)" | |
git checkout -b "$BRANCH" | |
git add x-pack/apm-server/default.pgo | |
git commit -m "PGO: Update default.pgo from benchmarks $WORKFLOW." | |
git push -u origin "$BRANCH" | |
gh pr create -B main -H "$BRANCH" -t "PGO: Update default.pgo" -b "Update default.pgo CPU profile from the benchmarks [workflow]($WORKFLOW)." -R elastic/apm-server | |
env: | |
PROFILE_PATH: ${{ env.WORKING_DIRECTORY }}/${{ env.BENCHMARK_CPU_OUT }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
WORKFLOW: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }} | |
- name: Tear down benchmark environment | |
if: always() | |
run: make destroy |