contract

package
v0.3.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: 9 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 contract defines what factorymeter writes out, and generates the reference docs and the JSON Schema from the definitions in code.

The contract has three layers. Records (pkg/record) are what is kept. Metrics (pkg/line) are what is measured. The report in this file is what is written out. Inside one version fields are only ever added, and a metric id never changes meaning.

Index

Constants

View Source
const (
	StatusMeasured     = "measured"
	StatusPartial      = "partial"
	StatusNotConnected = "not_connected"
)

Station statuses.

View Source
const (
	TrendBetter  = "better"
	TrendWorse   = "worse"
	TrendFlat    = "flat"
	TrendUnknown = "unknown"
)

Trends.

View Source
const (
	ConfidenceHigh   = "high"
	ConfidenceMedium = "medium"
	ConfidenceLow    = "low"
)

Confidence levels.

View Source
const Dir = "docs/reference"

Dir is where the generated reference files live in the repository.

View Source
const SchemaFile = "factorymeter-v1.schema.json"

SchemaFile is the name of the JSON Schema of the report.

View Source
const SchemaID = "https://raw.githubusercontent.com/marshal-org/factorymeter/main/" + Dir + "/" + SchemaFile

SchemaID is the id the JSON Schema of the report carries.

View Source
const Version = "factorymeter/v1"

Version marks every report.

Variables

View Source
var HowRecommended = []string{
	"A rule is a fixed test on the numbers of the report. It fires or it does not. Nothing is guessed and no model is asked.",
	fmt.Sprintf("A station is compared with itself, not with other companies: with its own best %d weeks in a row inside the window of the report. A stretch counts only when at least %d items left the station in it. A window of %d weeks or less has no best weeks, and the gain is not sized.", line.BestWeeks, line.MinSample, line.BestWeeks),
	"Hours freed a week is the waiting that goes away if the station gets back to that pace. It is waiting time of changes, not working time of people. A rule that cannot size its gain leaves it empty. A gain of 0 means no stretch of the window did better.",
	"The order is: the constraint first, then the largest hours freed, then the rest in the order of this page.",
	fmt.Sprintf("Confidence is how much data stands behind the numbers: high from %d items, medium from %d, low below that. For a sized gain it is the smaller of the items in the window and the items in the best weeks. A rule that counts what stands in a queue is always high.", line.HighSample, line.MediumSample),
	"Every recommendation carries its evidence: each number the rule read, the number it was compared with, and a sentence that says both.",
	"A rule about a queue names up to 5 items to look at first, the one that has stood longest first. A summary names none.",
	"A rule id never changes meaning. A rule whose test has to change gets a new id.",
}

HowRecommended says how every recommendation is made, whatever the rule.

View Source
var Records = []Record{
	{record.KindTicket, "An issue on GitHub, Linear or Jira. Tickets feed the spec station.", record.Ticket{}},
	{record.KindChange, "A pull request. Changes feed the code, review and merge stations, and tie CI runs and deploys to the line.", record.Change{}},
	{record.KindCIRun, "One attempt of one CI workflow on one commit. Runs on a commit of a change feed the ci station.", record.CIRun{}},
	{record.KindDeploy, "One deployment to an environment, or one published release. Deploys feed the verify and release stations.", record.Deploy{}},
	{record.KindLink, "A tie between two records: a change that closes a ticket, or a change that reverts another.", record.Link{}},
}

Records lists the record kinds in the order the docs print them.

View Source
var Rules = []string{
	"A definition says \"the period\". For the value of a metric that is the whole window of the report, 13 weeks unless asked otherwise. For one point of its history it is one week.",
	"A station's numbers are counted when they happen, not when the change merges. A wait counts in the period it ended, and work in the period the item left the station. A change that waited four weeks for review and got it this week counts this week, at the review station, whether or not it has merged yet.",
	"The numbers about the whole line are measured over the changes merged in the period.",
	"Queue numbers are not measured over a period. They are the state at the end of it.",
	fmt.Sprintf("A median, a percentile or a share drawn from fewer than %d items is still reported, and marked thin. No trend is called on a thin value.", line.MinSample),
	"Every time is wall-clock time. Nights and weekends count, because the work waits through them.",
	"Changes by automation, such as dependency bumps and release bots, are reported as their own class and are left out of every number about the whole line.",
	"A metric id never changes meaning. When a definition has to change, the metric gets a new id and the old one stays or is removed in a new contract version.",
}

Rules hold for every metric. They are stated once here instead of in each definition.

Functions

func Files

func Files() (map[string][]byte, error)

Files builds every generated reference file, keyed by its name in Dir.

func JSON

func JSON(v any) ([]byte, error)

JSON writes v the way every generated file is written: indented, with a final newline and without escaping the characters HTML cares about.

func MetricsMarkdown

func MetricsMarkdown() string

MetricsMarkdown renders the metric registry as a reference page.

func RecordsMarkdown

func RecordsMarkdown() string

RecordsMarkdown renders the record layout as a reference page.

func ReportMarkdown

func ReportMarkdown() string

ReportMarkdown renders the layout of the report as a reference page.

func ReportSchema

func ReportSchema() map[string]any

ReportSchema is the JSON Schema of the report.

func RulesMarkdown

func RulesMarkdown() string

RulesMarkdown renders the recommendation rules as a reference page.

func Schema

func Schema(v any, id, title, description string) map[string]any

Schema builds the JSON Schema, draft 2020-12, of a struct of the contract. Field descriptions come from the doc tags and allowed values from the enum tags, so the schema cannot say something the code does not.

Types

type Catalog

type Catalog struct {
	Schema   string         `json:"schema"`
	Kinds    []KindDoc      `json:"kinds"`
	Units    []UnitDoc      `json:"units"`
	Rules    []string       `json:"rules"`
	Stations []line.Station `json:"stations"`
	Metrics  []line.Metric  `json:"metrics"`
	// RecommendationRules are the rules behind "where to invest". The plain
	// name was taken by the rules of the metrics.
	RecommendationRules []line.Rule `json:"recommendation_rules"`
}

Catalog is the metric registry as a program reads it.

func NewCatalog

func NewCatalog() Catalog

NewCatalog builds the catalog from the registry.

type Coverage

type Coverage struct {
	Repos   []RepoCoverage   `json:"repos" doc:"One entry per repository in the store. Empty in a summary."`
	Sources []SourceCoverage `json:"sources" doc:"One entry per kind of record."`
}

Coverage says what stands behind the report.

type Evidence

type Evidence struct {
	Metric string   `json:"metric" doc:"The metric id." pattern:"^[a-z]+[.][a-z][a-z0-9_]*([.][a-z][a-z0-9_]*)?$"`
	Slice  Slice    `json:"slice" doc:"The part of the line the number is about."`
	Value  *float64 `json:"value" doc:"The value the rule read."`
	Versus *float64 `` /* 162-byte string literal not displayed */
	Text   string   `json:"text" doc:"The number in words."`
}

Evidence is one number behind a recommendation.

type Field

type Field struct {
	Name string
	Type string
	Doc  string
	Enum []string
}

Field is one field of a struct of the contract, as the docs print it.

func Fields

func Fields(v any) []Field

Fields lists the fields of a struct in the order they are declared.

type Item

type Item struct {
	Kind  string  `json:"kind" doc:"What the item is." enum:"ticket,change"`
	Key   string  `json:"key" doc:"The name people use for it, such as owner/repo#12."`
	URL   string  `json:"url" doc:"Link to it on the source."`
	Title string  `json:"title" doc:"Its title."`
	Class string  `json:"class" doc:"Who wrote it. Empty for a ticket." enum:"agent,human,automation,"`
	Hours float64 `json:"hours" doc:"How long it has stood in the queue, in hours."`
}

Item is one ticket or change a report points at.

type KindDoc

type KindDoc struct {
	ID   line.Kind `json:"id"`
	Does string    `json:"does"`
}

KindDoc describes one kind of metric.

type Period

type Period struct {
	From time.Time `json:"from" doc:"Start, inclusive."`
	To   time.Time `json:"to" doc:"End, exclusive."`
}

Period is one span of time.

type Point

type Point struct {
	Value *float64 `json:"value" doc:"The value in the period. Null when nothing was counted."`
	N     int      `json:"n" doc:"How many items the value is drawn from."`
}

Point is one period of a series.

type Recommendation

type Recommendation struct {
	Rule       string     `json:"rule" doc:"The id of the rule that fired, such as review.queue-growing. Rule ids are stable."`
	Station    string     `json:"station" doc:"The station the recommendation is about."`
	Title      string     `json:"title" doc:"What to do, in one line."`
	Why        string     `json:"why" doc:"The reasoning in a sentence or two."`
	Evidence   []Evidence `json:"evidence" doc:"The numbers the rule read."`
	HoursFreed *float64   `` /* 172-byte string literal not displayed */
	Confidence string     `json:"confidence" doc:"How much data stands behind the recommendation." enum:"high,medium,low"`
	PlayURL    string     `json:"play_url" doc:"Link to the playbook page that describes the practice. Empty when there is none."`
	Items      []Item     `json:"items" doc:"The items to look at first. Empty in a summary."`
}

Recommendation is one thing to do, with the numbers that led to it.

type Record

type Record struct {
	Kind  string
	Does  string
	Value any
}

A Record is one kind of record of the store.

type RepoCoverage

type RepoCoverage struct {
	Repo     string    `json:"repo" doc:"The repository, as owner/name."`
	Private  bool      `json:"private" doc:"True for a private repository."`
	From     time.Time `json:"from" doc:"How far back the store holds this repository."`
	SyncedAt time.Time `json:"synced_at" doc:"When the repository was last synced."`
	Changes  int       `json:"changes" doc:"Changes in the store for this repository."`
}

RepoCoverage is one repository in the store.

type Report

type Report struct {
	Schema          string           `json:"schema" doc:"Always factorymeter/v1." enum:"factorymeter/v1"`
	GeneratedAt     time.Time        `json:"generated_at" doc:"When the report was computed."`
	Tool            Tool             `json:"tool" doc:"The program that wrote the report."`
	Target          string           `json:"target" doc:"The owner or owner/repo that was measured. Empty in a summary."`
	Summary         bool             `json:"summary" doc:"True when every name, title and link was left out, so the file holds station numbers only."`
	Window          Window           `json:"window" doc:"The time the report covers."`
	Coverage        Coverage         `json:"coverage" doc:"What was loaded and what is missing."`
	Verdict         Verdict          `json:"verdict" doc:"The one-sentence answer."`
	Stations        []Station        `json:"stations" doc:"The seven stations of the line, in order."`
	Metrics         []Series         `json:"metrics" doc:"Every number, each with its weekly history."`
	Recommendations []Recommendation `json:"recommendations" doc:"Where to invest, most valuable first."`
	Limits          []string         `json:"limits" doc:"What the reader should know before trusting a number."`
}

Report is one run of "factorymeter report" as JSON.

type Series

type Series struct {
	Metric    string   `` /* 135-byte string literal not displayed */
	Slice     Slice    `json:"slice" doc:"The part of the line the series is about."`
	Unit      string   `json:"unit" doc:"What the values count." enum:"per_week,hours,share,count,lines"`
	Value     *float64 `json:"value" doc:"The value over the window. Null when nothing was counted."`
	N         int      `json:"n" doc:"How many items the value is drawn from."`
	Thin      bool     `json:"thin" doc:"True when the value is drawn from fewer items than the metric's minimum sample."`
	Previous  *float64 `` /* 130-byte string literal not displayed */
	PreviousN int      `json:"previous_n" doc:"How many items the previous value is drawn from."`
	Change    *float64 `` /* 247-byte string literal not displayed */
	Trend     string   `` /* 274-byte string literal not displayed */
	Points    []Point  `json:"points" doc:"One value per period of the window's periods, oldest first."`
}

Series is one metric for one slice: its value over the window, the value it is compared with, and its history.

type Slice

type Slice struct {
	Class string `json:"class" doc:"Who wrote the changes. Empty for all of them." enum:"agent,human,automation,"`
	Agent string `json:"agent" doc:"The id of one agent in the signature registry. Empty for all."`
	Repo  string `json:"repo" doc:"One repository. Empty for all."`
}

Slice says which part of the line a series is about. Every field empty means the whole line.

type SourceCoverage

type SourceCoverage struct {
	Kind    string `json:"kind" doc:"The kind of record." enum:"ticket,change,ci_run,deploy"`
	Source  string `json:"source" doc:"Where the records come from, such as github. Empty when nothing is connected."`
	Records int    `json:"records" doc:"How many records of this kind the window holds."`
	Note    string `` /* 133-byte string literal not displayed */
}

SourceCoverage is one kind of record in the store.

type Station

type Station struct {
	ID         string   `json:"id" doc:"The station id." enum:"spec,code,ci,verify,review,merge,release"`
	Name       string   `json:"name" doc:"The station name."`
	Status     string   `json:"status" doc:"Whether the station could be measured." enum:"measured,partial,not_connected"`
	Missing    string   `json:"missing" doc:"What to connect to measure the station fully. Empty when nothing is missing."`
	Constraint bool     `json:"constraint" doc:"True for the one station named the constraint."`
	HeldShare  *float64 `` /* 155-byte string literal not displayed */
	Oldest     []Item   `json:"oldest" doc:"The items that have stood longest in the station's queue, oldest first. Empty in a summary."`
}

Station is one station of the line in a report.

type Tool

type Tool struct {
	Name            string `json:"name" doc:"Always factorymeter."`
	Version         string `json:"version" doc:"The version of the program."`
	RegistryVersion string `json:"registry_version" doc:"The version of the agent signature registry used to tell agents from people."`
	RecordSchema    int    `json:"record_schema" doc:"The version of the record layout in the store the report was read from."`
}

Tool names the program and the rule files behind a report.

type UnitDoc

type UnitDoc struct {
	ID   line.Unit `json:"id"`
	Does string    `json:"does"`
}

UnitDoc describes one unit.

type Verdict

type Verdict struct {
	Headline   string `json:"headline" doc:"One sentence that names the constraint and how it is moving."`
	Constraint string `json:"constraint" doc:"The id of the constraint station. Empty when too few changes merged to name one."`
	Detail     string `json:"detail" doc:"One or two sentences of evidence behind the headline."`
}

Verdict is the answer on top of the page.

type Window

type Window struct {
	Since      time.Time `json:"since" doc:"Start of the window the values are computed over."`
	Until      time.Time `json:"until" doc:"End of the window."`
	PeriodDays int       `json:"period_days" doc:"Length of one period of a history, in days. 7 unless asked otherwise."`
	Periods    []Period  `json:"periods" doc:"The periods of every history, oldest first. They can reach further back than the window."`
	Previous   *Period   `` /* 155-byte string literal not displayed */
}

Window is the time a report covers.

Jump to

Keyboard shortcuts

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