Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go benchmark as part of the buildkite pipeline #3141

Merged
merged 33 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
73300dd
Update pipeline.yml
jlind23 Dec 5, 2023
f7539b6
add initial benchmark for PR
Dec 5, 2023
9e725b7
update pipeline
Dec 5, 2023
8d17079
update pipeline
Dec 5, 2023
0bedb84
split steps
Dec 5, 2023
82bbd23
Update .buildkite/pipeline.yml
jlind23 Dec 5, 2023
155a4a5
Add steps for comparing and baseline
alexsapran Dec 5, 2023
5cccf63
Make each annotate the gobench output
alexsapran Dec 5, 2023
0bc1a95
Fix artifact paths
alexsapran Dec 5, 2023
885a989
Compare dont need to checkout base
alexsapran Dec 5, 2023
5ff8b5d
Attempt to increase the cpu and mem for go bench
alexsapran Dec 5, 2023
a029392
Escape bash
alexsapran Dec 5, 2023
3501064
Remove the GH action for benchmark
alexsapran Dec 5, 2023
fd19ba6
Increase memory
alexsapran Dec 5, 2023
c2384b9
Formatting the annotations
alexsapran Dec 5, 2023
9caeb6f
Change the type of the VMs for benchmarks
alexsapran Dec 5, 2023
05165ad
Ignore direnv files
alexsapran Dec 6, 2023
b684303
Parse go benchmark results with gobenchdata
alexsapran Dec 6, 2023
4aeec7a
Fix the artifact path
alexsapran Dec 6, 2023
3a1d18e
fix the filepaths
alexsapran Dec 6, 2023
aaa85ed
Fix the path again
alexsapran Dec 6, 2023
41ec3c8
Make annotation reflect status
alexsapran Dec 6, 2023
8f53958
Fix failed json path
alexsapran Dec 6, 2023
12c0550
Suppress gobenchdata error exiting
alexsapran Dec 6, 2023
50874ef
Enable mem reporting for gobench by default
alexsapran Dec 6, 2023
b0e203a
Add links to artifact download in bk annotation
alexsapran Dec 6, 2023
9846de7
change the gobenchdata check name
alexsapran Dec 6, 2023
45b5dd5
Improve the benchmark script for the step
alexsapran Dec 6, 2023
2aa34e9
Allow gobenchdata failure to not block
alexsapran Dec 6, 2023
69a5cf7
Reset Benchmark timer for Bulk
alexsapran Dec 6, 2023
2e8253d
Revert "Reset Benchmark timer for Bulk"
alexsapran Dec 6, 2023
c2a1e18
Merge branch 'main' into jlind23-go-benchmark
jlind23 Dec 6, 2023
080cd1c
Merge remote-tracking branch 'upstream/jlind23-go-benchmark' into jli…
alexsapran Dec 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,42 @@ steps:
image: "${GO_AGENT_IMAGE}"
cpu: "8"
memory: "4G"

- group: "Performance test"
key: "performance-test"
steps:
- label: "Run go benchmark for PR branch"
key: "go-benchmark-pr"
command: ".buildkite/scripts/run_benchmark.sh pr"
artifact_paths:
- build/next.out
agents:
provider: "gcp"
machineType: "c2-standard-8"

- label: "Run go benchmark for ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}"
key: "go-benchmark-base"
command: ".buildkite/scripts/run_benchmark.sh base"
artifact_paths:
- build/base.out
agents:
jlind23 marked this conversation as resolved.
Show resolved Hide resolved
provider: "gcp"
machineType: "c2-standard-8"

- label: "Compare results"
key: "go-benchmark-compare"
command: ".buildkite/scripts/run_benchmark.sh compare"
artifact_paths:
- build/failed_summary.md
- build/failed_report.json
- build/full_report.json
depends_on:
- go-benchmark-pr
- go-benchmark-base
agents:
provider: "gcp"

depends_on: "check"

- group: "Run tests"
key: "tests"
Expand Down
95 changes: 95 additions & 0 deletions .buildkite/scripts/run_benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

set -euo pipefail

source .buildkite/scripts/common.sh

add_bin_path

with_go

export TYPE=${1}
#export BRANCH="${BUILDKITE_BRANCH}"
export BENCHMARK_ARGS="-count=8 -benchmem"

if [[ ${TYPE} == "pr" ]]; then
echo "Starting the go benchmark for the pull request"
BENCH_BASE=next.out make benchmark
BENCH=$(cat build/next.out)
buildkite-agent annotate --style 'info' --context "gobench_pr" --append << _EOF_
#### Benchmark for pull request
<details><summary>go bench output</summary>

\`\`\`bash
${BENCH}
\`\`\`

</details>

Download <a href="artifact://build/next.out">next.out</a>
_EOF_
fi

if [[ ${TYPE} == "base" ]]; then
echo "Starting the go benchmark for the pull request"
git checkout ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}
BENCH_BASE=base.out make benchmark
BENCH=$(cat build/base.out)
buildkite-agent annotate --style 'info' --context "gobench_base" --append << _EOF_
#### Benchmark for the ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}
<details><summary>go bench output for ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}</summary>

\`\`\`bash
${BENCH}
\`\`\`

</details>

Download <a href="artifact://build/base.out">${BUILDKITE_PULL_REQUEST_BASE_BRANCH}.out</a>
_EOF_
fi

if [[ ${TYPE} == "compare" ]]; then
echo "Comparing go benchmarks"
go install go.bobheadxi.dev/gobenchdata@latest
buildkite-agent artifact download "build/base.out" .
buildkite-agent artifact download "build/next.out" .

cat build/base.out| gobenchdata --json build/base.json
cat build/next.out| gobenchdata --json build/next.json
set +e # suppress error handling of gobenchdata
gobenchdata checks eval build/base.json build/next.json --json build/full_report.json
status=$(jq -r '.Status' build/full_report.json)
if [[ $status == "fail" ]]; then
cat build/full_report.json| \
jq 'del(.Checks.timePerOp.Diffs[]| select(.Status == "pass") )'| \
tee build/failed_report.json
gobenchdata checks report build/failed_report.json | tee build/failed_summary.md
BENCH_COMPARE=$(cat build/failed_summary.md)
buildkite-agent annotate --style 'error' --context "benchstat" --append << _EOF_
#### Benchmark comparison
<details><summary>Comparison table of benchmark results of HEAD compared to ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}</summary>

${BENCH_COMPARE}

</details>

Download <a href="artifact://build/failed_summary.md">failed_summary.md</a> , <a href="artifact://build/full_report.json">full_report.json</a>
_EOF_
#exit 1 # fail the build if the status is fail
else
BENCH_COMPARE=$(gobenchdata checks report build/full_report.json)
buildkite-agent annotate --style 'success' --context "benchstat" --append << _EOF_
#### Benchmark comparison
<details><summary>No significant performance issue detect against ${BUILDKITE_PULL_REQUEST_BASE_BRANCH}</summary>

${BENCH_COMPARE}

</details>

Download <a href="artifact://build/full_report.json">full_report.json</a>
_EOF_
fi
fi


101 changes: 0 additions & 101 deletions .github/workflows/benchmark.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ dev-tools/cloud/terraform/*.tfvars*

.service_token*
.kibana_service_token


# direnv
.envrc*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BUILDER_IMAGE=docker.elastic.co/beats-dev/golang-crossbuild:${GO_VERSION}-main-d
#Benchmark related targets
BENCH_BASE ?= benchmark-$(COMMIT).out
BENCH_NEXT ?=
BENCHMARK_ARGS := -count=8
BENCHMARK_ARGS := -count=8 -benchmem
BENCHMARK_PACKAGE ?= ./...
BENCHMARK_FILTER ?= Bench

Expand Down
9 changes: 9 additions & 0 deletions gobenchdata-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
checks:
- name: timePerOp
description: |-
This check is set to fail when there are benchmark tests that are slower than the defined threshold
package: .
benchmarks: []
diff: (current.NsPerOp - base.NsPerOp) / base.NsPerOp * 100
thresholds:
max: 10
Loading