terms

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package terms parses a compact one-line chaos rule DSL into engine.RuleSpec / engine.Rule. It is the terse text form behind env-var and HTTP activation; because it decodes to RuleSpec, every parsed rule reuses engine.BuildRule validation and the engine.LintSpecs blast-radius check.

Grammar (v1 — single term per rule):

ruleset  = rule { ";" rule }
rule     = [ name ":" ] [ selector { "," selector } "=" ] term
selector = "kind(" KIND ")" | "name(" GLOB ")" | "attr(" key "=" value ")"
term     = [ mode ] action [ "(" args ")" ]
mode     = INT "*"   (-> engine.Times)  |  FLOAT "%"  (-> engine.Probability, seed 0)
action   = latency | jitter | error | panic | conndrop | off

Action mapping:

latency(200ms)        -> fault.Latency(200ms)
jitter(10ms,200ms)    -> fault.Jittered(10ms,200ms)
error("boom")         -> fault.Error(errors.New("boom"))
panic("kaboom")       -> fault.Panic("kaboom")
conndrop              -> fault.ConnDrop()
off                   -> rule present but inert (no faults)

Example:

rules, err := terms.Compile(`flaky: kind(http_client),name(/users/*)=2*latency(200ms)`)

Note for gofail users: there is no return(v). chaotic injects faults, it does not substitute return values, so gofail's return is renamed error here.

Limits: the DSL emits only the serializable RuleSpec subset — no MatchPredicate and no typed errors.

Staged faults: "term -> term -> ..." compiles to engine.WithStages. A leading "N*" sets a stage's match count; the final stage may omit the count to fire forever, e.g. 2*latency(200ms)->error("boom").

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(s string) ([]engine.Rule, error)

Compile is Parse followed by engine.BuildRule for each spec — the convenience path when you want rules to AddRule directly. Validation (unknown kinds, bad durations, out-of-range probabilities) is performed by BuildRule, so a structurally valid terms string can still fail here with a clear error.

Example
package main

import (
	"fmt"

	"github.com/RomanAgaltsev/chaotic/source/terms"
)

func main() {
	rules, err := terms.Compile(`flaky: kind(http_client),name(/users/*)=2*latency(200ms)`)
	if err != nil {
		panic(err)
	}
	fmt.Println(len(rules), rules[0].Name())
}
Output:
1 flaky

func Parse

func Parse(s string) ([]engine.RuleSpec, error)

Parse turns a terms string into RuleSpecs (the declarative form), so the same BuildRule validation and the LintSpecs blast-radius check apply. Rules are separated by ';'. See the package doc for the grammar.

Types

This section is empty.

Jump to

Keyboard shortcuts

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