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

Add benchmarks to GHA #1405

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
28 changes: 28 additions & 0 deletions .github/workflows/build-test.yaml
Expand Up @@ -220,3 +220,31 @@ jobs:
input: "proto/internal"
against: "https://github.com/authzed/spicedb.git#branch=main,subdir=proto/internal"
buf_token: "${{ secrets.BUF_REGISTRY_TOKEN }}"
go-bench:
name: "Go Benchmark"
runs-on: ["self-hosted", "benchmarks"]
needs: "paths-filter"
if: |
needs.paths-filter.outputs.codechange == 'true'
steps:
- uses: "actions/checkout@v3"
- uses: "authzed/actions/setup-go@main"
- name: "Benchmark"
run: |
set -o pipefail # Don't let tee replace the exit-code
go run mage.go test:bench | tee benchmarks.txt
- name: "Download previous benchmark data"
uses: "actions/cache@v1"
with:
path: "./cache"
key: "${{ runner.name }}-benchmark-main"
- uses: "benchmark-action/github-action-benchmark@v1"
with:
tool: "go"
output-file-path: "benchmarks.txt"
save-data-file: "${{ github.ref_name == 'main' }}"
external-data-json-path: "./cache/benchmark-data.json"
github-token: "${{ github.token }}"
auto-push: false
comment-on-alert: true
summary-always: true
13 changes: 13 additions & 0 deletions .github/workflows/lint.yaml
Expand Up @@ -11,9 +11,22 @@ on: # yamllint disable-line rule:truthy
types:
- "checks_requested"
jobs:
go-filter:
runs-on: "ubuntu-latest"
outputs:
gochange: "${{ steps.code-filter.outputs.gochange }}"
steps:
- uses: "actions/checkout@v3"
- uses: "dorny/paths-filter@v2"
id: "go-filter"
with:
filters: |
gochange:
- "**.go"
go-lint:
name: "Lint Go"
runs-on: "buildjet-4vcpu-ubuntu-2204"
if: "needs.paths-filter.outputs.gochange == 'true'"
steps:
- uses: "actions/checkout@v4"
- uses: "authzed/actions/setup-go@main"
Expand Down
12 changes: 4 additions & 8 deletions internal/testserver/datastore/crdb.go
Expand Up @@ -46,24 +46,20 @@ func RunCRDBForTesting(t testing.TB, bridgeNetworkName string) RunningEngineForT
NetworkID: bridgeNetworkName,
})
require.NoError(t, err)

builder := &crdbTester{
hostname: "localhost",
creds: "root:fake",
}
t.Cleanup(func() {
require.NoError(t, pool.Purge(resource))
})

port := resource.GetPort(fmt.Sprintf("%d/tcp", 26257))
builder := &crdbTester{creds: "root:fake"}
if bridgeNetworkName != "" {
builder.hostname = name
builder.port = "26257"
} else {
builder.port = port
builder.hostname = "localhost"
builder.port = resource.GetPort("26257/tcp")
}

uri := fmt.Sprintf("postgres://%s@localhost:%s/defaultdb?sslmode=disable", builder.creds, port)
uri := fmt.Sprintf("postgres://%s@localhost:%s/defaultdb?sslmode=disable", builder.creds, builder.port)
require.NoError(t, pool.Retry(func() error {
var err error
ctx, cancelConnect := context.WithTimeout(context.Background(), dockerBootTimeout)
Expand Down
35 changes: 18 additions & 17 deletions internal/testserver/datastore/mysql.go
Expand Up @@ -21,9 +21,10 @@ import (
)

const (
mysqlPort = 3306
defaultCreds = "root:secret"
testDBPrefix = "spicedb_test_"
mysqlPort = "3306"
mysqlPortPair = mysqlPort + "/tcp"
defaultCreds = "root:secret"
testDBPrefix = "spicedb_test_"
)

type mysqlTester struct {
Expand Down Expand Up @@ -57,33 +58,33 @@ func RunMySQLForTestingWithOptions(t testing.TB, options MySQLTesterOptions, bri

name := fmt.Sprintf("mysql-%s", uuid.New().String())
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Name: name,
Repository: "mysql",
Tag: containerImageTag,
Env: []string{"MYSQL_ROOT_PASSWORD=secret"},
// increase max connections (default 151) to accommodate tests using the same docker container
Cmd: []string{"--max-connections=500"},
NetworkID: bridgeNetworkName,
Name: name,
Repository: "mysql",
Tag: containerImageTag,
Env: []string{"MYSQL_ROOT_PASSWORD=secret"},
ExposedPorts: []string{mysqlPortPair},
Cmd: []string{"--max-connections=500"}, // accommodate tests using the same container
NetworkID: bridgeNetworkName,
})
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, pool.Purge(resource))
})

builder := &mysqlTester{
creds: defaultCreds,
options: options,
}
t.Cleanup(func() {
require.NoError(t, pool.Purge(resource))
})

port := resource.GetPort(fmt.Sprintf("%d/tcp", mysqlPort))
if bridgeNetworkName != "" {
builder.hostname = name
builder.port = fmt.Sprintf("%d", mysqlPort)
builder.port = mysqlPort
} else {
builder.port = port
builder.hostname = "localhost"
builder.port = resource.GetPort(mysqlPortPair)
}

dsn := fmt.Sprintf("%s@(localhost:%s)/mysql?parseTime=true", builder.creds, port)
dsn := fmt.Sprintf("%s@(localhost:%s)/mysql?parseTime=true", builder.creds, builder.port)
require.NoError(t, pool.Retry(func() error {
var err error
builder.db, err = sql.Open("mysql", dsn)
Expand Down
5 changes: 5 additions & 0 deletions magefiles/test.go
Expand Up @@ -53,6 +53,11 @@ func (Test) Analyzers() error {
return goDirTest("./tools/analyzers", "./...")
}

// Bench Runs benchmarks
func (Test) Bench() error {
return goTest("-bench=.", "-benchmem", "-run=^$", "-tags=ci,docker,skipintegrationtests", "-timeout=10m", "./...")
}

// Wasm Run wasm browser tests
func (Test) Wasm() error {
// build the test binary
Expand Down
6 changes: 5 additions & 1 deletion pkg/datastore/test/tuples.go
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -600,7 +601,10 @@ func CreateAlreadyExistingTest(t *testing.T, tester DatastoreTester) {

_, err = common.WriteTuples(ctx, ds, core.RelationTupleUpdate_CREATE, tpl1)
require.ErrorAs(err, &common.CreateRelationshipExistsError{})
require.Contains(err.Error(), "could not CREATE relationship ")
require.Condition(func() bool {
return strings.Contains(err.Error(), "could not CREATE relationship") || // mysql5
strings.Contains(err.Error(), "could not CREATE one or more relationships") // mysql8
})
grpcutil.RequireStatus(t, codes.AlreadyExists, err)

f := func(ctx context.Context, rwt datastore.ReadWriteTransaction) error {
Expand Down