hooklane

package
v1.78.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dump

type Dump struct {
	Lanes map[string]map[string]LaneDump `json:"lanes"`
}

Dump is the state of the lanes, by package name and queue.

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 Kind

type Kind string

Kind is what brought an item into its lane.

const (
	KindEvent    Kind = "Event"    // KindEvent is a Kubernetes event of a binding.
	KindSchedule Kind = "Schedule" // KindSchedule is a crontab tick.
	KindSync     Kind = "Sync"     // KindSync is a binding's synchronization at Start.
)

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:

  1. unregister from the router, so no event is routed any more;
  2. close every lane, dropping what waits in it;
  3. cancel the lifetime;
  4. 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);
  5. disable the bindings and drop the controllers;
  6. 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) Dump

func (r *Router) Dump(name string) Dump

Dump returns the state of every package's lanes, or of name's when it is set.

func (*Router) RouteKubeEvent

func (r *Router) RouteKubeEvent(ctx context.Context, kubeEvent kemtypes.KubeEvent)

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

func (r *Router) RouteSchedule(ctx context.Context, crontab string)

RouteSchedule delivers a crontab tick to the lane of every schedule binding on that crontab.

func (*Router) Samples

func (r *Router) Samples() []Sample

Samples returns one sample per lane of every package.

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

func (r *Router) Start(ctx, parent context.Context, pkg Object, changed func()) (func(), error)

Start starts the hooks of pkg and returns the stop that ends them:

  1. initialize the hook controllers;
  2. start one lane per hook queue and register them with the router;
  3. 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;
  4. enable the schedule bindings;
  5. 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.
)

func States

func States() []State

States lists every state a lane can be in.

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).

type WaitingItem

type WaitingItem struct {
	Hook     string `json:"hook"`
	Kind     Kind   `json:"kind"`
	Contexts int    `json:"contexts"`
	Age      string `json:"age"`
}

WaitingItem is one waiting item.

Jump to

Keyboard shortcuts

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