Documentation
¶
Overview ¶
Package sim models the desk's flow of an issue from its start to its release as the supervisor loop is meant to run it, simulates that model, measures the real flow from the event log and compares the two: where the real system is slower than the model, what the log names as the cause, and which single change would gain the most released issues per day.
The model is deliberately small. An issue is started by a worker when a slot is free; the worker pushes a pull request; CI runs; a reviewer is started once CI is green; the reviewer posts findings and asks for changes; the merge lane merges one pull request at a time; the release rolls out. The loop drives every transition but the worker's and the reviewer's own turns, so while the loop is down nothing starts, nothing is reviewed and nothing merges.
Index ¶
- Constants
- Variables
- func Verbs(verb string) bool
- type BoardItem
- type Checked
- type CheckedItem
- type CheckedProblem
- type Comparison
- type Count
- type FailedMerge
- type Forecast
- type Item
- type ItemForecast
- type LaneState
- type Model
- type Observed
- type ObservedStage
- type Outage
- type ParkedAgent
- type Problem
- type ProviderRoom
- type ProviderUse
- type Quantiles
- type Result
- type Row
- type Snapshot
- type Stage
- type StageResult
- type StartForecast
- type Tally
- type Total
- type Transition
- type WhatIf
Constants ¶
const ( VerdictOnTrack = "on track" VerdictAhead = "ahead" VerdictBehind = "behind" VerdictStuck = "stuck as forecast" VerdictGone = "gone" )
Verdicts of a checked item.
const ( ProblemResolved = "resolved" ProblemStanding = "standing" ProblemUnchecked = "unchecked" )
Outcomes of a checked problem.
const ( AgentBusy = "busy" AgentParked = "parked" AgentIdle = "idle" )
States of an item's agent on the roster.
const ( SeverityStop = "stop" SeveritySlow = "slow" )
const ( StageImplementing = state.DeliveryImplementing StageCI = state.DeliveryCI StageReviewQueued = state.DeliveryReviewQueued StageReviewing = state.DeliveryReviewing StageFixing = state.DeliveryFixing StageMerging = state.DeliveryMerging StageReleasing = state.DeliveryReleasing // StageDecision is an issue parked on its person's answer, which the // delivery steps count inside implementing. StageDecision = "decision" )
Stage names are the delivery steps of state.Delivery, so a model's stage compares with the step the loop records for a real delivery.
const BehindGrace = 10 * time.Minute
BehindGrace is how late an item may run before the check calls it behind: the loop's own pass between two polls.
const DefaultSigma = 0.8
DefaultSigma is the spread of every default stage: the 90th percentile is about 2.8 times the median, as the real steps show.
const LoopGap = 15 * time.Minute
LoopGap is the longest silence of the supervisor loop that still counts as up: the loop logs a claim or a stage on nearly every 30s pass.
const Seeds = 5
Seeds is how many seeds Compare averages the fitted runs over, so that the chance of one run never ranks a change below another.
const StepBoard = "board"
StepBoard is the step of an item still on the board.
Variables ¶
var Stages = []string{StageImplementing, StageCI, StageReviewQueued, StageReviewing, StageFixing, StageMerging, StageReleasing}
Stages lists the steps in flow order.
Functions ¶
Types ¶
type BoardItem ¶
type BoardItem struct {
Ref string `json:"ref"`
Status string `json:"status,omitempty"`
Skip string `json:"skip,omitempty"`
}
BoardItem is a board candidate in the order board next walks them; Skip is the implementation's reason not to start it, "" when free.
type Checked ¶
type Checked struct {
ForecastAt time.Time `json:"forecastAt"`
At time.Time `json:"at"`
Items []CheckedItem `json:"items"`
Forecast Tally `json:"forecast"`
Actual Tally `json:"actual"`
Problems []CheckedProblem `json:"problems,omitempty"`
// Counts the items by verdict (on track, ahead, behind, ...).
Counts map[string]int `json:"counts"`
}
Checked is a forecast against the desk at a later time.
type CheckedItem ¶
type CheckedItem struct {
Ref string `json:"ref"`
// Expected is the step the forecast had the item in at the check,
// Actual the step it is in: done once released, gone when the loop
// no longer records it.
Expected string `json:"expected"`
Actual string `json:"actual"`
Verdict string `json:"verdict"`
// Behind is how long ago the forecast had the item enter the first
// step it has not reached, with the Behind verdict.
Behind time.Duration `json:"behind,omitempty"`
Agent string `json:"agent,omitempty"`
AgentState string `json:"agentState,omitempty"`
Waits string `json:"waits,omitempty"`
}
CheckedItem is one forecast item against the desk now.
type CheckedProblem ¶
type CheckedProblem struct {
Problem
Outcome string `json:"outcome"`
// Moved names the refs that left the step the forecast saw them in,
// Still those that did not.
Moved []string `json:"moved,omitempty"`
Still []string `json:"still,omitempty"`
}
CheckedProblem is a forecast problem against the items it named.
type Comparison ¶
type Comparison struct {
Model Model `json:"model"`
Expected Result `json:"expected"`
Observed Observed `json:"observed"`
// Fitted is the model with the observed stage times, loop uptime,
// drop share and start rate; Baseline its run, which should come
// close to the observed throughput when the model holds.
Fitted Model `json:"fitted"`
Baseline Result `json:"baseline"`
Rows []Row `json:"rows"`
// WhatIfs are the single changes to the fitted model, by gain.
WhatIfs []WhatIf `json:"whatIfs"`
// Findings are the sentences a reader acts on, ranked.
Findings []string `json:"findings"`
}
Comparison is the model against the log: per stage, the loop, the capacity, the throughput and the changes ranked by what they gain.
func Compare ¶
func Compare(m Model, o Observed) Comparison
Compare runs the model, fits it to the observation, runs the fit and every single change back towards the model, and ranks the changes.
type FailedMerge ¶
type FailedMerge struct {
Ref string `json:"ref"`
At time.Time `json:"at"`
Exit int `json:"exit"`
Reason string `json:"reason,omitempty"`
}
FailedMerge is a merge the gate recorded as failed.
type Forecast ¶
type Forecast struct {
At time.Time `json:"at"`
Horizon time.Duration `json:"horizon"`
Model Model `json:"model"`
Snapshot Snapshot `json:"snapshot"`
Items []ItemForecast `json:"items"`
Starts []StartForecast `json:"starts,omitempty"`
Totals []Total `json:"totals"`
Problems []Problem `json:"problems,omitempty"`
}
Forecast is the desk's expected flow over a horizon from a snapshot.
func Forecasting ¶
Forecasting runs the snapshot forward through the model over the horizon: the items in flight from their current steps, the free board items as the slots allow, under the implementation's own verdicts (loop running, room, holds, reviews already requested).
type Item ¶
type Item struct {
Ref string `json:"ref"`
Pulls []string `json:"pulls,omitempty"`
Step string `json:"step"`
Since time.Time `json:"since"`
Agent string `json:"agent,omitempty"`
// AgentState is busy, parked, idle or "" for no agent on the roster.
AgentState string `json:"agentState,omitempty"`
Waits string `json:"waits,omitempty"`
}
Item is one active delivery as the loop records it.
type ItemForecast ¶
type ItemForecast struct {
Ref string `json:"ref"`
Step string `json:"step"`
Since time.Time `json:"since"`
// Timeline is every stage the item is forecast to enter within the
// horizon, done last when it is released.
Timeline []Transition `json:"timeline,omitempty"`
// ReleaseAt is zero while the release lies past the horizon.
ReleaseAt time.Time `json:"releaseAt,omitzero"`
// Stuck says why the item is forecast not to move at all.
Stuck string `json:"stuck,omitempty"`
}
ItemForecast is one item's forecast path.
type LaneState ¶
type LaneState struct {
Lane string `json:"lane"`
Ref string `json:"ref"`
Phase string `json:"phase"`
Since time.Time `json:"since"`
}
LaneState is a merge in a lane.
type Model ¶
type Model struct {
// Stages maps a stage name to its service time. review-queued is the
// time the loop takes to start a reviewer once CI is green, merging the
// gate's own run (devctl pr merge with its merge-result check), and
// releasing the release workflow with the rollout.
Stages map[string]Stage `json:"stages"`
// Workers is the ceiling of busy agents (capacity.ceiling): workers,
// fixers and reviewers share it; reviewers may exceed it by
// ReviewHeadroom (capacity.reviewHeadroom).
Workers int `json:"workers"`
ReviewHeadroom int `json:"reviewHeadroom"`
// Lanes is how many repositories merge in parallel: one merge at a
// time per lane.
Lanes int `json:"lanes"`
// LoopUptime is the share of time the supervisor loop runs, 0 to 1,
// and LoopOutage the mean length of one down period.
LoopUptime float64 `json:"loopUptime"`
LoopOutage time.Duration `json:"loopOutage"`
// RedCI is the chance a CI run is red and goes back to a fixer;
// ChangesRequested the chance a review asks for changes instead of
// fixing on the branch; Dropped the chance a started issue ends
// without a pull request (research, closed unmerged, overlap).
RedCI float64 `json:"redCI"`
ChangesRequested float64 `json:"changesRequested"`
Dropped float64 `json:"dropped"`
// UpdateBranch adds a CI run to every merge, as devctl pr merge
// --update-branch does when the base moved.
UpdateBranch bool `json:"updateBranch"`
// answer once, for the decision stage's service time.
DecisionShare float64 `json:"decisionShare"`
// Backlog is how many issues wait on the board at the start, and
// ArrivalsPerDay how many are filed per day on top. A negative
// backlog never runs out.
Backlog int `json:"backlog"`
ArrivalsPerDay float64 `json:"arrivalsPerDay"`
// Horizon is the simulated time, Seed the random seed.
Horizon time.Duration `json:"horizon"`
Seed int64 `json:"seed"`
}
Model is the flow with its capacities, service times and chances.
func Default ¶
func Default() Model
Default is the intended flow: the loop up, the stage times a worker, a reviewer, CI and the gate take when nothing waits, the chances the week's log shows for red CI and change requests, and no drops.
func Fit ¶
Fit returns m with the observed values: the stages' medians, the loop's uptime, the share of dropped work and the rate at which issues were started, so that a run of it replays the week as the log shows it.
type Observed ¶
type Observed struct {
Outcomes map[string]int `json:"outcomes"`
Since time.Time `json:"since"`
Until time.Time `json:"until"`
Days float64 `json:"days"`
// Stages are the delivery steps' residence times (delivery.step).
Stages []ObservedStage `json:"stages"`
// Deliveries counts the issues observed, Started those whose worker
// started in the window, Released those that reached done in it and
// Dropped those that ended in it without a merge; DropShare is
// Dropped over both.
Deliveries int `json:"deliveries"`
Started int `json:"started"`
Released int `json:"released"`
Dropped int `json:"dropped"`
StartedPerDay float64 `json:"startedPerDay"`
ReleasedPerDay float64 `json:"releasedPerDay"`
// LoopUptime is the share of the window with a supervisor loop event
// at least every LoopGap; Outages are the longest gaps.
LoopUptime float64 `json:"loopUptime"`
LoopDown time.Duration `json:"loopDown"`
Outages []Outage `json:"outages,omitempty"`
// MeanBusy and MeanCeiling are the busy agents and the ceiling across
// the subscription providers, time-weighted from the USAGE lines.
MeanBusy float64 `json:"meanBusy"`
MeanCeiling float64 `json:"meanCeiling"`
Utilization float64 `json:"utilization"`
Providers []ProviderUse `json:"providers,omitempty"`
// Starts count agents.start events by kind.
WorkerStarts int `json:"workerStarts"`
ReviewStarts int `json:"reviewStarts"`
// Failures are the supervisor.failure events by step and reason,
// MergeFailures the merge.failed events by exit code, Parks the
// agents.park events by what they wait on, Rollbacks the release
// rollbacks.
Failures []Count `json:"failures,omitempty"`
MergeFailures []Count `json:"mergeFailures,omitempty"`
Parks []Count `json:"parks,omitempty"`
Rollbacks int `json:"rollbacks"`
// RateLimited counts events that name an exhausted GitHub API limit.
RateLimited int `json:"rateLimited"`
// Lanes counts the merge lanes that saw a merge.
Lanes int `json:"lanes"`
}
Observed is the real flow read from the event log.
type ObservedStage ¶
ObservedStage is a delivery step's residence time over the window.
type ParkedAgent ¶
type ParkedAgent struct {
Name string `json:"name"`
On string `json:"on,omitempty"`
Waits string `json:"waits"`
}
ParkedAgent is an agent kept parked and what it waits on.
type Problem ¶
type Problem struct {
Severity string `json:"severity"`
What string `json:"what"`
Refs []string `json:"refs,omitempty"`
}
Problem is what the snapshot says will not move, or moves too slowly, before any simulation: Stop stops the flow, Slow slows it.
type ProviderRoom ¶
type ProviderRoom struct {
Name string `json:"name"`
Busy int `json:"busy"`
Ceiling int `json:"ceiling"`
Room int `json:"room"`
}
ProviderRoom is a provider's busy agents, ceiling and room now.
type ProviderUse ¶
type ProviderUse struct {
Provider string `json:"provider"`
MeanBusy float64 `json:"meanBusy"`
MeanCeiling float64 `json:"meanCeiling"`
}
ProviderUse is a provider's mean busy agents against its mean ceiling over the window, from the watch's USAGE lines.
type Quantiles ¶
type Quantiles struct {
Count int `json:"count"`
Median time.Duration `json:"median"`
P90 time.Duration `json:"p90"`
Max time.Duration `json:"max"`
}
Quantiles summarise a set of durations.
type Result ¶
type Result struct {
Horizon time.Duration `json:"horizon"`
Started int `json:"started"`
Released int `json:"released"`
Dropped int `json:"dropped"`
Open int `json:"open"`
StartedPerDay float64 `json:"startedPerDay"`
ReleasedPerDay float64 `json:"releasedPerDay"`
// Cycle is the time from a worker's start to the release.
Cycle Quantiles `json:"cycle"`
// BacklogWait is the time an issue waited on the board for a worker.
BacklogWait Quantiles `json:"backlogWait"`
Stages []StageResult `json:"stages"`
// WorkerUtilization is the busy slot time over the slots (Workers plus
// ReviewHeadroom) × Horizon, LaneUtilization the merging time over
// Lanes × Horizon.
WorkerUtilization float64 `json:"workerUtilization"`
LaneUtilization float64 `json:"laneUtilization"`
LoopDown time.Duration `json:"loopDown"`
}
Result is what a run of the model yields.
type Row ¶
type Row struct {
Stage string `json:"stage"`
Expected Quantiles `json:"expected"`
Observed Quantiles `json:"observed"`
// Gap is the observed median over the expected one.
Gap time.Duration `json:"gap"`
// Causes are what the log names around this stage, most frequent first.
Causes []string `json:"causes,omitempty"`
}
Row compares one stage: the model's residence against the log's.
type Snapshot ¶
type Snapshot struct {
At time.Time `json:"at"`
LoopRunning bool `json:"loopRunning"`
// Stopped names a standing stop or starts hold.
Stopped string `json:"stopped,omitempty"`
// Room and Blocks are capacity's verdict for a worker start.
Room int `json:"room"`
// StartBlocked excludes temporary occupancy of worker slots.
StartBlocked bool `json:"startBlocked,omitempty"`
MergeBlocks map[string]string `json:"mergeBlocks,omitempty"`
Blocks []string `json:"blocks,omitempty"`
Busy int `json:"busy"`
Parked int `json:"parked"`
Idle int `json:"idle"`
Providers []ProviderRoom `json:"providers,omitempty"`
// Reviewers names the busy review agents.
Reviewers []string `json:"reviewers,omitempty"`
Items []Item `json:"items"`
Board []BoardItem `json:"board,omitempty"`
BoardRead bool `json:"boardRead"`
Holds []string `json:"holds,omitempty"`
Lanes []LaneState `json:"lanes,omitempty"`
ReviewRequests []state.ReviewRequest `json:"reviewRequests,omitempty"`
FailedMerges []FailedMerge `json:"failedMerges,omitempty"`
ParkedAgents []ParkedAgent `json:"parkedAgents,omitempty"`
Timers []int `json:"timers,omitempty"`
// UnmergedLimit is supervisor.unmergedLimit, for the record: board
// next applies it and holds the items past it.
UnmergedLimit int `json:"unmergedLimit"`
}
Snapshot is the desk now, as the forecast reads it from the state and the implementation's own verdicts (capacity, board next).
type Stage ¶
Stage is one step's service time: a lognormal distribution around Median with the spread Sigma (0 makes every sample the median).
type StageResult ¶
type StageResult struct {
Stage string `json:"stage"`
Wait Quantiles `json:"wait"`
Service Quantiles `json:"service"`
Residence Quantiles `json:"residence"`
}
StageResult is one stage's figures: Wait is the time an issue waited for the loop or a resource before the stage, Service the stage's own time and Residence both, which is what a delivery.step event measures.
type StartForecast ¶
StartForecast is a board item forecast to start.
type Total ¶
type Total struct {
After time.Duration `json:"after"`
Started int `json:"started"`
Released int `json:"released"`
}
Total is the forecast count after a time.
type Transition ¶
Transition is a stage an item is forecast to reach at a time.