Documentation
¶
Overview ¶
Package supervise starts the engines as child processes, checks them against versions.json, waits for their health endpoints, restarts them when they crash and stops them on shutdown.
Index ¶
- Constants
- Variables
- func GoMemLimitEnv(limit int64, share float64) []string
- func LoadVersions(path string) (map[string]EngineVersion, error)
- func MemoryLimit(read func(string) ([]byte, error)) int64
- func VerifyBinary(bin string, want EngineVersion) error
- type Credentials
- type Engine
- type EngineStatus
- type EngineVersion
- type Options
- type Supervisor
Constants ¶
const BifrostAdminUser = "remora"
BifrostAdminUser is the fixed name of the front door's admin account.
const RawLogRetentionDays = 7
RawLogRetentionDays is the retention configured for the request log.
Variables ¶
var ( ErrEngineMissing = errors.New("supervise: engine binary missing") ErrVersionMismatch = errors.New("supervise: engine binary does not match versions.json") ErrUnhealthy = errors.New("supervise: engine did not become healthy") )
Errors returned when an engine binary cannot be verified or started.
MemoryShares split the container's memory limit between the processes: each Go runtime gets its share as a soft limit (GOMEMLIMIT), so it collects garbage harder before the container as a whole is killed. The rest is headroom for the speech adapter, SQLite caches and what the runtimes keep outside their heaps.
Functions ¶
func GoMemLimitEnv ¶ added in v0.2.1
GoMemLimitEnv returns the GOMEMLIMIT entry for a child that gets share of limit, or nil when there is no limit.
func LoadVersions ¶
func LoadVersions(path string) (map[string]EngineVersion, error)
LoadVersions reads versions.json, a JSON object keyed by engine name.
func MemoryLimit ¶ added in v0.2.1
MemoryLimit returns the cgroup v2 memory limit in bytes, read through read, or 0 when there is none: the file is missing or unreadable (no cgroup v2, as on macOS), or holds "max".
func VerifyBinary ¶
func VerifyBinary(bin string, want EngineVersion) error
VerifyBinary checks that bin exists and that its sha256 equals want.SHA256. It returns an error wrapping ErrEngineMissing or ErrVersionMismatch.
Types ¶
type Credentials ¶
type Credentials struct {
BifrostAdminUser string // engine_state bifrost/admin_username, fixed "remora"
BifrostAdminPassword string // engine_state bifrost/admin_password
BifrostEncryptionKey string // engine_state bifrost/encryption_key; never rotated (Bifrost cannot change it)
CLIProxyManagementSecret string // engine_state cliproxyapi/management_secret
CLIProxyAPIKey string // engine_state cliproxyapi/api_key: the client key the front door uses (plan 03)
}
Credentials are the secrets remora shares with its engines. They are generated at first boot and sealed in the store's engine_state table.
func EnsureCredentials ¶
EnsureCredentials returns the engine credentials, generating and storing only the values that are missing. A nonempty value already in the store is never regenerated. The store must have a sealer configured.
type Engine ¶
type Engine struct {
Name string // "bifrost" | "cliproxyapi"
Bin string // path to the binary, checked against versions.json
Args, Env []string // Env is the child's complete environment (exec.Cmd.Env semantics)
HealthURL string // answers 2xx once the engine is ready
}
Engine is one child process to supervise.
func BifrostEngine ¶
func BifrostEngine(cfg config.Config, c Credentials) (Engine, error)
BifrostEngine renders $DATA/bifrost/config.json (0600) and returns the front door's Engine. It renders on every boot: the file is a pure function of cfg and c.
func CLIProxyAPIEngine ¶
func CLIProxyAPIEngine(cfg config.Config, c Credentials, providerStrategies map[string]string) (Engine, error)
CLIProxyAPIEngine renders $DATA/cliproxyapi/config.yaml (0600) and returns the OAuth engine's Engine. It renders on every boot: the engine has no port flag, so its port lives only in this file. The engine rewrites the plaintext secret-key as a bcrypt hash on load; rendering the plaintext again is harmless. providerStrategies is accounts.EngineStrategies of the stored strategies.
type EngineStatus ¶
type EngineStatus struct {
Name string `json:"name"`
Version string `json:"version"`
Up bool `json:"up"`
Restarts int `json:"restarts"`
}
EngineStatus is a snapshot of one supervised engine.
type EngineVersion ¶
type EngineVersion struct {
Version string `json:"version"` // the release tag, e.g. "transports/v2.3.0"
SHA256 string `json:"sha256"` // hex of the binary built into the image
}
EngineVersion is one entry of versions.json: the release an engine binary was built from and its checksum.
type Options ¶
type Options struct {
HealthTimeout time.Duration // 120s: Bifrost's first boot runs its migrations
HealthInterval time.Duration // 10s between running health checks; startup interval is capped at 250ms
StopTimeout time.Duration // 15s, then SIGKILL
BackoffMin time.Duration // 1s
BackoffMax time.Duration // 30s
StableAfter time.Duration // 60s healthy resets the backoff
}
Options tunes the supervisor. Zero fields take the defaults noted on each field.
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor runs engines as child processes. Create it with New.
func New ¶
func New(logger *slog.Logger, versions map[string]EngineVersion, opts Options) *Supervisor
New returns a Supervisor that checks engines against versions. Zero fields of opts take their defaults.
func (*Supervisor) Start ¶
func (s *Supervisor) Start(ctx context.Context, engines ...Engine) error
Start verifies every engine against versions.json, then launches them in order, each after the previous one is healthy. It returns once all are healthy. On failure, or when ctx is canceled, it stops every child it started. After Start succeeds, an engine that exits or stops passing health checks is restarted with exponential backoff until Stop.
func (*Supervisor) Status ¶
func (s *Supervisor) Status() []EngineStatus
Status returns a snapshot of every engine, in start order.