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

Create benchmark.yml and add end-to-end benchmark #1736

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: benchmark
on:
push:
branches:
- main

permissions:
contents: write
deployments: write

jobs:
benchmark:
name: Run Go benchmark example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up go
uses: actions/setup-go@v4
with:
go-version: "1.19"
- name: Set up go env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Run benchmark
run: |
mkdir out || (exit 0)
go test -bench=. -benchtime=1s ./benchmarks/... -tags=benchmarks | tee ./out/benchmark.txt

- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
name: Go Benchmark
tool: 'go'
output-file-path: ./out/benchmark.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '200%'
comment-on-alert: true
fail-on-alert: true
alert-comment-cc-users: '@edithwuly'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually we'll probably want this to be '@buildpacks/platform-maintainers' but this will be helpful to reduce noise while we're iterating on the benchmark suite

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I just leave @edithwuly here temporarily.

41 changes: 37 additions & 4 deletions benchmarks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package benchmarks
import (
"bytes"
"fmt"
"os"
"path/filepath"
"testing"

Expand All @@ -21,13 +22,16 @@ import (
)

var (
baseImg = "some-org/" + h.RandString(10)
trustedImg = baseImg + "-trusted-"
builder = "cnbs/sample-builder:bionic"
mockAppPath = filepath.Join("..", "acceptance", "testdata", "mock_app")
baseImg string
trustedImg string
builder string
mockAppPath string
paketoBuilder string
additionalBuildapck string
)

func BenchmarkBuild(b *testing.B) {
setEnv()
dockerClient, err := dockerCli.NewClientWithOpts(dockerCli.FromEnv, dockerCli.WithVersion("1.38"))
if err != nil {
b.Error(errors.Wrap(err, "creating docker client"))
Expand Down Expand Up @@ -59,6 +63,16 @@ func BenchmarkBuild(b *testing.B) {
}
})

b.Run("with Addtional Buildpack", func(b *testing.B) {
for i := 0; i < b.N; i++ {
// perform the operation we're analyzing
cmd.SetArgs([]string{fmt.Sprintf("%s%d", trustedImg, i), "-p", mockAppPath, "-B", paketoBuilder, "--buildpack", additionalBuildapck})
if err = cmd.Execute(); err != nil {
b.Error(errors.Wrapf(err, "running build #%d", i))
}
}
})

// Cleanup
for i := 0; i < b.N; i++ {
if err = h.DockerRmi(dockerClient, fmt.Sprintf("%s%d", baseImg, i)); err != nil {
Expand All @@ -84,3 +98,22 @@ func createCmd(b *testing.B, docker *dockerCli.Client) *cobra.Command {
}
return commands.Build(logger, cfg.Config{}, packClient)
}

func setEnv() {
if baseImg = os.Getenv("baseImg"); baseImg == "" {
baseImg = "some-org/" + h.RandString(10)
}
trustedImg = baseImg + "-trusted-"
if builder = os.Getenv("builder"); builder == "" {
builder = "cnbs/sample-builder:bionic"
}
if mockAppPath = os.Getenv("mockAppPath"); mockAppPath == "" {
mockAppPath = filepath.Join("..", "acceptance", "testdata", "mock_app")
}
if paketoBuilder = os.Getenv("paketoBuilder"); paketoBuilder == "" {
paketoBuilder = "paketobuildpacks/builder:base"
}
if additionalBuildapck = os.Getenv("additionalBuildapck"); additionalBuildapck == "" {
additionalBuildapck = "docker://cnbs/sample-package:hello-universe"
}
}