Skip to content

Commit

Permalink
Merge branch 'hperl/e2e-benchmark' into hperl/exp/vanguard
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Jan 7, 2025
2 parents 0dae7e8 + 05f5180 commit c048b89
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 139 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/licenses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
push:
branches:
- main
- v3
- master

jobs:
Expand All @@ -25,7 +26,7 @@ jobs:
uses: ory/ci/licenses/write@master
if:
${{ github.ref == 'refs/heads/main' || github.ref ==
'refs/heads/master' }}
'refs/heads/master' || github.ref == 'refs/heads/v3' }}
with:
author-email:
${{ secrets.ORY_BOT_PAT &&
Expand Down
64 changes: 2 additions & 62 deletions .reports/dep-licenses.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"github.com/cenkalti/backoff/v3","MIT"
"module name","licenses"

"github.com/cespare/xxhash/v2","MIT"
"github.com/dgraph-io/ristretto","Apache-2.0"
"github.com/dgraph-io/ristretto/z","MIT"
Expand All @@ -13,65 +14,9 @@
"github.com/gobuffalo/httptest","MIT"
"github.com/gobuffalo/httptest/internal/takeon/github.com/ajg/form","BSD-3-Clause"
"github.com/gobuffalo/httptest/internal/takeon/github.com/markbates/hmax","MIT"
"filippo.io/edwards25519","BSD-3-Clause"
"github.com/Masterminds/semver/v3","MIT"
"github.com/aymerick/douceur","MIT"
"github.com/fatih/color","MIT"
"github.com/fatih/structs","MIT"
"github.com/go-sql-driver/mysql","MPL-2.0"
"github.com/gobuffalo/envy","MIT"
"github.com/gobuffalo/fizz","MIT"
"github.com/gobuffalo/flect","MIT"
"github.com/gobuffalo/github_flavored_markdown","MIT"
"github.com/gobuffalo/github_flavored_markdown/internal/russross/blackfriday","BSD-2-Clause"
"github.com/gobuffalo/github_flavored_markdown/internal/shurcooL/sanitized_anchor_name","MIT"
"github.com/gobuffalo/helpers","MIT"
"github.com/gobuffalo/nulls","MIT"
"github.com/gobuffalo/plush/v4","MIT"
"github.com/gobuffalo/pop/v6","MIT"
"github.com/gobuffalo/tags/v3","MIT"
"github.com/gobuffalo/validate/v3","MIT"
"github.com/gofrs/uuid","MIT"
"github.com/gorilla/css/scanner","BSD-3-Clause"
"github.com/jackc/chunkreader/v2","MIT"
"github.com/jackc/pgconn","MIT"
"github.com/jackc/pgio","MIT"
"github.com/jackc/pgpassfile","MIT"
"github.com/jackc/pgproto3/v2","MIT"
"github.com/jackc/pgservicefile","MIT"
"github.com/jackc/pgx/v5","MIT"
"github.com/jackc/puddle/v2","MIT"
"github.com/jmoiron/sqlx","MIT"
"github.com/joho/godotenv","MIT"
"github.com/kballard/go-shellquote","MIT"
"github.com/luna-duclos/instrumentedsql","MIT"
"github.com/mattn/go-colorable","MIT"
"github.com/mattn/go-isatty","MIT"
"github.com/microcosm-cc/bluemonday","BSD-3-Clause"
"github.com/rogpeppe/go-internal/modfile","BSD-3-Clause"
"github.com/sergi/go-diff/diffmatchpatch","MIT"
"github.com/sourcegraph/annotate","BSD-3-Clause"
"github.com/sourcegraph/syntaxhighlight","BSD-3-Clause"
"golang.org/x/crypto/pbkdf2","BSD-3-Clause"
"golang.org/x/mod","BSD-3-Clause"
"golang.org/x/net/html","BSD-3-Clause"
"golang.org/x/sync","BSD-3-Clause"
"golang.org/x/sys/unix","BSD-3-Clause"
"golang.org/x/text","BSD-3-Clause"
"gopkg.in/yaml.v2","Apache-2.0"
"github.com/gofrs/uuid","MIT"
"github.com/grpc-ecosystem/go-grpc-middleware/v2","Apache-2.0"
"golang.org/x/net","BSD-3-Clause"
"golang.org/x/sys/unix","BSD-3-Clause"
"golang.org/x/text","BSD-3-Clause"
"google.golang.org/genproto/googleapis/rpc/status","Apache-2.0"
"google.golang.org/grpc","Apache-2.0"
"google.golang.org/protobuf","BSD-3-Clause"
"github.com/julienschmidt/httprouter","BSD-3-Clause"
"github.com/luna-duclos/instrumentedsql","MIT"
"github.com/ory/analytics-go/v5","MIT"
"github.com/segmentio/backo-go","MIT"
"github.com/xtgo/uuid","BSD-3-Clause"
"github.com/ory/graceful","Apache-2.0"
"github.com/pkg/errors","BSD-2-Clause"
"github.com/golang/protobuf/proto","BSD-3-Clause"
Expand All @@ -83,11 +28,6 @@
"google.golang.org/genproto/googleapis/rpc","Apache-2.0"
"google.golang.org/grpc","Apache-2.0"
"google.golang.org/protobuf","BSD-3-Clause"
"github.com/golang/protobuf/proto","BSD-3-Clause"
"github.com/nyaruka/phonenumbers","MIT"
"github.com/ory/jsonschema/v3","BSD-3-Clause"
"golang.org/x/text","BSD-3-Clause"
"google.golang.org/protobuf","BSD-3-Clause"
"cloud.google.com/go/compute/metadata","Apache-2.0"
"code.dny.dev/ssrf","MIT"
"dario.cat/mergo","BSD-3-Clause"
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

**Table of Contents**

- [0.0.0 (2024-12-30)](#000-2024-12-30)
- [0.0.0 (2025-01-02)](#000-2025-01-02)
- [Bug Fixes](#bug-fixes)
- [Features](#features)
- [0.13.0-alpha.0 (2024-02-27)](#0130-alpha0-2024-02-27)
Expand Down Expand Up @@ -161,7 +161,7 @@

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# [0.0.0](https://github.com/ory/keto/compare/v0.13.0-alpha.0...v0.0.0) (2024-12-30)
# [0.0.0](https://github.com/ory/keto/compare/v0.13.0-alpha.0...v0.0.0) (2025-01-02)

### Bug Fixes

Expand Down
24 changes: 12 additions & 12 deletions internal/e2e/cli_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ type cliClient struct {
c *cmdx.CommandExecuter
}

func (g *cliClient) queryNamespaces(t *testing.T) (res ketoapi.GetNamespacesResponse) {
func (g *cliClient) queryNamespaces(t testing.TB) (res ketoapi.GetNamespacesResponse) {
t.Skip("not implemented for the CLI")
return
}

var _ client = (*cliClient)(nil)

func (g *cliClient) oplCheckSyntax(t *testing.T, _ []byte) []*ketoapi.ParseError {
func (g *cliClient) oplCheckSyntax(t testing.TB, content []byte) []*ketoapi.ParseError {
t.Skip("not implemented as a command yet")
return []*ketoapi.ParseError{}
}

func (g *cliClient) createTuple(t *testing.T, r *ketoapi.RelationTuple) {
func (g *cliClient) createTuple(t testing.TB, r *ketoapi.RelationTuple) {
tupleEnc, err := json.Marshal(r)
require.NoError(t, err)

Expand Down Expand Up @@ -80,7 +80,7 @@ func (g *cliClient) assembleQueryFlags(q *ketoapi.RelationQuery, opts []x.Pagina
return flags
}

func (g *cliClient) queryTuple(t *testing.T, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) *ketoapi.GetResponse {
func (g *cliClient) queryTuple(t testing.TB, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) *ketoapi.GetResponse {
out := g.c.ExecNoErr(t, append(g.assembleQueryFlags(q, opts), "relation-tuple", "get")...)

var resp ketoapi.GetResponse
Expand All @@ -89,13 +89,13 @@ func (g *cliClient) queryTuple(t *testing.T, q *ketoapi.RelationQuery, opts ...x
return &resp
}

func (g *cliClient) queryTupleErr(t *testing.T, expected herodot.DefaultError, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) {
func (g *cliClient) queryTupleErr(t testing.TB, expected herodot.DefaultError, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) {
stdErr := g.c.ExecExpectedErr(t, append(g.assembleQueryFlags(q, opts), "relation-tuple", "get")...)
assert.Contains(t, stdErr, expected.GRPCCodeField.String())
assert.Contains(t, stdErr, expected.Error())
}

func (g *cliClient) check(t *testing.T, r *ketoapi.RelationTuple) bool {
func (g *cliClient) check(t testing.TB, r *ketoapi.RelationTuple) bool {
var sub string
if r.SubjectID != nil {
sub = *r.SubjectID
Expand All @@ -108,23 +108,23 @@ func (g *cliClient) check(t *testing.T, r *ketoapi.RelationTuple) bool {
return res.Allowed
}

func (g *cliClient) batchCheckErr(t *testing.T, requestTuples []*ketoapi.RelationTuple, expected herodot.DefaultError) {
func (g *cliClient) batchCheckErr(t testing.TB, requestTuples []*ketoapi.RelationTuple, expected herodot.DefaultError) {
t.Skip("not implemented for the CLI")
}

func (g *cliClient) batchCheck(t *testing.T, requestTuples []*ketoapi.RelationTuple) []checkResponse {
func (g *cliClient) batchCheck(t testing.TB, r []*ketoapi.RelationTuple) []checkResponse {
t.Skip("not implemented for the CLI")
return nil
}

func (g *cliClient) expand(t *testing.T, r *ketoapi.SubjectSet, depth int) *ketoapi.Tree[*ketoapi.RelationTuple] {
func (g *cliClient) expand(t testing.TB, r *ketoapi.SubjectSet, depth int) *ketoapi.Tree[*ketoapi.RelationTuple] {
out := g.c.ExecNoErr(t, "expand", r.Relation, r.Namespace, r.Object, "--"+cliexpand.FlagMaxDepth, fmt.Sprintf("%d", depth), "--"+cmdx.FlagFormat, string(cmdx.FormatJSON))
res := ketoapi.Tree[*ketoapi.RelationTuple]{}
require.NoError(t, json.Unmarshal([]byte(out), &res))
return &res
}

func (g *cliClient) waitUntilLive(t *testing.T) {
func (g *cliClient) waitUntilLive(t testing.TB) {
flags := make([]string, len(g.c.PersistentArgs))
copy(flags, g.c.PersistentArgs)

Expand All @@ -142,7 +142,7 @@ func (g *cliClient) waitUntilLive(t *testing.T) {
require.Equal(t, grpcHealthV1.HealthCheckResponse_SERVING.String()+"\n", out)
}

func (g *cliClient) deleteTuple(t *testing.T, r *ketoapi.RelationTuple) {
func (g *cliClient) deleteTuple(t testing.TB, r *ketoapi.RelationTuple) {
tupleEnc, err := json.Marshal(r)
require.NoError(t, err)

Expand All @@ -151,6 +151,6 @@ func (g *cliClient) deleteTuple(t *testing.T, r *ketoapi.RelationTuple) {
assert.Len(t, stderr, 0, stdout)
}

func (g *cliClient) deleteAllTuples(t *testing.T, q *ketoapi.RelationQuery) {
func (g *cliClient) deleteAllTuples(t testing.TB, q *ketoapi.RelationQuery) {
_ = g.c.ExecNoErr(t, append(g.assembleQueryFlags(q, nil), "relation-tuple", "delete-all", "--force")...)
}
76 changes: 76 additions & 0 deletions internal/e2e/e2e_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package e2e

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/keto/internal/namespace"
"github.com/ory/keto/internal/x/dbx"
"github.com/ory/keto/ketoapi"
"github.com/ory/x/pointerx"
)

func BenchmarkE2E(b *testing.B) {

dsn := dbx.GetSqlite(b, dbx.SQLiteMemory)
ctx, reg, namespaceTestMgr, getAddr := newInitializedReg(b, dsn, map[string]interface{}{"log.level": "panic"})
closeServer := startServer(ctx, b, reg)
b.Cleanup(closeServer)

_, _, readAddr := getAddr(b, "read")
_, _, writeAddr := getAddr(b, "write")
_, _, oplAddr := getAddr(b, "opl")

for _, cl := range []client{
newGrpcClient(b, ctx,
readAddr,
writeAddr,
oplAddr,
),
&restClient{
readURL: "http://" + readAddr,
writeURL: "http://" + writeAddr,
oplSyntaxURL: "http://" + oplAddr,
},
&sdkClient{
readRemote: readAddr,
writeRemote: writeAddr,
syntaxRemote: oplAddr,
},
} {

b.Run(fmt.Sprintf("client=%T", cl), func(b *testing.B) {
n := &namespace.Namespace{Name: "test"}
namespaceTestMgr.add(b, n)
cl.waitUntilLive(b)
b.ResetTimer()
for i := 0; i < b.N; i++ {
tuple := &ketoapi.RelationTuple{
Namespace: n.Name,
Object: fmt.Sprintf("object %d for client %T", i, cl),
Relation: "access",
SubjectID: pointerx.Ptr("client"),
}
cl.createTuple(b, tuple)

resp := cl.queryTuple(b, &ketoapi.RelationQuery{Namespace: &tuple.Namespace})
require.Len(b, resp.RelationTuples, 1)
assert.Equal(b, tuple, resp.RelationTuples[0])

assert.True(b, cl.check(b, tuple))
batchResult := cl.batchCheck(b, []*ketoapi.RelationTuple{tuple})
require.Len(b, batchResult, 1)
assert.True(b, batchResult[0].allowed)
assert.Empty(b, batchResult[0].errorMessage)

cl.deleteTuple(b, tuple)
resp = cl.queryTuple(b, &ketoapi.RelationQuery{Namespace: &tuple.Namespace})
require.Len(b, resp.RelationTuples, 0)
}
})
}

}
26 changes: 13 additions & 13 deletions internal/e2e/full_suit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ import (
type (
transactClient interface {
client
transactTuples(t *testing.T, ins []*ketoapi.RelationTuple, del []*ketoapi.RelationTuple)
transactTuples(t testing.TB, ins []*ketoapi.RelationTuple, del []*ketoapi.RelationTuple)
}
client interface {
createTuple(t *testing.T, r *ketoapi.RelationTuple)
deleteTuple(t *testing.T, r *ketoapi.RelationTuple)
deleteAllTuples(t *testing.T, q *ketoapi.RelationQuery)
queryTuple(t *testing.T, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) *ketoapi.GetResponse
queryTupleErr(t *testing.T, expected herodot.DefaultError, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter)
check(t *testing.T, r *ketoapi.RelationTuple) bool
batchCheck(t *testing.T, r []*ketoapi.RelationTuple) []checkResponse
batchCheckErr(t *testing.T, requestTuples []*ketoapi.RelationTuple, expected herodot.DefaultError)
expand(t *testing.T, r *ketoapi.SubjectSet, depth int) *ketoapi.Tree[*ketoapi.RelationTuple]
oplCheckSyntax(t *testing.T, content []byte) []*ketoapi.ParseError
waitUntilLive(t *testing.T)
queryNamespaces(t *testing.T) ketoapi.GetNamespacesResponse
createTuple(t testing.TB, r *ketoapi.RelationTuple)
deleteTuple(t testing.TB, r *ketoapi.RelationTuple)
deleteAllTuples(t testing.TB, q *ketoapi.RelationQuery)
queryTuple(t testing.TB, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter) *ketoapi.GetResponse
queryTupleErr(t testing.TB, expected herodot.DefaultError, q *ketoapi.RelationQuery, opts ...x.PaginationOptionSetter)
check(t testing.TB, r *ketoapi.RelationTuple) bool
batchCheck(t testing.TB, r []*ketoapi.RelationTuple) []checkResponse
batchCheckErr(t testing.TB, requestTuples []*ketoapi.RelationTuple, expected herodot.DefaultError)
expand(t testing.TB, r *ketoapi.SubjectSet, depth int) *ketoapi.Tree[*ketoapi.RelationTuple]
oplCheckSyntax(t testing.TB, content []byte) []*ketoapi.ParseError
waitUntilLive(t testing.TB)
queryNamespaces(t testing.TB) ketoapi.GetNamespacesResponse
}
)

Expand Down
Loading

0 comments on commit c048b89

Please sign in to comment.