Documentation
¶
Overview ¶
Package hooklane runs a package's runtime and synchronization hooks in lanes: one lane per hook queue of the package, a FIFO with one goroutine, so the hooks of one queue run one at a time in event order and the queues run in parallel, beside the package's operations. The lanes of a package live from Start to its stop, which Current (or Global) calls; the Router (Serve) delivers the events of shell-operator's shared managers to them and never creates one. Waiting runs of one hook coalesce into one run with all their contexts, and a hook's executionMinInterval holds its runs meanwhile; a failed head blocks its lane until its retry.
Index ¶
- type Dump
- type FailureDump
- type InFlight
- type Kind
- type LaneDump
- type LaneSummary
- type Lanes
- type Object
- type Router
- func (r *Router) Dump(name string) Dump
- func (r *Router) RouteKubeEvent(ctx context.Context, kubeEvent kemtypes.KubeEvent)
- func (r *Router) RouteSchedule(ctx context.Context, crontab string)
- func (r *Router) Samples() []Sample
- func (r *Router) Serve(done <-chan struct{}, kube <-chan kemtypes.KubeEvent, schedule <-chan string)
- func (r *Router) Start(ctx, parent context.Context, pkg Object, changed func()) (func(), error)
- func (r *Router) Summary(name string) []LaneSummary
- type Sample
- type State
- type Stats
- type Waiting
- type WaitingItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FailureDump ¶
type FailureDump struct {
Hook string `json:"hook"`
Error string `json:"error"`
Attempts int `json:"attempts"`
NextRetry string `json:"nextRetry"` // NextRetry is the time until the retry; negative when due.
}
FailureDump is the head's failure while it waits for its retry.
type InFlight ¶
type InFlight struct {
Hook string `json:"hook"`
Kind Kind `json:"kind"`
Bindings []string `json:"bindings"`
Batch int `json:"batch"` // Batch is the number of binding contexts of the run.
StartedAt string `json:"startedAt"`
RunningFor string `json:"runningFor"`
}
InFlight is the item the lane runs now.
type LaneDump ¶
type LaneDump struct {
State State `json:"state"`
InFlight *InFlight `json:"inFlight,omitempty"`
Waiting Waiting `json:"waiting"`
Failure *FailureDump `json:"failure,omitempty"`
Stats Stats `json:"stats"`
}
LaneDump is the state of one lane.
type LaneSummary ¶
type LaneSummary struct {
Queue string `json:"queue"`
State State `json:"state"`
Waiting int `json:"waiting"`
Failure string `json:"failure,omitempty"` // Failure is the failed head's error.
}
LaneSummary is one lane in short, for the package dump.
type Lanes ¶
type Lanes struct {
// contains filtered or unexported fields
}
Lanes are the started lanes of one package, by queue.
func (*Lanes) Stop ¶
func (l *Lanes) Stop()
Stop ends the hooks; idempotent, so also a Start's own failure can call it:
- unregister from the router, so no event is routed any more;
- close every lane, dropping what waits in it;
- cancel the lifetime;
- wait for every lane's goroutine, with no bound: a hook in flight returns before its controller is cleared (a warning every stopWarnPeriod names it);
- disable the bindings and drop the controllers;
- reset the observed hook failure, which nothing records any more.
type Object ¶
type Object interface {
GetName() string
GetValuesChecksum() string
// InitializeHooks creates the hook controllers and binds them to events.
InitializeHooks()
// DisableHooks stops the bindings and drops the controllers; called once every lane exited.
DisableHooks()
GetHooksByBinding(binding shtypes.BindingType) []hooks.ControllableHook
// GetHooksQueues are the queues of the schedule and Kubernetes bindings: one lane each.
GetHooksQueues() []string
RunHookByName(ctx context.Context, hook string, bctx []bctx.BindingContext) error
// UnlockKubernetesMonitors lets the events of monitors flow after their synchronization.
UnlockKubernetesMonitors(hook string, monitors ...string)
}
Object is a package's hooks as the lanes run them: an application, a module or the global module.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router starts the lanes of packages and of Global and delivers the events of shell-operator's shared kube events and schedule managers to them (Serve reads them); one per engine. Start registers a package's lanes and their stop unregisters them first, so an entry never outlives its lanes, and a delivery that races the stop finds the lane closed. Safe for concurrent use.
func NewRouter ¶
func NewRouter(pauser pauser, failures failureRecorder, clock retry.Clock, logger *log.Logger) *Router
NewRouter returns an empty Router; clock nil means the wall clock.
func (*Router) RouteKubeEvent ¶
RouteKubeEvent delivers kubeEvent to the lane of every Kubernetes binding that handles it, as one item per binding execution. Never blocks on a hook.
func (*Router) RouteSchedule ¶
RouteSchedule delivers a crontab tick to the lane of every schedule binding on that crontab.
func (*Router) Serve ¶
func (r *Router) Serve(done <-chan struct{}, kube <-chan kemtypes.KubeEvent, schedule <-chan string)
Serve reads the kube events and schedule managers' channels and delivers every event to the lanes until done is closed. One goroutine serves every package and Global, so event intake is serial; it stays short because a delivery only appends to a lane and never waits for a hook. The managers send without a timeout and a run in flight may be one of them (a synchronization's unlock flushes its buffered events, a binding action recreates a monitor): Serve must run until every lane has stopped, so the engine closes done only after the core's shutdown and the managers' stop. The schedule manager's channel is drained only here, so Serve starts before it.
Routing needs no cancellation: matching an event builds its binding contexts and reads no cache, so the routes get a background context.
func (*Router) Start ¶
Start starts the hooks of pkg and returns the stop that ends them:
- initialize the hook controllers;
- start one lane per hook queue and register them with the router;
- enable the Kubernetes bindings, one hook after another as addon-operator does, and put one synchronization item per binding into its hook's lane in hook order, the bindings that wait for it first;
- enable the schedule bindings;
- wait for the synchronization of the bindings that wait for it, bounded by ctx.
The lanes live under a child of parent, not of ctx: a binding that does not wait is synchronized after Start returned. changed is called whenever a hook changed the values checksum; it must not block. On an error Start stops what it started; the caller gets no stop.
func (*Router) Summary ¶
func (r *Router) Summary(name string) []LaneSummary
Summary returns name's lanes in short, by queue; nil while its hooks are not started.
type Sample ¶
type Sample struct {
Package string
Lane string
State State
Length int // Length is the items in the lane, the one in flight included.
}
Sample is one lane in the numbers the lane metrics publish.
type State ¶
type State string
State is what a lane is doing.
const ( StateIdle State = "idle" // StateIdle: nothing waits. StateRunning State = "running" // StateRunning: the head runs. StateRetrying State = "retrying" // StateRetrying: the head failed and waits for its retry. // StateThrottled: the head's hook ran as often as its executionMinInterval allows; it waits, // and what arrives for it meanwhile joins it. StateThrottled State = "throttled" StateStopping State = "stopping" // StateStopping: closed; the run in flight, if any, ends it. )
type Stats ¶
type Stats struct {
Runs int `json:"runs"`
Failures int `json:"failures"`
LastSuccess time.Time `json:"lastSuccess,omitzero"`
// AllowedFailures are failures of items that allow them (allowFailure): recorded here, then
// the item left the lane.
AllowedFailures int `json:"allowedFailures,omitempty"`
LastAllowedFailure string `json:"lastAllowedFailure,omitempty"`
}
Stats count since the lane started.
type Waiting ¶
type Waiting struct {
Count int `json:"count"`
ByHook map[string]int `json:"byHook,omitempty"`
OldestAge string `json:"oldestAge,omitempty"`
Items []WaitingItem `json:"items,omitempty"` // Items are the first dumpItems.
}
Waiting are the items behind the one in flight (the failed head included while it waits).