From dd3276908c5bdb29f943c8b897dae335f0f780e7 Mon Sep 17 00:00:00 2001 From: Jian Zhang Date: Fri, 7 Feb 2025 17:25:27 +0800 Subject: [PATCH] add benchmark pipeline --- .github/workflows/benchmark.yaml | 45 ++++++++++++++++++++++++++++++++ Makefile | 11 ++++++++ benchmarks/baseline.txt | 16 ++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 .github/workflows/benchmark.yaml create mode 100644 benchmarks/baseline.txt diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml new file mode 100644 index 000000000..e62777e4d --- /dev/null +++ b/.github/workflows/benchmark.yaml @@ -0,0 +1,45 @@ +name: Benchmark Test + +on: + pull_request: + branches: + - main + +jobs: + benchmark: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Install dependencies + run: | + go mod download + go mod tidy + + # - name: Debug via SSH + # uses: mxschmitt/action-tmate@v3 + + - name: Run benchmark test + # working-directory: test/e2e + run: | + ARTIFACT_PATH=/tmp/artifacts make test-benchmark + + - name: Upload benchmark results + uses: actions/upload-artifact@v4 + with: + name: benchmark-artifacts + path: /tmp/artifacts/ + + - name: Compare with baseline + run: | + go install golang.org/x/perf/cmd/benchstat@latest + benchstat benchmarks/baseline.txt new.txt + diff --git a/Makefile b/Makefile index ba2bc7953..bc7d049fe 100644 --- a/Makefile +++ b/Makefile @@ -153,6 +153,11 @@ test: manifests generate fmt lint test-unit test-e2e #HELP Run all tests. e2e: #EXHELP Run the e2e tests. go test -count=1 -v ./test/e2e/... +.PHONY: benchmark +benchmark: #EXHELP Run the benchmark tests. + export CATALOG_IMG=registry.redhat.io/redhat/redhat-operator-index:v4.18 + go test -v -run=^$ -bench=. -benchmem -count=1 -v ./test/e2e/... > new.txt + E2E_REGISTRY_NAME := docker-registry E2E_REGISTRY_NAMESPACE := operator-controller-e2e @@ -209,6 +214,12 @@ test-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/e2e test-e2e: GO_BUILD_FLAGS := -cover test-e2e: run image-registry e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster +.PHONY: test-benchmark +test-benchmark: KIND_CLUSTER_NAME := operator-controller-benchmark +test-benchmark: KUSTOMIZE_BUILD_DIR := config/overlays/benchmark +test-benchmark: GO_BUILD_FLAGS := -cover +test-benchmark: run image-registry benchmark kind-clean #HELP Run benchmark test suite on local kind cluster + .PHONY: extension-developer-e2e extension-developer-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/cert-manager extension-developer-e2e: KIND_CLUSTER_NAME := operator-controller-ext-dev-e2e #EXHELP Run extension-developer e2e on local kind cluster diff --git a/benchmarks/baseline.txt b/benchmarks/baseline.txt new file mode 100644 index 000000000..6bf274941 --- /dev/null +++ b/benchmarks/baseline.txt @@ -0,0 +1,16 @@ +goos: darwin +goarch: arm64 +pkg: github.com/operator-framework/operator-controller/test/e2e +cpu: Apple M1 Pro +BenchmarkCreateClusterCatalog-10 1 1352852042 ns/op 404520 B/op 3914 allocs/op +BenchmarkCreateClusterCatalog-10 13 86982353 ns/op 36907 B/op 394 allocs/op +BenchmarkCreateClusterCatalog-10 12 84962496 ns/op 34555 B/op 393 allocs/op +BenchmarkCreateClusterCatalog-10 18 70375363 ns/op 34880 B/op 388 allocs/op +BenchmarkCreateClusterCatalog-10 15 71715708 ns/op 37654 B/op 399 allocs/op +BenchmarkCreateClusterCatalog-10 13 85251170 ns/op 36572 B/op 396 allocs/op +BenchmarkCreateClusterCatalog-10 13 83413260 ns/op 38435 B/op 393 allocs/op +BenchmarkCreateClusterCatalog-10 13 93851487 ns/op 37249 B/op 395 allocs/op +BenchmarkCreateClusterCatalog-10 13 78722212 ns/op 36593 B/op 393 allocs/op +BenchmarkCreateClusterCatalog-10 13 86393522 ns/op 37404 B/op 395 allocs/op +PASS +ok github.com/operator-framework/operator-controller/test/e2e 32.699s