bench

package
v0.271.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bench synthesizes tuples and checks from an authorization model and benchmarks the checks against a before and an after model on a counting embedded OpenFGA server.

Index

Constants

This section is empty.

Variables

View Source
var ErrSetup = errors.New("benchmark setup failed")

ErrSetup marks failures creating the embedded server or writing the model and tuples to it (e.g. tuples that do not fit the model); match with errors.Is.

Functions

This section is empty.

Types

type Check

type Check struct {
	Name     string `json:"name" jsonschema_description:"Human-readable check label."`
	User     string `json:"user" jsonschema_description:"The user in the check, as type:id."`
	Relation string `json:"relation" jsonschema_description:"The relation checked."`
	Object   string `json:"object" jsonschema_description:"The object checked, as type:id."`
}

Check is a single benchmark query.

type CheckResult

type CheckResult struct {
	Check
	Allowed bool     `json:"allowed" jsonschema_description:"The check answer under the before model."`
	Before  Metrics  `json:"before" jsonschema_description:"Metrics against the before model."`
	After   *Metrics `json:"after,omitempty" jsonschema_description:"Metrics against the after model; absent for a single-model profile."`
}

CheckResult is one check's outcome. After is nil for a single-model profile.

type Metrics

type Metrics struct {
	Reads      int64   `json:"reads" jsonschema_description:"Datastore reads the check performed."`
	Dispatches float64 `json:"dispatches" jsonschema_description:"Dispatches the check performed, averaged over the iterations."`
	P50Ms      float64 `json:"p50Ms" jsonschema_description:"Median latency in milliseconds."`
	P95Ms      float64 `json:"p95Ms" jsonschema_description:"95th percentile latency in milliseconds."`
}

Metrics are the measurements for one check against one model.

type Mismatch

type Mismatch struct {
	Check
	AllowedBefore bool `json:"allowedBefore" jsonschema_description:"The answer under the before model."`
	AllowedAfter  bool `json:"allowedAfter" jsonschema_description:"The answer under the after model."`
}

Mismatch is a check whose answer differs between the two models.

type Options

type Options struct {
	Iterations int            // timed checks per check; default 100
	ServerOpts map[string]any // embedded server options
}

Options configures Run.

type Result

type Result struct {
	Source     string  `json:"source" jsonschema_description:"Where the tuples and checks came from: workspace or synthesis."`
	Seed       uint64  `json:"seed,omitempty" jsonschema_description:"The synthesis seed, for reproducing the run."`
	TupleCount int     `json:"tupleCount" jsonschema_description:"Number of tuples the benchmark loaded."`
	Iterations int     `json:"iterations" jsonschema_description:"Timed iterations per check."`
	Tuples     []Tuple `` // synthesis only
	/* 130-byte string literal not displayed */
	Skipped    []string      `json:"skipped,omitempty" jsonschema_description:"Restrictions or checks synthesis could not cover."`
	Checks     []CheckResult `json:"checks" jsonschema_description:"Per-check results."`
	Totals     Totals        `json:"totals" jsonschema_description:"Metrics summed by the before answer."`
	Probes     int           `json:"probes" jsonschema_description:"Number of untimed answer-only probe checks compared between the models."`
	Mismatches []Mismatch    `json:"mismatches" jsonschema_description:"Checks whose answer differs between the models and is attributable to the rewrite."`
	// Unstable are differing answers that are engine nondeterminism, not an
	// effect of the rewrite: the original model's answer varied between
	// re-runs, or the check cannot reach any relation the rewrite changed.
	Unstable []Mismatch `json:"unstable" jsonschema_description:"Differing answers that are engine nondeterminism, not an effect of the rewrite."`
	// Unexercised are rewritten relations ("type#relation") the benchmark
	// never exercised. For a synthesized source, their dependency path reaches
	// a restriction synthesis skipped; for a workspace source, no workspace
	// check reaches them. Set by the command.
	Unexercised []string `` /* 228-byte string literal not displayed */
}

Result is the benchmark outcome.

func Run

func Run(ctx context.Context, before, after *openfgav1.AuthorizationModel, src *Source, o Options) (*Result, error)

Run benchmarks before (and after, when non-nil) over src. Checks run in source order against sequential servers: one for before, then a fresh one for after. Deny and allow are classified by the before answer.

type Source

type Source struct {
	Kind   string                `json:"kind"` // "workspace" | "synthesis"
	Seed   uint64                `json:"seed,omitempty"`
	Tuples []*openfgav1.TupleKey `json:"-"`
	Checks []Check               `json:"checks"`
	// Probes are untimed answer-only checks compared between the models.
	Probes  []Check  `json:"-"`
	Skipped []string `json:"skipped,omitempty"`
}

Source is the tuple set and checks a benchmark runs over.

func FromWorkspace

func FromWorkspace(ws *modeltest.Workspace) (*Source, []string, error)

FromWorkspace builds a benchmark Source from a loaded ofga test workspace: the union of every test's resolved tuples (identical keys collapsed) and one Check per (user, relation, object) asserted by any check case. Notices describe anything dropped: tests on a different inline model, and tuples that share a key but differ in condition (the first wins).

func Synthesize

Synthesize builds a deterministic tuple set and checks from m.

type SynthOptions

type SynthOptions struct {
	Seed           uint64
	Depth          int
	ObjectsPerType int
	Noise          int
}

SynthOptions tunes Synthesize. Zero values mean the defaults: seed 1, depth 6, 3 objects per type, 100 noise objects per type.

type Totals

type Totals struct {
	DenyReadsBefore      int64   `json:"denyReadsBefore" jsonschema_description:"Datastore reads summed over checks denied before, against the before model."`
	DenyReadsAfter       int64   `json:"denyReadsAfter" jsonschema_description:"Datastore reads summed over checks denied before, against the after model."`
	DenyDispatchesBefore float64 `json:"denyDispatchesBefore" jsonschema_description:"Dispatches summed over checks denied before, against the before model."`
	DenyDispatchesAfter  float64 `json:"denyDispatchesAfter" jsonschema_description:"Dispatches summed over checks denied before, against the after model."`
	AllowReadsBefore     int64   `json:"allowReadsBefore" jsonschema_description:"Datastore reads summed over checks allowed before, against the before model."`
	AllowReadsAfter      int64   `json:"allowReadsAfter" jsonschema_description:"Datastore reads summed over checks allowed before, against the after model."`
}

Totals sums metrics by the before answer: deny checks (false) and allow checks (true).

type Tuple

type Tuple struct {
	User     string `json:"user" jsonschema_description:"The tuple user, as type:id or type:id#relation."`
	Relation string `json:"relation" jsonschema_description:"The tuple relation."`
	Object   string `json:"object" jsonschema_description:"The tuple object, as type:id."`
}

Tuple is a relationship tuple without proto types, for serialized output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL