line

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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 line is the model of the delivery line: the stations work passes through and the registry of every number factorymeter reports about them.

It holds definitions only. Nothing here reads a repository or computes a value. The docs under docs/reference are generated from this package, so a definition is written once.

Index

Constants

View Source
const (
	// SliceClass cuts by who wrote the change: agent, human or automation.
	SliceClass = "class"
	// SliceAgent cuts agent changes by the agent that wrote them.
	SliceAgent = "agent"
	// SliceRepo cuts by repository.
	SliceRepo = "repo"
)

Slices a metric can be cut by.

View Source
const (
	// BestWeeks is the length of the stretch a station is sized against: its
	// own best four weeks of the window.
	BestWeeks = 4
	// SlowRatio is how far above its best four weeks a station that is not
	// the constraint must run before it gets a recommendation.
	SlowRatio = 1.25
	// SlowShare is the smallest gain worth a recommendation at a station that
	// is not the constraint, as a part of the hours it is compared with.
	SlowShare = 0.05
	// CIFailing is the share of failed CI rounds from which the checks get a
	// recommendation.
	CIFailing = 0.15
	// AgentCIGap is how many points more often CI must fail for agents than
	// for people. 0.05 is five points.
	AgentCIGap = 0.05
	// Reverted is the share of merges reverted from which reverts get a
	// recommendation, and RevertedMin the fewest reverts it takes.
	Reverted    = 0.05
	RevertedMin = 3
	// Abandoned is the share of closed changes that were not merged.
	Abandoned = 0.2
	// ReviewQueueMin is the smallest review queue that counts as a queue.
	ReviewQueueMin = 5
	// A draft is stale after StaleDraftDays. It takes StaleDraftMin of them.
	StaleDraftDays = 14
	StaleDraftMin  = 3
	// An approved change has waited too long after ApprovedHours. It takes
	// ApprovedMin of them.
	ApprovedHours = 24
	ApprovedMin   = 3
	// Ungated is the share of changes merged with no review from which a
	// line with no verify station is told to add a gate.
	Ungated = 0.5
	// An agent's changes are large when their median is AgentSizeRatio times
	// that of people and at least AgentSizeLines.
	AgentSizeRatio = 2.0
	AgentSizeLines = 200
	// Agents wait longer for review when their median wait is AgentWaitRatio
	// times that of people and at least AgentWaitHours more.
	AgentWaitRatio = 1.5
	AgentWaitHours = 1.0
	// Reopened is the share of finished tickets that had been finished
	// before and were opened again.
	Reopened = 0.1
	// A ticket nobody started is stale after StaleTicketDays. It takes
	// StaleTicketMin of them.
	StaleTicketDays = 90
	StaleTicketMin  = 5
	// The tickets ready to start are thin when they are fewer than the line
	// starts in BacklogWeeks.
	BacklogWeeks = 1
	// A recommendation drawn from HighSample items or more is high
	// confidence, from MediumSample or more medium, below that low.
	HighSample   = 30
	MediumSample = 10
)

The numbers the recommendation rules compare with. A rule says when it fires in words built from these, so the docs cannot drift from the code.

View Source
const (
	Spec    = "spec"
	Code    = "code"
	CI      = "ci"
	Verify  = "verify"
	Review  = "review"
	Merge   = "merge"
	Release = "release"
	// Whole is not a station. It holds the numbers about the line as a whole.
	Whole = "line"
)

Station ids, in the order work passes through them.

View Source
const (
	NeedTicket = "ticket"
	NeedChange = "change"
	NeedCIRun  = "ci_run"
	NeedDeploy = "deploy"
)

Record kinds a station or a metric can need. They match pkg/record.

View Source
const IDPattern = `^[a-z]+[.][a-z][a-z0-9_]*([.][a-z][a-z0-9_]*)?$`

IDPattern is the form of a metric id. It is written without a backslash so it can sit in a struct tag.

View Source
const MinSample = 5

MinSample is the fewest items a median, a percentile or a share is drawn from before the report trusts it. A value drawn from fewer is still printed, and marked.

View Source
const Playbook = "https://thesoftwarefactory.site/playbook/"

Playbook is where the pages a recommendation links to live.

View Source
const RuleIDPattern = `^[a-z]+[.][a-z][a-z0-9]*(-[a-z0-9]+)*$`

RuleIDPattern is the form of a rule id. It is written without a backslash so it can sit in a struct tag.

View Source
const V1 = "v1"

V1 is the first version of the contract.

Variables

View Source
var KindDoes = map[Kind]string{
	Flow:   "How many items leave the station each week.",
	Wait:   "How long an item waits before the station starts on it.",
	Work:   "How long the station works on an item.",
	Rework: "The share of items the station sends back or has to redo.",
	Queue:  "How many items stand at the station at the end of the period, and how old the oldest is.",
	Held:   "The hours items spend at the station, wait and work together. The constraint is the station with the most.",
	Other:  "Numbers that fit none of the five.",
}

KindDoes says what each kind of number answers.

Kinds lists the kinds in the order a station shows them.

View Source
var Plays = []string{
	"find-the-constraint", "set-a-baseline", "one-owner-for-the-whole-line", "environment-per-agent", "agents-prove-their-work",
	"decide-up-front", "out-of-the-synchronous-loop", "trust-is-earned-with-evidence", "guardrails-before-autonomy", "keep-the-line-fed",
}

Plays are the playbook pages a rule can link to.

View Source
var Registry = build()

Registry is every metric, in the order the docs list them.

View Source
var Rules = stamp([]Rule{
	slow(Code, "Get changes ready for review sooner", "decide-up-front", "code.work.p50"),
	slow(CI, "Make CI rounds shorter", "find-the-constraint", "ci.work.p50", "ci.wait.p50"),
	slow(Verify, "Bring changes up on an environment faster", "environment-per-agent", "verify.wait.p50", "verify.work.p50"),
	slow(Review, "Cut the wait for review", "trust-is-earned-with-evidence", "review.wait.p50", "review.work.p50", "review.queue"),
	slow(Merge, "Merge finished changes sooner", "out-of-the-synchronous-loop", "merge.wait.p50", "merge.queue"),
	slow(Release, "Release more often", "find-the-constraint", "release.wait.p50", "release.deploys", "release.queue"),
	{
		ID: "verify.missing", Station: Verify, Title: "Prove changes on a running environment before they merge", Play: "agents-prove-their-work",
		Reads: []string{"review.skipped"},
		Fires: fmt.Sprintf("The verify station is not connected, and at least %s of the changes merged in the window had no review by another person.", pct(Ungated)),
	},
	{
		ID: "ci.failing", Station: CI, Title: "Cut the share of CI rounds that fail",
		Reads: []string{"ci.rework", "ci.flow", "ci.work.p50"},
		Fires: fmt.Sprintf("At least %s of the CI rounds in the window failed, timed out or were run again. The evidence names the workflows whose runs did so most often.", pct(CIFailing)),
		Sized: "The share of failed rounds now, less the share in the best four weeks, times the rounds in a week, times the mean hours a round holds a change.",
	},
	{
		ID: "ci.agents-fail-more", Station: CI, Title: "Have agents run the checks before they push", Play: "agents-prove-their-work",
		Reads: []string{"ci.rework"},
		Fires: fmt.Sprintf("CI rounds on changes by agents fail at least %.0f points more often than rounds on changes by people. %s", AgentCIGap*100, bothSides),
	},
	{
		ID: "merge.reverted", Station: Merge, Title: "Find out why merged changes get reverted", Play: "agents-prove-their-work",
		Reads: []string{"merge.rework"},
		Fires: fmt.Sprintf("At least %s of the changes merged in the window were reverted later, and at least %d of them.", pct(Reverted), RevertedMin),
	},
	{
		ID: "code.abandoned", Station: Code, Title: "Find out why changes are closed without merging", Play: "decide-up-front",
		Reads: []string{"code.rework"},
		Fires: fmt.Sprintf("At least %s of the changes closed in the window were closed without merging.", pct(Abandoned)),
	},
	{
		ID: "review.queue-growing", Station: Review, Title: "Clear the review queue", Play: "trust-is-earned-with-evidence",
		Reads: []string{"review.queue", "review.queue.oldest", "review.wait.p50"},
		Fires: fmt.Sprintf("At least %d changes wait for a first review at the end of the window, and the trend of the queue is worse: it is longer than at the end of the window before by more than the report calls flat. The rule is silent when no change in the store was ever reviewed by another person.", ReviewQueueMin),
	},
	{
		ID: "merge.approved-waiting", Station: Merge, Title: "Merge the changes that are already approved", Play: "out-of-the-synchronous-loop",
		Reads: []string{"merge.queue", "merge.queue.oldest"},
		Fires: fmt.Sprintf("At least %d changes have been approved for more than %d hours and are not merged at the end of the window.", ApprovedMin, ApprovedHours),
	},
	{
		ID: "code.stale-drafts", Station: Code, Title: "Finish or close the drafts that stopped moving",
		Reads: []string{"code.queue", "code.queue.oldest"},
		Fires: fmt.Sprintf("At least %d changes have been a draft for more than %d days at the end of the window.", StaleDraftMin, StaleDraftDays),
	},
	{
		ID: "spec.reopened", Station: Spec, Title: "Find out why finished tickets are opened again", Play: "decide-up-front",
		Reads: []string{"spec.rework"},
		Fires: fmt.Sprintf("At least %s of the tickets finished in the window had been finished before and were opened again. The share is drawn from at least %d tickets.", pct(Reopened), MinSample),
	},
	{
		ID: "spec.stale-tickets", Station: Spec, Title: "Close or schedule the tickets nobody has started",
		Reads: []string{"spec.queue", "spec.queue.oldest"},
		Fires: fmt.Sprintf("At least %d tickets have been open for more than %d days at the end of the window with no work started on them.", StaleTicketMin, StaleTicketDays),
	},
	{
		ID: "spec.backlog-thin", Station: Spec, Title: "Write up more work that is ready to start", Play: "keep-the-line-fed",
		Reads: []string{"spec.queue", "spec.flow"},
		Fires: fmt.Sprintf("Fewer tickets are open and not started at the end of the window than the line starts in %s. The pace is drawn from at least %d tickets started in the window.", weeksWord(BacklogWeeks), MinSample),
	},
	{
		ID: "review.agents-wait-longer", Station: Review, Title: "Find out why changes by agents wait longer for review", Play: "trust-is-earned-with-evidence",
		Reads: []string{"review.wait.p50"},
		Fires: fmt.Sprintf("The median wait for a first review is at least %.1f times as long for changes by agents as for changes by people, and at least %.0f hour longer. %s", AgentWaitRatio, AgentWaitHours, bothSides),
	},
	{
		ID: "code.agent-changes-large", Station: Code, Title: "Have agents ship smaller changes",
		Reads: []string{"line.size.p50"},
		Fires: fmt.Sprintf("The median change by an agent is at least %.0f times the size of the median change by a person, and at least %d lines. %s", AgentSizeRatio, AgentSizeLines, bothSides),
	},
})

Rules is every recommendation, in the order they are listed when nothing else ranks them.

View Source
var Stations = []Station{
	{
		ID: Spec, Name: "Spec", Item: "ticket", Needs: []string{NeedTicket},
		Does:    "A ticket is written and waits for someone to start on it.",
		Arrives: "The ticket is created.",
		Leaves:  "Work starts: the ticket first moves to a started state, or its first linked change is opened, whichever comes first.",
		Why:     "A backlog holds tickets on purpose, often for months. Counting that as waiting would name spec the constraint in every repository.",
		NotObservable: map[Kind]string{
			Work: "Writing a ticket leaves no start time.",
			Held: "Spec is left out of the constraint, so its hours are not added up.",
		},
	},
	{
		ID: Code, Name: "Code", Item: "change", Needs: []string{NeedChange}, InConstraint: true,
		Does:    "The change is written.",
		Arrives: "The first commit of the change is written or the change is opened, whichever is earlier.",
		Leaves:  "The change is marked ready for review. A change opened ready leaves when it is opened.",
		NotObservable: map[Kind]string{
			Wait: "Code has no queue of its own. A ticket waiting for someone to start waits at spec.",
		},
	},
	{
		ID: CI, Name: "CI", Item: "CI round", Needs: []string{NeedChange, NeedCIRun}, InConstraint: true,
		Does:    "The checks run on each push to a change. One CI round is every run on one commit of a change.",
		Arrives: "The first run on the commit is created.",
		Leaves:  "The last run on the commit finishes.",
		NotObservable: map[Kind]string{
			Queue: "A CI round lasts minutes. A count of rounds in flight at the end of a week says nothing about the week.",
		},
	},
	{
		ID: Verify, Name: "Verify", Item: "change", Needs: []string{NeedChange, NeedDeploy}, InConstraint: true,
		Does:    "The change is proved on a running environment before it merges.",
		Arrives: "A commit of the change is deployed to an environment that is not production.",
		Leaves:  "That deployment reports success.",
		NotObservable: map[Kind]string{
			Queue: "Nothing records that a change is waiting for an environment.",
		},
	},
	{
		ID: Review, Name: "Review", Item: "change", Needs: []string{NeedChange}, InConstraint: true,
		Does:    "Another person reads the change and approves it or sends it back.",
		Arrives: "The change is marked ready for review.",
		Leaves:  "The last approval before the merge. A change that merges after a review with no approval leaves at the merge. A change nobody else reviewed skips the station.",
	},
	{
		ID: Merge, Name: "Merge", Item: "change", Needs: []string{NeedChange}, InConstraint: true,
		Does:    "The approved change lands on the main branch.",
		Arrives: "The change leaves review. A change nobody else reviewed arrives when it is marked ready for review.",
		Leaves:  "The change merges.",
		NotObservable: map[Kind]string{
			Work: "A merge is one click. It has no start time apart from its end.",
		},
	},
	{
		ID: Release, Name: "Release", Item: "change", Needs: []string{NeedChange, NeedDeploy}, InConstraint: true,
		Does:    "The merged change reaches production.",
		Arrives: "The change merges.",
		Leaves:  "The first production deploy that holds it. A change merged before the first production deploy in the store is not counted.",
	},
}

Stations is the line, first station first.

View Source
var UnitDoes = map[Unit]string{
	PerWeek: "Items per week: the count in the period divided by the length of the period in weeks.",
	Hours:   "Hours of wall-clock time. Nights and weekends count.",
	Share:   "A share between 0 and 1. 0.25 is 25 percent.",
	Count:   "A plain count at one moment.",
	Lines:   "Lines of code.",
}

UnitDoes says how to read a value of each unit.

Units lists the units in the order the docs print them.

Functions

func Validate

func Validate(list []Metric) []error

Validate checks a list of metrics against the rules of the contract. It returns every problem it finds.

func ValidateRules

func ValidateRules(list []Rule) []error

ValidateRules checks a list of rules. It returns every problem it finds.

Types

type Good

type Good string

Good is the direction in which a metric gets better.

const (
	Up   Good = "up"
	Down Good = "down"
	// Neither is for a number that is not better either way, such as the
	// share of changes written by agents.
	Neither Good = "neither"
)

type Kind

type Kind string

Kind groups metrics. Every station has the same five where they can be observed: flow, wait, work, rework and queue. Held is the time behind the constraint. Other holds the few numbers that fit none of them.

const (
	Flow   Kind = "flow"
	Wait   Kind = "wait"
	Work   Kind = "work"
	Rework Kind = "rework"
	Queue  Kind = "queue"
	Held   Kind = "held"
	Other  Kind = "other"
)

type Metric

type Metric struct {
	// ID is "station.kind" or "station.kind.stat", for example
	// "review.wait.p50".
	ID      string `json:"id"`
	Station string `json:"station"`
	Kind    Kind   `json:"kind"`
	Name    string `json:"name"`
	Unit    Unit   `json:"unit"`
	Good    Good   `json:"good"`
	// MinSample is the fewest items the value should be drawn from. Zero for
	// a plain count.
	MinSample int `json:"min_sample"`
	// Slices lists what the metric can be cut by, besides the whole line.
	Slices []string `json:"slices"`
	// Needs lists the record kinds the metric is computed from.
	Needs []string `json:"needs"`
	// Definition says exactly what is counted, so a value can be checked by
	// hand.
	Definition string `json:"definition"`
	// Since is the contract version that introduced the metric.
	Since string `json:"since"`
}

Metric defines one number of the report. The id is the contract: it never changes meaning. A metric whose definition has to change gets a new id.

func ByID

func ByID(id string) (Metric, bool)

ByID finds a metric by its id.

func ForStation

func ForStation(station string) []Metric

ForStation lists the metrics of one station, or of the whole line for Whole, in registry order.

type Rule

type Rule struct {
	// ID is stable: station, a dot, a short name with dashes.
	ID      string `json:"id"`
	Station string `json:"station"`
	// Title says what to do, in one line.
	Title string `json:"title"`
	// Fires says when the rule makes its recommendation.
	Fires string `json:"fires"`
	// Reads lists the metrics the rule looks at.
	Reads []string `json:"reads"`
	// Sized says how the hours freed are worked out. Empty for a rule that
	// never sizes its gain.
	Sized string `json:"sized"`
	// Play is the playbook page that describes the practice. Empty for none.
	Play  string `json:"play"`
	Since string `json:"since"`
}

Rule is one recommendation factorymeter can make. It holds the definition only. The code that reads the numbers is in pkg/measure.

func RuleByID

func RuleByID(id string) (Rule, bool)

RuleByID finds a rule by its id.

func (Rule) PlayURL

func (r Rule) PlayURL() string

PlayURL is the link to the playbook page of a rule, or empty.

type Station

type Station struct {
	ID   string `json:"id"`
	Name string `json:"name"`
	// Does says what happens at the station.
	Does string `json:"does"`
	// Item is what moves through it: a ticket, a change, a CI round or a deploy.
	Item string `json:"item"`
	// Arrives and Leaves say when an item enters and leaves the station.
	Arrives string `json:"arrives"`
	Leaves  string `json:"leaves"`
	// Needs lists the record kinds the station is measured from. A station
	// with none of them in the store is shown as not connected.
	Needs []string `json:"needs"`
	// InConstraint is false for a station that can never be named the
	// constraint. Why says why.
	InConstraint bool   `json:"in_constraint"`
	Why          string `json:"why,omitempty"`
	// NotObservable maps a metric kind to the reason the station has no such
	// number.
	NotObservable map[Kind]string `json:"not_observable,omitempty"`
}

Station is one step of the line.

func StationByID

func StationByID(id string) (Station, bool)

StationByID finds a station. The second result is false for an unknown id and for Whole, which is not a station.

type Unit

type Unit string

Unit is what a value counts.

const (
	PerWeek Unit = "per_week"
	Hours   Unit = "hours"
	Share   Unit = "share"
	Count   Unit = "count"
	Lines   Unit = "lines"
)

Jump to

Keyboard shortcuts

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