From 64def90532b4ff87fe85a0607ecaac05d8d3ba72 Mon Sep 17 00:00:00 2001 From: Caleb Doxsey Date: Fri, 17 Jun 2022 15:52:35 -0600 Subject: [PATCH] add benchmark (#3433) * add benchmark * add benchmark github action * commit * permissions --- .github/workflows/benchmark.yaml | 68 ++++++++++++++++++++++++++++++++ integration/benchmark_test.go | 43 ++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 .github/workflows/benchmark.yaml create mode 100644 integration/benchmark_test.go diff --git a/.github/workflows/benchmark.yaml b/.github/workflows/benchmark.yaml new file mode 100644 index 000000000..892d492ad --- /dev/null +++ b/.github/workflows/benchmark.yaml @@ -0,0 +1,68 @@ +name: Benchmark + +permissions: + contents: write + deployments: write + +on: + push: + branches: + - main + pull_request: + +jobs: + benchmark: + strategy: + fail-fast: false + matrix: + go-version: [1.18.x] + node-version: [16.x] + platform: [ubuntu-latest] + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/setup-go@b22fbbc2921299758641fab08929b4ac52b32923 # pin@v2 + with: + go-version: ${{ matrix.go-version }} + + - uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # pin@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: set env vars + run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH + + - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3 + with: + fetch-depth: 0 + + - uses: actions/cache@30f413bfed0a2bc738fdfd409e5a9e96b24545fd # pin@v3 + with: + path: | + ~/go/pkg + ~/.cache/go-build + ~/Library/Caches/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: build dev docker image + run: | + ./scripts/build-dev-docker.bash + + - name: start cluster + run: | + export POMERIUM_TAG=dev + cd ./integration/clusters/google-single + docker-compose up -d + + - name: integration tests + run: | + go test -bench Benchmark ./integration/... | tee benchmark.txt + + - name: store benchmark + uses: benchmark-action/github-action-benchmark@v1 + with: + tool: "go" + output-file-path: benchmark.txt + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: true diff --git a/integration/benchmark_test.go b/integration/benchmark_test.go new file mode 100644 index 000000000..a1ae68a61 --- /dev/null +++ b/integration/benchmark_test.go @@ -0,0 +1,43 @@ +package main + +import ( + "context" + "net/http" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/pomerium/pomerium/integration/flows" +) + +func BenchmarkLoggedInUserAccess(b *testing.B) { + ctx := context.Background() + client := getClient() + res, err := flows.Authenticate(ctx, client, mustParseURL("https://httpdetails.localhost.pomerium.io/by-domain"), + flows.WithEmail("user1@dogs.test")) + require.NoError(b, err) + _ = res.Body.Close() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + req, err := http.NewRequestWithContext(ctx, "GET", "https://httpdetails.localhost.pomerium.io/by-domain", nil) + require.NoError(b, err) + res, err := client.Do(req) + require.NoError(b, err) + res.Body.Close() + } +} + +func BenchmarkLoggedOutUserAccess(b *testing.B) { + ctx := context.Background() + client := getClient() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + req, err := http.NewRequestWithContext(ctx, "GET", "https://httpdetails.localhost.pomerium.io/by-domain", nil) + require.NoError(b, err) + res, err := client.Do(req) + require.NoError(b, err) + res.Body.Close() + } +}