Documentation
¶
Overview ¶
Package engine ties a project to one environment: it builds components lazily from the plugin registry, resolves svc:// addresses through the runtime, and runs the multi-service operations (up, down, status) every front end shares.
Index ¶
- Constants
- Variables
- func All[T any](a *App, kind core.Kind) (map[string]T, map[string]error)
- func DefaultVar(v *spec.DashVar, values []string) []string
- func ExpandQuery(q string, vars map[string][]string, rng, step time.Duration) string
- func FillQuery(q *spec.Query, args map[string]string) (string, []string)
- func Get[T any](a *App, kind core.Kind, name string) (T, string, error)
- func MarshalTargets(ts []ScrapeTarget) ([]byte, error)
- func Pattern(names []string) string
- func Ready(st core.Status) bool
- func SortedKeys[V any](m map[string]V) []string
- func WriteReportFile(file string, write func(io.Writer)) error
- type App
- func (a *App) AI(sock string) (*ai.Runner, error)
- func (a *App) AIDir() string
- func (a *App) AlertRules() []spec.Alert
- func (a *App) Build(ctx context.Context, s *spec.Service, tag string, out io.Writer) (string, error)
- func (a *App) BuildFrom(ctx context.Context, s *spec.Service, tag, ref string, out io.Writer) (string, error)
- func (a *App) CheckAlerts(ctx context.Context) ([]Firing, []error)
- func (a *App) Close() error
- func (a *App) Component(name string) (any, error)
- func (a *App) CreateNamespace(ctx context.Context, ns string) error
- func (a *App) DefaultImage(ctx context.Context, s *spec.Service) string
- func (a *App) DefaultTag(ctx context.Context, ref string) string
- func (a *App) Deploy(ctx context.Context, name, tag string) error
- func (a *App) Down(ctx context.Context, targets []string, out io.Writer) error
- func (a *App) EnvOverrides(name string) map[string]string
- func (a *App) Environment() *spec.Environment
- func (a *App) Exec(ctx context.Context, name string, o core.ExecOptions) error
- func (a *App) Guard() error
- func (a *App) ImageBased() bool
- func (a *App) InfraApp() (*App, error)
- func (a *App) Kind(name string) (core.Kind, string, error)
- func (a *App) LoadLimits(name string) LoadLimits
- func (a *App) LoadState(ctx context.Context) (map[string]string, error)
- func (a *App) LoadTestRun(id, suite string) (*TestRun, error)
- func (a *App) Logs(ctx context.Context, name string, o core.LogOptions) (<-chan core.LogLine, error)
- func (a *App) ManifestDirs() []string
- func (a *App) MeasureReport(ctx context.Context, name, source string, from, to time.Time) (*ReportResult, error)
- func (a *App) Names(kind core.Kind) []string
- func (a *App) Namespace() string
- func (a *App) Namespaces(ctx context.Context) ([]string, error)
- func (a *App) NewTestRun(suite string, o TestOptions) *TestRun
- func (a *App) Nudge(ctx context.Context, name string, dir int) (float64, error)
- func (a *App) Owner(name string) (core.Runtime, *spec.Service, error)
- func (a *App) PreviousBenches(r *TestRun) map[string]Bench
- func (a *App) Project() *spec.Project
- func (a *App) Queriers() map[string]core.Querier
- func (a *App) Queries() map[string]*spec.Query
- func (a *App) QueryNames() []string
- func (a *App) ReportFile(name string, at time.Time) string
- func (a *App) ReportNames() []string
- func (a *App) Resolve(ctx context.Context, addr string) (string, error)
- func (a *App) Resources(ctx context.Context, name string) ([]core.Resources, error)
- func (a *App) Restart(ctx context.Context, name string) error
- func (a *App) RunQuery(ctx context.Context, comp, text string) (core.Table, error)
- func (a *App) RunSaved(ctx context.Context, name string, args map[string]string) (core.Table, error)
- func (a *App) RunTask(ctx context.Context, name string, args []string, out io.Writer) error
- func (a *App) RunTests(ctx context.Context, s *spec.TestSuite, run *TestRun, jobs []TestJob) error
- func (a *App) Runtime() core.Runtime
- func (a *App) SaveTestRun(r *TestRun) error
- func (a *App) Scale(ctx context.Context, name string, n int) error
- func (a *App) ScaleBy(ctx context.Context, names []string, delta int, set bool) error
- func (a *App) ScrapeTargets(ctx context.Context, host string) ([]ScrapeTarget, error)
- func (a *App) Service(name string) (*spec.Service, error)
- func (a *App) SetAutoscale(ctx context.Context, name string, b core.Bounds) error
- func (a *App) SetEnv(ctx context.Context, names []string, kv map[string]string) error
- func (a *App) SetRate(ctx context.Context, name string, rps float64, force bool) error
- func (a *App) SetResources(ctx context.Context, name string, r core.Resources) error
- func (a *App) SetState(ctx context.Context, kv map[string]string) error
- func (a *App) SharedElsewhere(name string) bool
- func (a *App) Source(ctx context.Context, ref string) (string, error)
- func (a *App) Start(ctx context.Context, name string) error
- func (a *App) StartInOrder(ctx context.Context, names []string, wait time.Duration) error
- func (a *App) StateDir() string
- func (a *App) Status(ctx context.Context, name string) (core.Status, error)
- func (a *App) StatusAll(ctx context.Context, names []string) []core.Status
- func (a *App) Stop(ctx context.Context, name string) error
- func (a *App) Suite(name string) (*spec.TestSuite, error)
- func (a *App) SuiteNames() []string
- func (a *App) TagImage(s *spec.Service, tag string) string
- func (a *App) Targets(targets []string, deps bool) ([]string, error)
- func (a *App) TaskHelp(name string) string
- func (a *App) TaskNames() []string
- func (a *App) Tasks() map[string]spec.Task
- func (a *App) TestRuns(suite string) []string
- func (a *App) Up(ctx context.Context, targets []string, o UpOptions) error
- func (a *App) UseNamespace(ns string) error
- func (a *App) VarValues(ctx context.Context, v *spec.DashVar) ([]string, error)
- func (a *App) Vars(ctx context.Context) (map[string]Var, error)
- func (a *App) Wait(ctx context.Context, name string, timeout time.Duration) (core.Status, error)
- type Bench
- type Firing
- type Level
- type LoadLimits
- type ReportResult
- type ReportRow
- type ScrapeTarget
- type TestCase
- type TestJob
- type TestOptions
- type TestRun
- type UpOptions
- type Var
Constants ¶
const ( TestRunning = "run" TestPass = "pass" TestFail = "fail" TestSkip = "skip" TestStopped = "stopped" )
Test statuses; a test still going is TestRunning, one cut short by a stop TestStopped.
const AllValue = "$__all"
AllValue is the "all" choice of a dashboard variable: a regex that matches anything.
Variables ¶
var DefaultAlerts = []spec.Alert{
{Name: "memory", Source: "hosts", Metric: "memory", Warn: 90, Crit: 98, Unit: "%"},
{Name: "cpu", Source: "hosts", Metric: "cpu", Warn: 90, Crit: 98, Unit: "%"},
{Name: "disk", Source: "hosts", Metric: "disk", Warn: 97, Crit: 98, Unit: "%"},
}
DefaultAlerts watch the nodes when rig.yaml names no alerts: memory and CPU at 90% and 98%, disk at 97% and 98%.
var ErrOverMax = errors.New("rate above the generator's max (pass force to exceed it)")
var ErrProtected = errors.New("environment is protected: pass --yes to change it")
ErrProtected stops a mutating operation on a protected environment unless the caller confirmed.
var NamespaceOverride string
NamespaceOverride, when set, replaces the namespace of a Kubernetes environment for this run (rig -n); otherwise the one `rig ns` picked, kept in .rig/<env>/namespace, does.
Functions ¶
func DefaultVar ¶
DefaultVar is what a variable starts as: its default, else all (when offered), else the first value.
func ExpandQuery ¶
ExpandQuery fills a panel query's $variables (several values become a|b, all becomes .*) and Grafana's $__range, $__interval and $__rate_interval for the time range and step.
func FillQuery ¶
FillQuery replaces {{name}} placeholders with args, then the query's defaults; it reports placeholders left without a value.
func Get ¶
Get returns component name of kind as T; with name "" the only (or first) one of that kind, falling back to what the runtime itself provides (logs, hosts) or to a default adapter.
func MarshalTargets ¶
func MarshalTargets(ts []ScrapeTarget) ([]byte, error)
func Pattern ¶
Pattern is a -run expression that matches exactly these tests (full names, TestX/sub/...), level by level: every name of a level is allowed at that level, so a few more may run.
func SortedKeys ¶
SortedKeys is a small helper front ends use for stable output.
Types ¶
type App ¶
type App struct {
Spec *spec.Project
Env *spec.Environment
// Confirmed lets mutating operations run on a protected environment.
Confirmed bool
// contains filtered or unexported fields
}
func (*App) AI ¶
AI is the assistant's runner for this project and environment; sock is the bridge that answers its approvals and UI actions ("" when nothing can).
func (*App) AlertRules ¶
func (*App) Build ¶
func (a *App) Build(ctx context.Context, s *spec.Service, tag string, out io.Writer) (string, error)
Build builds one service's image from the working tree and returns the reference.
func (*App) BuildFrom ¶
func (a *App) BuildFrom(ctx context.Context, s *spec.Service, tag, ref string, out io.Writer) (string, error)
BuildFrom builds one service's image with the builder its build section asks for, from a git ref when given, and returns the reference. Pushing over a tag the registry already has needs confirmation.
func (*App) CheckAlerts ¶
CheckAlerts evaluates every rule once; the most severe firings come first. A rule that cannot be evaluated is reported as an error, not as a firing.
func (*App) DefaultTag ¶
DefaultTag names a build: the branch (or ref) when it is short enough to read, then the time, e.g. feature-x-20261003-1907; a plain timestamp outside git or for long branch names.
func (*App) Deploy ¶
Deploy rolls out a service. A tag deploys that tag of its image from the registry without building.
func (*App) Down ¶
Down stops targets in reverse dependency order. With no targets it stops every app and load service: infrastructure, and services shared from another environment, stop only when named.
func (*App) EnvOverrides ¶
EnvOverrides are the variables SetEnv gave a service.
func (*App) Environment ¶
func (a *App) Environment() *spec.Environment
func (*App) Guard ¶
Guard refuses a mutating operation on a protected environment the caller did not confirm.
func (*App) ImageBased ¶
ImageBased reports whether the runtime runs images (and so needs builds) rather than local processes.
func (*App) InfraApp ¶
InfraApp opens (once) the environment that runs this one's shared services; nil when there is none.
func (*App) LoadLimits ¶
func (a *App) LoadLimits(name string) LoadLimits
func (*App) LoadTestRun ¶
LoadTestRun reads a saved run; id "" or "last" is the newest (of suite, when given).
func (*App) ManifestDirs ¶
ManifestDirs is where this project keeps Kubernetes manifests: the project's manifests:, else the runtime's manifests option, else the project directory.
func (*App) MeasureReport ¶
func (a *App) MeasureReport(ctx context.Context, name, source string, from, to time.Time) (*ReportResult, error)
MeasureReport runs a report's queries over [from, to] against source (default the report's own) and summarises every series they return.
func (*App) Namespace ¶
Namespace is the namespace the environment works in, "" when it is not on Kubernetes.
func (*App) Namespaces ¶
Namespaces lists the cluster's namespaces.
func (*App) NewTestRun ¶
func (a *App) NewTestRun(suite string, o TestOptions) *TestRun
NewTestRun starts the record of a run of suite.
func (*App) Nudge ¶
Nudge moves a generator's rate one step up (dir > 0) or down and returns the new rate.
func (*App) Owner ¶
Owner returns the runtime that runs the named service and that environment's view of it.
func (*App) PreviousBenches ¶
PreviousBenches are the benchmarks of the newest saved run of suite before r that has any, by package and name.
func (*App) Queriers ¶
Queriers lists every component that answers ad hoc queries, the runtime included.
func (*App) Queries ¶
Queries are the project's saved queries with this environment's replacing those of the same name.
func (*App) QueryNames ¶
func (*App) ReportFile ¶
ReportFile is where a measured report is saved unless the caller names a file: the project's data directory, outside the repository.
func (*App) ReportNames ¶
func (*App) Resolve ¶
Resolve turns svc://service:port[/path] into an address reachable from here; anything else is returned as is.
func (*App) RunSaved ¶
func (a *App) RunSaved(ctx context.Context, name string, args map[string]string) (core.Table, error)
RunSaved runs a saved query with placeholder values.
func (*App) RunTask ¶
RunTask runs a task's steps in order with sh -c from the project directory, stopping at the first failure. svc:// addresses in a step become a host:port reachable from here, and a nested `rig` inherits this project, environment and confirmation. A NAME=value arg sets that env var for the steps (overriding any manifest var or pre-set shell env of the same name) instead of requiring it pre-set; every other arg reaches every step positionally as $1... and $RIG_ARGS.
func (*App) RunTests ¶
RunTests runs the jobs of a suite one after another into run, stopping at ctx's end, and saves the run when done. Every job but the first keeps the results the earlier ones reported.
func (*App) SaveTestRun ¶
func (*App) ScaleBy ¶
ScaleBy moves each service's replica count by delta (or sets it, when set is true).
func (*App) ScrapeTargets ¶
ScrapeTargets lists the environment's services with metrics as a Prometheus container on the docker runtime's network sees them: containers by name, local processes through host (the container's name for the host, host.docker.internal say).
func (*App) SetAutoscale ¶
SetAutoscale moves the autoscaler bounds of a service.
func (*App) SetEnv ¶
SetEnv sets (an empty value removes) environment variables of services in this environment's state, so every later deploy keeps them, and redeploys the services that run so they take effect.
func (*App) SetRate ¶
SetRate sets a generator's rate within its max, unless force, and records it in the run state.
func (*App) SetResources ¶
SetResources changes one container's requests and limits (which restarts its pods).
func (*App) SharedElsewhere ¶
SharedElsewhere reports whether the service runs in the infra environment rather than this one.
func (*App) Source ¶
Source exports a git ref of the project's repository into the user cache (rig/src/<commit>, once per commit) and returns the directory that corresponds to the project directory inside it.
func (*App) StartInOrder ¶
StartInOrder starts names layer by layer in dependency order, waiting for a layer to be ready before the next: marking a whole chain and starting it never races its own dependencies.
func (*App) StatusAll ¶
StatusAll asks for every named service, in one call per runtime when the runtime can; errors become StateUnknown rows.
func (*App) SuiteNames ¶
SuiteNames are the test suites in rig.yaml's order.
func (*App) TagImage ¶
TagImage is the reference of s's image at tag in this environment's registry.
func (*App) Tasks ¶
Tasks are the project's tasks with this environment's replacing those of the same name.
func (*App) Up ¶
Up builds (when asked) and deploys targets layer by layer in dependency order, waiting for each layer to be ready before the next starts. Dependencies pulled in by the targets, and infrastructure when no target is given, are only started when not already running, never redeployed.
func (*App) UseNamespace ¶
UseNamespace makes ns this environment's namespace from now on; "" goes back to rig.yaml's.
func (*App) VarValues ¶
VarValues are the choices of a dashboard variable: its fixed values, or the values of its label over the series its query returns now.
type Bench ¶
type Bench struct {
Package string `json:"package"`
Name string `json:"name"`
Procs int `json:"procs,omitempty"`
N int64 `json:"n"`
Metrics map[string]float64 `json:"metrics"` // ns/op, B/op, allocs/op, MB/s and custom units
}
Bench is one benchmark result line.
type Firing ¶
Firing is one alert over a threshold, on one subject (a node, a queue, a row of its query).
type LoadLimits ¶
type ReportResult ¶
type ReportResult struct {
Name string `json:"name"`
Env string `json:"env"`
From time.Time `json:"from"`
To time.Time `json:"to"`
Stats []string `json:"stats"`
Rows []ReportRow `json:"rows"`
}
ReportResult is a reports: entry measured over one window.
func (*ReportResult) Markdown ¶
func (r *ReportResult) Markdown(w io.Writer)
Markdown writes the report as a table, one row per series.
type ReportRow ¶
type ReportRow struct {
Metric string `json:"metric"`
Series string `json:"series,omitempty"`
Unit string `json:"unit,omitempty"`
Values map[string]float64 `json:"values"`
Err string `json:"err,omitempty"`
}
ReportRow is one series of one metric, summarised.
type ScrapeTarget ¶
type ScrapeTarget struct {
Targets []string `json:"targets"`
Labels map[string]string `json:"labels"`
}
ScrapeTarget is one entry of a Prometheus file_sd file.
type TestCase ¶
type TestCase struct {
Package string `json:"package"`
Name string `json:"name,omitempty"`
Status string `json:"status"`
Elapsed float64 `json:"elapsed,omitempty"`
Parallel bool `json:"parallel,omitempty"`
Started time.Time `json:"started"`
Output []string `json:"output,omitempty"`
}
TestCase is one package (Name "") or test as go test -json reported it.
type TestJob ¶
type TestJob struct {
Options TestOptions
}
TestJob is one go test invocation of a run: these options, perhaps narrowed to some tests.
func RerunFailed ¶
func RerunFailed(r *TestRun, base TestOptions) []TestJob
RerunFailed are the jobs that run a run's failures again. Each failed test is cut back to its deepest parallel ancestor (a case that stands on its own, like one mode of an integration case), else to its top-level test, so the steps before it run too; tests cut to the same depth share a job.
type TestOptions ¶
type TestOptions struct {
Packages []string `json:"packages,omitempty"`
Run string `json:"run,omitempty"`
Skip string `json:"skip,omitempty"`
Race bool `json:"race,omitempty"`
Cover bool `json:"cover,omitempty"`
Short bool `json:"short,omitempty"`
Failfast bool `json:"failfast,omitempty"`
Shuffle bool `json:"shuffle,omitempty"`
Count int `json:"count,omitempty"`
Parallel int `json:"parallel,omitempty"`
CPU string `json:"cpu,omitempty"`
Timeout time.Duration `json:"timeout,omitempty"`
Bench string `json:"bench,omitempty"`
Benchtime string `json:"benchtime,omitempty"`
Benchmem bool `json:"benchmem,omitempty"`
}
TestOptions are the go test flags of one run; Suite fills them from rig.yaml and the caller changes them.
func Only ¶
func Only(base TestOptions, pkg string, names ...string) TestOptions
Only narrows options to these tests of one package.
func OptionsFor ¶
func OptionsFor(s *spec.TestSuite) TestOptions
OptionsFor is what a suite runs with unless changed.
type TestRun ¶
type TestRun struct {
ID string `json:"id"`
Suite string `json:"suite"`
Env string `json:"env"`
Options TestOptions `json:"options"`
Commands [][]string `json:"commands"`
Started time.Time `json:"started"`
Ended time.Time `json:"ended"`
Err string `json:"err,omitempty"`
Tests []*TestCase `json:"tests"`
Benches []Bench `json:"benches,omitempty"`
Coverage map[string]float64 `json:"coverage,omitempty"`
// Stderr is what go test printed outside its JSON: build errors, mostly.
Stderr []string `json:"stderr,omitempty"`
// Metrics is the suite's report: measured over the run.
Metrics *ReportResult `json:"metrics,omitempty"`
// contains filtered or unexported fields
}
TestRun is one go test invocation (or several, for a rerun of failures at different depths) and everything it reported. It is safe to read with Read while the run goes on.
func (*TestRun) FailedPackages ¶
FailedPackages are packages that failed on their own (a build failure, a panic in TestMain), not through a failed test.
func (*TestRun) WriteJUnit ¶
WriteJUnit writes the run as JUnit XML (one testsuite per package), for CI.
type UpOptions ¶
type UpOptions struct {
Build bool
// Tag names the images: what builds produce, or without Build, the tag to deploy from the registry.
Tag string
// Ref builds from a git ref (branch, tag, commit) instead of the working tree.
Ref string
NoDeps bool
Wait time.Duration
// Settle is how long up watches what it deployed after the last phase: a service that turned
// ready and then crashed (a missing config key, say) fails the up instead of passing silently.
Settle time.Duration
// DryRun prints the phases and what each service would get, changing nothing.
DryRun bool
Out io.Writer
}