add benchmark (#3433)

* add benchmark

* add benchmark github action

* commit

* permissions
This commit is contained in:
Caleb Doxsey 2022-06-17 15:52:35 -06:00 committed by GitHub
parent 1134244075
commit 64def90532
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 0 deletions

68
.github/workflows/benchmark.yaml vendored Normal file
View file

@ -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

View file

@ -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()
}
}