Documentation
¶
Overview ¶
Package experiment implements `experiment get`, `apply` and `run`.
Experiment designs pass through as documents rather than generated structs: decoding a file into typed Go values and encoding it again would drop fields the spec does not know yet and rewrite zero values, silently changing files kept in Git. The generated client still types every path, parameter and the smaller request bodies.
Index ¶
- Variables
- func Apply(ctx context.Context, c *platform.Client, o ApplyOptions) error
- func ApplyTemplate(ctx context.Context, c *platform.Client, key string, o TemplateOptions) error
- func Delete(ctx context.Context, c *platform.Client, key string) error
- func Dump(ctx context.Context, c *platform.Client, o DumpOptions) error
- func Get(ctx context.Context, c *platform.Client, o GetOptions) error
- func Init(ctx context.Context, c *platform.Client, o InitOptions) error
- func ResolveFiles(paths []string, recursive bool) ([]string, error)
- func ResolvePlaceholders(o TemplateOptions) ([]api.ExperimentTemplatePlaceholderValueAO, error)
- func Run(ctx context.Context, c *platform.Client, o RunOptions) error
- func WriteGitHubSummary(runs []*RunResult) error
- func WriteReport(file string, runs []*RunResult) error
- type ApplyOptions
- type Document
- type DumpOptions
- type GetOptions
- type InitOptions
- type RunOptions
- type RunResult
- type Step
- type TemplateOptions
- type WaitOptions
Constants ¶
This section is empty.
Variables ¶
var ErrIncomplete = fmt.Errorf("incomplete dump")
ErrIncomplete makes the command exit non-zero after everything that could be fetched has been written, so that a pipeline does not mistake a partial dump for a full one.
var ErrTimedOut = errors.New("timed out")
ErrTimedOut is returned when --timeout cancelled the run.
var ErrUnexpected = errors.New("the run did not end as expected")
ErrUnexpected marks a run that did not end as expected, by --expect-state and --expect-reason or by completing, which --expectation-retries runs again.
var Interactive = func() bool { return term.IsTerminal(int(os.Stdin.Fd())) }
Interactive reports whether questions can be asked. Tests replace it.
var PollInterval = 5 * time.Second
PollInterval is how often --wait asks for the state of a run. Tests shorten it.
var StartCheckDelay = 2 * time.Second
StartCheckDelay is how long --no-wait gives a run before first looking at it. The platform accepts a run and may cancel it moments later, when its validation finds another experiment running; unchecked, a pipeline would pass on a run that never ran.
var StartCheckTimeout = 15 * time.Second
StartCheckTimeout bounds the whole check, requests and the client's back-off included: --no-wait promises not to wait for the run, so a slow platform only earns a warning.
Functions ¶
func ApplyTemplate ¶
ApplyTemplate creates an experiment from a template, or updates the one with key.
func Init ¶
Init walks through creating an experiment from a template: which template, its placeholders, the team and environment. It creates the experiment and writes it to a file, ready for `run -f` and for Git.
func ResolveFiles ¶
ResolveFiles expands directories into their YAML files, recursively on request.
func ResolvePlaceholders ¶
func ResolvePlaceholders(o TemplateOptions) ([]api.ExperimentTemplatePlaceholderValueAO, error)
ResolvePlaceholders reads the placeholders file, a map of key to value or the platform's list of {key, value}, and applies -p values on top, so that a pipeline can keep shared values in a file and override one per stage.
func WriteGitHubSummary ¶
WriteGitHubSummary appends a Markdown summary of the runs to the job summary when the CLI runs in GitHub Actions, which names the file in GITHUB_STEP_SUMMARY.
func WriteReport ¶
WriteReport writes the runs as JUnit XML, which CI systems show as test results, or as JSON, chosen by the file's extension.
Types ¶
type ApplyOptions ¶
type DumpOptions ¶
type GetOptions ¶
type GetOptions struct {
Key, File, Type string
}
type InitOptions ¶
type RunOptions ¶
type RunOptions struct {
Key string
Files []string
Recursive bool
Yes, Wait bool
AllowParallel bool
Retries int
RetryInterval int
// Parallel is how many runs go at once; 0 or 1 runs them one after another.
Parallel int
// BusyRetries tries a run again, BusyRetryInterval apart, when another experiment is
// running and running in parallel is not allowed, instead of asking or failing.
BusyRetries int
BusyRetryInterval time.Duration
// ExpectationRetries runs an experiment again, ExpectationRetryInterval apart, when
// its run did not end as expected.
ExpectationRetries int
ExpectationRetryInterval time.Duration
WaitOptions
// Report is a file to write a JUnit (or, for .json, JSON) report of the runs to.
Report string
TemplateOptions
}
type RunResult ¶
type RunResult struct {
ID int64 `json:"id"`
Key string `json:"key"`
Name string `json:"name"`
State string `json:"state"`
Reason string `json:"reason,omitempty"`
Started time.Time `json:"started"`
Ended time.Time `json:"ended"`
UILocation string `json:"uiLocation,omitempty"`
// APILocation is where the platform's API serves the run, as run-experiment's
// executionUrl output names it.
APILocation string `json:"apiLocation,omitempty"`
Steps []Step `json:"steps"`
}
RunResult is a finished (or abandoned) experiment run, as reports describe it.
type Step ¶
type TemplateOptions ¶
type WaitOptions ¶
type WaitOptions struct {
// Timeout cancels the run once it has taken this long; zero waits indefinitely.
Timeout time.Duration
// KeepRunningOnInterrupt leaves the run going when the CLI is interrupted, as the
// TypeScript CLI did. By default it is cancelled: an aborted pipeline should not
// leave an attack running on its own.
KeepRunningOnInterrupt bool
// ShowSteps prints each step's state as it changes.
ShowSteps bool
// Prefix starts each line about the run, telling runs apart when several go at once.
Prefix string
// ExpectState passes the run once it reaches this state, which need not be an end
// such as RUNNING, and fails it when it ends in another. A run that ended passes a
// state it went through without a poll seeing it. Empty expects COMPLETED.
ExpectState string
// ExpectReason also requires the run's reason to be exactly this.
ExpectReason string
// Steps asks the platform for the steps of the run, which reports need.
Steps bool
}
WaitOptions shape what `run --wait` does besides waiting.