Skip to content

Commit

Permalink
Add benchmark-action/github-action-benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
prymitive committed Dec 18, 2023
1 parent 955e080 commit e4dcf37
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,20 @@ jobs:
- name: Test
run: make benchmark

- name: CPU
run: go tool pprof -top cpu.prof
- name: Download previous benchmark data
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Memory
run: go tool pprof -top mem.prof
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
tool: go
output-file-path: benchmark.txt
external-data-json-path: ./cache/benchmark-data.json
comment-on-alert: true
alert-threshold: "100%"
summary-always: true
auto-push: false
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ coverhtml: test

.PHONY: benchmark
benchmark:
$(MAKE) -C cmd/pint/bench fetch
go test \
-v \
-count=10 \
-run=none \
-bench=. \
-benchmem \
-cpuprofile cpu.prof \
-memprofile mem.prof \
./cmd/pint
-cpuprofile cpu.pprof \
-memprofile mem.pprof \
./cmd/pint | tee benchmark.txt
9 changes: 9 additions & 0 deletions cmd/pint/bench/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
REVISION := 31a27fb9e0e778bd8fe6097aa58c8ea598fe9cec

.PHONE: fetch
fetch:
curl -sL -o archive.tar.gz https://github.com/samber/awesome-prometheus-alerts/archive/$(REVISION).tar.gz
tar -xf archive.tar.gz
rm -fr rules
mv awesome-prometheus-alerts-$(REVISION)/dist/rules rules
rm -fr awesome-prometheus-alerts-$(REVISION) archive.tar.gz
7 changes: 7 additions & 0 deletions cmd/pint/bench/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Benchmark data

A collection of Prometheus rules copied from
[samber/awesome-prometheus-alerts](https://github.com/samber/awesome-prometheus-alerts)
and used to benchmark pint.

Run `make fetch` first to download and unpack rules into `rules` folder.
47 changes: 47 additions & 0 deletions cmd/pint/bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"context"
"log/slog"
"testing"

"github.com/prometheus/client_golang/prometheus"

"github.com/cloudflare/pint/internal/config"
"github.com/cloudflare/pint/internal/discovery"
"github.com/cloudflare/pint/internal/git"
"github.com/cloudflare/pint/internal/log"
)

func BenchmarkFindEntries(b *testing.B) {
log.Setup(slog.LevelError, true)

finder := discovery.NewGlobFinder(
[]string{"bench/rules"},
git.NewPathFilter(nil, nil, nil),
)
for n := 0; n < b.N; n++ {
_, _ = finder.Find()
}
}

func BenchmarkCheckRules(b *testing.B) {
log.Setup(slog.LevelError, true)

finder := discovery.NewGlobFinder(
[]string{"bench/rules"},
git.NewPathFilter(nil, nil, nil),
)
entries, err := finder.Find()
if err != nil {
b.Errorf("Find() error: %s", err)
b.FailNow()
}

ctx := context.Background()
cfg, _ := config.Load("", false)
gen := config.NewPrometheusGenerator(cfg, prometheus.NewRegistry())
for n := 0; n < b.N; n++ {
_, _ = checkRules(ctx, 10, true, gen, cfg, entries)
}
}

0 comments on commit e4dcf37

Please sign in to comment.