Documentation
¶
Overview ¶
Package engine decides what a durable run does next, as pure functions of the run's status, its pinned revision and the time.
The run controller reads a ProcedureRun, asks Next for the one external thing the run needs (a call, an observation, or nothing), makes it, and folds the answer back with ApplyCall or ApplyObservation. Each returns the run's next status, with the history rows it commits appended to the status's pending history and numbered after the last one. The controller writes that status, and only then appends the rows: the history holds exactly the transitions a run committed.
Nothing here calls a tool, reads a clock or touches the API server, so a restart, a new leader or an upgraded build that reads the same status decides the same thing.
Semantics ¶
Entering a state runs its steps in order. A call step is made once per attempt of the state; its answer is kept by step id and is what later expressions read. A waitUntil step begins a wait whose deadline is fixed when it begins; each observation that changes is recorded, and once the condition holds the run goes on. An observation made at or after the deadline that still doesn't satisfy the condition acts on atDeadline. Once a state's steps are done, the first transition whose condition holds fires: to another state, or the end of the run with an outcome.
Index ¶
- Constants
- Variables
- func ApplyAdmission(rev *Revision, run Run, action Action, grant api.QueueLease, now time.Time) api.ProcedureRunStatus
- func ApplyCall(rev *Revision, run Run, action Action, out CallOutcome, now time.Time) musterv1alpha1.ProcedureRunStatus
- func ApplyHeld(rev *Revision, run Run, action Action, held HeldCall, now time.Time) v1.ProcedureRunStatus
- func ApplyObservation(rev *Revision, run Run, action Action, answer map[string]any, now time.Time) (musterv1alpha1.ProcedureRunStatus, bool)
- func Cancel(rev *Revision, run Run, reason string, now time.Time) v1.ProcedureRunStatus
- func CheckMigration(rev *Revision, open []OpenRun) error
- func ChildCreated(rev *Revision, run Run, a Action, name string, now time.Time) v1.ProcedureRunStatus
- func ChildViews(rev *Revision, run Run, id string, views []any, now time.Time) v1.ProcedureRunStatus
- func ChildrenCancelled(rev *Revision, run Run, now time.Time) v1.ProcedureRunStatus
- func DefinitionReason(err error) string
- func ExpireSources(rev *Revision, run Run, actions []Action, now time.Time) (v1.ProcedureRunStatus, bool)
- func ExpressionBug(rev *Revision, run Run, err error, now time.Time) v1.ProcedureRunStatus
- func FailedObservation(rev *Revision, run Run, a Action, unanswered bool, now time.Time) v1.ProcedureRunStatus
- func FollowRefused(run Run, task string) bool
- func HistoryEntries(runUID, namespace, name, procedure string, ...) []history.Entry
- func InlineWait(rev *Revision, run Run) bool
- func Migrate(old, rev *Revision, run Run, now time.Time) (musterv1alpha1.ProcedureRunStatus, bool)
- func Observed(rev *Revision, run Run, failed, tasksPolled bool, ...) v1.ProcedureRunStatus
- func RefuseRead(rev *Revision, run Run, a Action, reason string, now time.Time) v1.ProcedureRunStatus
- func SampledDeadline(rev *Revision, run Run, a Action, quantile time.Duration, now time.Time) v1.ProcedureRunStatus
- func SettleRun(rev *Revision, run Run, now time.Time) musterv1alpha1.ProcedureRunStatus
- func SharedDeadline(rev *Revision, run Run, now time.Time) v1.ProcedureRunStatus
- func Signal(run Run, name string, value any, now time.Time) (v1.ProcedureRunStatus, error)
- func SourceReading(rev *Revision, run Run, a Action, answer map[string]any, now time.Time) v1.ProcedureRunStatus
- func Start(rev *Revision, run Run, now time.Time) musterv1alpha1.ProcedureRunStatus
- func WaitDependencies(rev *Revision, run Run) (map[string][]string, []string)
- type Action
- func (a Action) AdmissionRequest() (class string, fields map[string]any, inputError string)
- func (a Action) Classify(class call.Class, answer map[string]any, message string) (call.Class, string)
- func (a Action) IsAsk() bool
- func (a Action) IsStart() bool
- func (a Action) PollCap() time.Duration
- func (a Action) QueryKey() string
- func (a Action) ReadsInline(rev *Revision, condition string) bool
- func (a Action) SampleQuantile() float64
- func (a Action) Shared() bool
- type ActionKind
- type CallOutcome
- type HeldCall
- type OpenRun
- type Revision
- type Run
- type WaitSample
Constants ¶
const ( DryRunWhyUnknownResult = "unknown-result" DryRunWhyStartWouldFollow = "start-would-follow" DryRunWhyAskWithoutDefault = "ask-without-default" )
Why a dry run stopped before reaching an end transition.
const ( HeldNotReadOnly = "not-read-only" HeldHintNotTrusted = "hint-not-trusted" HeldNotListed = "not-listed" )
Outcomes recorded on held history entries explaining why the call was not executed during a dry run.
const ( StallHeartbeatSilent = "HeartbeatSilent" StallDeadlinePassed = "DeadlinePassed" )
The reasons of the Stalled condition.
const AtDeadlineEscalate = "escalate"
AtDeadlineEscalate moves a run whose deadline passed to its escalate state.
const ConditionStalled = "Stalled"
ConditionStalled is set on a run whose followed task reports a heartbeat older than its step's maxSilence (reason HeartbeatSilent), or whose wait is past its deadline and can't be re-observed (reason DeadlinePassed).
const DeadlineGrace = 5 * time.Minute
DeadlineGrace is how long a wait may stay past its deadline without a successful re-observation before the run is stalled.
const MaxSignalBytes = 4096
MaxSignalBytes is the maximum JSON-encoded value of one named signal.
const OutcomeDryRun = "dryRun"
OutcomeDryRun is the outcome of a dry run that stopped at a call it held.
const ReasonReadOnlyDeclared = "ReadOnlyDeclared"
ReasonReadOnlyDeclared is the DefinitionRefused condition reason when a Procedure step attempts to declare readOnly.
Variables ¶
var ErrRefused = errors.New("definition refused")
ErrRefused is wrapped by Compile's error for a definition that can't run.
Functions ¶
func ApplyAdmission ¶
func ApplyAdmission(rev *Revision, run Run, action Action, grant api.QueueLease, now time.Time) api.ProcedureRunStatus
ApplyAdmission checkpoints a grant, or a release, with its history row and advances past the step. A repeated admit in continuing work keeps the original lease.
func ApplyCall ¶
func ApplyCall(rev *Revision, run Run, action Action, out CallOutcome, now time.Time) musterv1alpha1.ProcedureRunStatus
ApplyCall folds the outcome of action, a Call, into the run. An answered call advances the step. A refusal holds its arguments and a bug parks the run. Transient failures leave the checkpoint available for another try.
func ApplyHeld ¶
func ApplyHeld(rev *Revision, run Run, action Action, held HeldCall, now time.Time) v1.ProcedureRunStatus
ApplyHeld folds a call a dry run held into the run: the call is recorded as held with its server, catalogue status, MCP hints and observation versions. An ensure remembers its evaluated arguments and continues. A call with a dryRun expression continues with its assumed result; one without leaves its result unknown until something reads it. An ask with a default takes its default immediately; an ask without a default or a start the run would follow ends the run dryRun at that step.
func ApplyObservation ¶
func ApplyObservation(rev *Revision, run Run, action Action, answer map[string]any, now time.Time) (musterv1alpha1.ProcedureRunStatus, bool)
ApplyObservation folds an answer to action, an Observe, made at now, into the run. It reports whether the status changed: an answer equal to the last one, before the deadline and without the condition holding, changes nothing, so an idle wait writes nothing.
func CheckMigration ¶
CheckMigration returns why rev can't be accepted with these open runs, or nil. A revision that maps an older generation must map every state an open run of that generation is in; it is refused as a whole otherwise, so no run moves and no run is stranded in a state the mapping forgot. Runs of generations the revision doesn't map stay on their revision.
func ChildCreated ¶
func ChildCreated(rev *Revision, run Run, a Action, name string, now time.Time) v1.ProcedureRunStatus
ChildCreated checkpoints a child only after Kubernetes confirms its identity.
func ChildViews ¶
func ChildViews(rev *Revision, run Run, id string, views []any, now time.Time) v1.ProcedureRunStatus
ChildViews updates the ordered results of a fan-out when a child changes.
func ChildrenCancelled ¶
ChildrenCancelled releases the parent's child list after cancellation was requested.
func DefinitionReason ¶
DefinitionReason is the condition reason for a refused revision.
func ExpireSources ¶
func ExpireSources(rev *Revision, run Run, actions []Action, now time.Time) (v1.ProcedureRunStatus, bool)
ExpireSources drops answers whose evaluated arguments changed, including when an input became unknown. Persist this before making dependent reads.
func ExpressionBug ¶
ExpressionBug parks the run on a source argument error.
func FailedObservation ¶
func FailedObservation(rev *Revision, run Run, a Action, unanswered bool, now time.Time) v1.ProcedureRunStatus
FailedObservation records a failed poll of a wait's own observe tool.
func FollowRefused ¶
FollowRefused reports whether the run recorded the follow of its task as refused. Such a follow is not read again, so a wait that depends on it can't be observed.
func HistoryEntries ¶
func HistoryEntries(runUID, namespace, name, procedure string, st musterv1alpha1.ProcedureRunStatus) []history.Entry
HistoryEntries converts a status's pending rows into history entries of the run.
func InlineWait ¶
InlineWait reports whether the current wait polls its own tool or decision.
func Migrate ¶
func Migrate(old, rev *Revision, run Run, now time.Time) (musterv1alpha1.ProcedureRunStatus, bool)
Migrate moves a run pinned to old onto rev, when rev maps old's generation, and reports whether it moved. The run goes on in the state the mapping names. Where the new state begins with the same steps as the old one up to where the run is, it keeps its place, attempt and wait, so no call is made again; otherwise it starts the new state from its first step as a new attempt.
func Observed ¶
func Observed(rev *Revision, run Run, failed, tasksPolled bool, taskAnswers map[string]time.Time, now time.Time) v1.ProcedureRunStatus
Observed applies a refresh of the named sources and followed tasks: a failed dependency marks the wait unobserved. Task heartbeat age is measured at the time its own poll answered.
func RefuseRead ¶
func RefuseRead(rev *Revision, run Run, a Action, reason string, now time.Time) v1.ProcedureRunStatus
RefuseRead records that the follow of a task or the answer to a question was refused, with the reason. Like a refused call, the read is not made again until its arguments change.
func SampledDeadline ¶
func SampledDeadline(rev *Revision, run Run, a Action, quantile time.Duration, now time.Time) v1.ProcedureRunStatus
SampledDeadline fixes the deadline of a wait estimated from earlier runs: times the quantile of their durations, at least its atLeast.
func SettleRun ¶
func SettleRun(rev *Revision, run Run, now time.Time) musterv1alpha1.ProcedureRunStatus
SettleRun moves a status that sits between steps on to its next step or transition.
func SharedDeadline ¶
SharedDeadline handles a wait on named sources after their final successful reads.
func Signal ¶
Signal records the latest value and the history row in one checkpoint. The caller persists it with the run's resource version.
func SourceReading ¶
func SourceReading(rev *Revision, run Run, a Action, answer map[string]any, now time.Time) v1.ProcedureRunStatus
SourceReading folds a changed reading into the checkpoint.
func Start ¶
func Start(rev *Revision, run Run, now time.Time) musterv1alpha1.ProcedureRunStatus
Start pins rev on a run that has no status yet and enters the start state.
Types ¶
type Action ¶
type Action struct {
// HoldDeadline keeps a deadline action pending while another source it reads is unobserved.
HoldDeadline bool
// Principal is the subject of the reading being applied, empty for muster.
Principal string
// ChildKey identifies one child across retries, independent of its object name.
ChildKey string
Timeout time.Duration
Kind ActionKind
State string
// Step is the step's id, or "#<n>" for one without.
Step string
Attempt int
// Tool is the call's or observation's tool, as <MCPServer>.<tool>.
Tool string
// Args are the evaluated arguments.
Args map[string]any
// Key is a call's idempotency key.
Key string
// Deadline is when an observed wait's deadline passes.
Deadline time.Time
// Queue is the Queue an Admit or a Release names.
Queue string
// Implicit marks the admission a triggered run waits for before its
// first step, which is no step of the revision.
Implicit bool
// InputError says why an Admit's fields can't be rendered yet.
InputError string
// contains filtered or unexported fields
}
Action is the one external thing a run needs next.
func Next ¶
Next returns what the run needs next. It errs only for a status that doesn't fit the revision, such as a state the revision doesn't have.
func (Action) AdmissionRequest ¶
AdmissionRequest returns the class and fields an Admit asks for, or why it has none yet.
func (Action) Classify ¶
func (a Action) Classify(class call.Class, answer map[string]any, message string) (call.Class, string)
Classify applies the definition's checked rules to one transport outcome.
func (Action) PollCap ¶
PollCap bounds how long a follow may wait for its next poll: a task's maxSilence, so a silent heartbeat is seen in time. Zero for no bound.
func (Action) ReadsInline ¶
ReadsInline reports whether a named condition uses this step's own observation, directly or through a let binding.
func (Action) SampleQuantile ¶
SampleQuantile is the quantile of earlier waits a SampleDeadline needs.
type ActionKind ¶
type ActionKind int
ActionKind is the kind of external thing a run needs next.
const ( // None: the run needs nothing; it has ended or is blocked. None ActionKind = iota // Call: make the step's call. Call // Observe: poll the step's observation, now or when it is due. Observe // Settle: the status is between steps (after a migration or a crash // before the next step was reached); Settle moves it on. Settle // Child: start or recover the run step's child by ChildKey. Child // CancelChildren: ask each live child to cancel. CancelChildren // SampleDeadline: fix a wait's deadline from earlier runs' durations, // the SampleQuantile of them, with SampledDeadline. SampleDeadline // Admit: request a lease in Queue with Args {class, fields}, or wait // for it; ApplyAdmission folds the grant in. Admit // Release: return the lease in Queue with ApplyAdmission. Release )
type CallOutcome ¶
type CallOutcome struct {
Class call.Class
// Answer is the tool's answer as an object; nil when it gave none.
Answer map[string]any
// Message is the refusal's or error's text.
Message string
// Principal is the subject the call was made as.
Principal string
// Args are the arguments the call was made with.
Args map[string]any
}
CallOutcome is how a call ended, as ApplyCall folds it in.
type HeldCall ¶
type HeldCall struct {
Server string
Listed bool
Destructive bool
Idempotent bool
Reason string
// Principal is the subject a live run would have made the call as:
// "client:<id>" in a namespace with an organization principal, "" for
// muster itself.
Principal string
}
HeldCall describes why a dry run held a tool call and what the catalogue declared about the tool.
type Revision ¶
type Revision struct {
Name string
ProcedureUID string
Generation int64
Spec musterv1alpha1.ProcedureSpec
// contains filtered or unexported fields
}
Revision is one compiled revision of a Procedure: what a run pinned to it follows.
func Compile ¶
func Compile(name, uid string, generation int64, spec musterv1alpha1.ProcedureSpec) (*Revision, error)
Compile checks a Procedure's spec and compiles its expressions. Its error names where the problem sits, for example "states.WAITING.steps.0.waitUntil: …".
type Run ¶
type Run struct {
// CancelRequest is the reason already present on a run before its first checkpoint.
CancelRequest string
DryRun bool
Namespace string
Input *apiextensionsv1.JSON
// Queue and Fields are a triggered run's admission request: it waits
// in Queue before its first step.
Queue string
Fields *apiextensionsv1.JSON
UID string
Subject string
Status musterv1alpha1.ProcedureRunStatus
}
Run is what the engine reads of a ProcedureRun.
type WaitSample ¶
type WaitSample struct {
Quantile float64 `json:"quantile"`
Times float64 `json:"times"`
AtLeast string `json:"atLeast"`
}
WaitSample estimates a wait's deadline from the successful waits of the same Procedure, namespace, state and step in other runs: Times the nearest-rank Quantile of their durations, and at least AtLeast.