Documentation
¶
Overview ¶
Package eval is the hub's evaluation of the harness (moved from the old gateway so that it can be switched off): on a schedule it queues the golden tasks of a suite for a machine, hands them one at a time to the machine's runner, reads the verdicts back, closes the batches and warns the owner when the smoke suites get worse. The runs are paid from the machine owner's own subscription, so nothing starts for a person whose rollout switch is off, nor when the subscription's windows are filling up, nor when the week's runs already took their share. The tables are those of migration 0062 (docs/hub/eval.md).
Index ¶
- Constants
- Variables
- func LatestSlot(days []int, atMsk string, every int, now time.Time) (time.Time, bool)
- func NextSlot(days []int, atMsk string, every int, now time.Time) (time.Time, bool)
- type Check
- type Deps
- type Gate
- type HubLink
- func (l *HubLink) Connected(machineID string) bool
- func (l *HubLink) Poll(ctx context.Context, machineID string, runIDs []string) (map[string]RunState, error)
- func (l *HubLink) Start(ctx context.Context, machineID string, req RunRequest) error
- func (l *HubLink) Stop(ctx context.Context, machineID, runID string) error
- type Link
- type Linker
- type RunRequest
- type RunState
- type Scheduler
- type Usage
Constants ¶
const SwitchScheduler = "hub-eval"
SwitchScheduler is the rollout switch (docs/hub/rollout-switches.md) that lets the scheduler queue and start runs on the machines of a person. Off for everyone until a row says otherwise.
Variables ¶
var ErrNotDelivered = errors.New("eval: the machine did not get the request")
ErrNotDelivered is what a Link returns when nothing reached the machine (no connection, the hub restarting): the run goes back to the queue. Any other error may come after the runner started, so the run stays claimed and the poll decides.
Functions ¶
func LatestSlot ¶
LatestSlot is the newest slot of the schedule that is not after now; ok is false for a schedule with no slot in the last eight days or one whose newest slot falls in a week it skips (the week after is not looked back at, as before).
Types ¶
type Check ¶
type Check struct {
Name string `json:"name"`
Passed bool `json:"passed"`
ExitCode *int `json:"exitCode"`
Ms int `json:"ms"`
}
Check is the verdict of one check of a run.
type Deps ¶
type Deps struct {
DB *store.DB
Gate Gate
// Link is the way to the machines' runners; nil means the scheduler does nothing.
Link Link
Log *slog.Logger
// Now is the clock; nil means time.Now.
Now func() time.Time
}
Deps are what the scheduler is built from.
type HubLink ¶
type HubLink struct {
Links Linker
// Offers says whether the machine's agent said the feature in its hello.
Offers func(machineID, feature string) bool
}
HubLink is the Link that goes over the hub's links to the machines' agents (hubproto eval.run.*).
func (*HubLink) Connected ¶
Connected: the machine is linked now and its agent serves evaluation runs (the operator opted in there).
func (*HubLink) Poll ¶
func (l *HubLink) Poll(ctx context.Context, machineID string, runIDs []string) (map[string]RunState, error)
Poll asks for the state of the runs; a run the agent does not know is missing from its answer.
type Link ¶
type Link interface {
// Connected says whether the machine can be reached now.
Connected(machineID string) bool
// Start hands one run to the machine's runner.
Start(ctx context.Context, machineID string, req RunRequest) error
// Poll asks for the state of the runs the machine has; a run it does not know is missing from the answer.
Poll(ctx context.Context, machineID string, runIDs []string) (map[string]RunState, error)
// Stop asks the runner to end a run.
Stop(ctx context.Context, machineID, runID string) error
}
Link is the way to a machine's runner. The hub's link to the machine (hub-link) implements it; the scheduler itself does not know how a request travels.
type Linker ¶
type Linker interface {
Get(machineID string) *link.Link
Do(ctx context.Context, machineID, op string, params any, timeout time.Duration) (json.RawMessage, error)
}
Linker reaches a machine over the agent link.
type RunRequest ¶
type RunRequest struct {
RunID string `json:"runId"`
Task json.RawMessage `json:"task"`
Arm json.RawMessage `json:"arm"`
}
RunRequest is what a machine's runner is given to start one run: the task with its hidden checks and limits, and the arm (the way the harness is set up for this run). Both are JSON documents the runner reads.
type RunState ¶
type RunState struct {
RunID string `json:"runId"`
State string `json:"state"` // preparing, running, grading, done, failed, timeout, stopped, skipped
StartedAt string `json:"startedAt"`
FinishedAt string `json:"finishedAt"`
Error string `json:"error"`
Fingerprint string `json:"fingerprint"`
Passed *bool `json:"passed"`
WallS *int `json:"wallS"`
Usage *Usage `json:"usage"`
Checks []Check `json:"checks"`
Diff any `json:"diff"`
}
RunState is the runner's report on one run.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler runs the evaluation. Of the replicas of a hub one does a pass at a time (store.TakeLease).