index

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package index reads a schema-versioned JSON document of per-model measurements into a value every reader in a process can share.

THE INDEX IS READ-ONLY AND IMMUTABLE, which is the whole design: nothing merges into it and nothing mutates it after Parse, so one document may be handed to every goroutine without a lock. Whoever read the file stays outside the package — Parse takes bytes, Read takes a reader, and Fallback chooses between two documents that both arrive as bytes.

FORWARD COMPATIBILITY IS THE POINT. An unknown top-level field, an unknown metric kind, an undeclared dim on a cell and an unknown cell field are all ignored, because a reader that refused them would make every future field a flag day. The one thing refused outright is a schema this reader does not understand, which is what the schema number exists to say.

Index

Constants

This section is empty.

Variables

View Source
var ErrSchema = errors.New("document schema is newer than this reader")

ErrSchema is wrapped by the error a document whose schema is newer than this reader returns. A reader that is behind the document cannot guess what the newer fields mean, so it refuses rather than half-reads.

Functions

func Seed

func Seed() []byte

Seed answers with the embedded document's bytes, as a COPY: the index is read many times and by many goroutines, and a caller that changed the slice would change what every later Seed call hands back.

Types

type Cell

type Cell struct {
	Metric   string
	Role     string
	Model    string
	Mean     float64
	SD       float64
	N        int
	Installs int
	Dims     map[string]string
}

Cell is one measurement from the document. Dims carries the declared dims beyond role and model that the cell spelled, and is nil for a cell that carried none. Installs is the contributor count the cell spells — the one the floor reads it on; a cell that spells none, the shape the seed carries, reads zero, its rows being the only count the document gives.

type Index

type Index struct {
	// contains filtered or unexported fields
}

Index is a parsed measurement document. Nothing on it mutates after it is built, and every accessor hands back copies, so many goroutines may read one Index at once.

func Fallback

func Fallback(primary, embedded []byte) (*Index, error)

Fallback answers with the document that should be trusted: primary, unless it is missing, empty, unparsable, or older by its generated date, in which case the embedded one. Equal dates keep primary. When neither parses it returns the error from the embedded document.

func Parse

func Parse(data []byte) (*Index, error)

Parse reads a measurement document from bytes.

func Read

func Read(r io.Reader) (*Index, error)

Read reads a measurement document from a reader. The reader is drained and closed by nobody but the caller; the document is all this package takes.

func SeedIndex

func SeedIndex() (*Index, error)

SeedIndex parses the embedded document — the index a machine with no cache starts from. The error is returned rather than panicking, though the seed is a file this build was shipped with and a test in this package parses it, so an error here is a bug and not a mode.

func (*Index) Canonical

func (x *Index) Canonical(model string) string

Canonical answers with the canonical id the document spells for a model id, for the id itself and for any of its alternates, and with the normalised input for an id the document never names.

func (*Index) Cell

func (x *Index) Cell(metric, role, model string, dims map[string]string) (Cell, bool)

Cell addresses a measurement exactly: metric, role, model and dims all have to match, and a nil dims map and an empty one are the same address. A lookup with no dims finds the cell that carries none, and never a cell that carries some.

func (*Index) Cells

func (x *Index) Cells(metric string) []Cell

Cells answers with every returnable cell of one metric, sorted by role, then model, then by its dims rendered as sorted "key=value" pairs.

func (*Index) Dims

func (x *Index) Dims(metric string) []string

Dims answers with the metric's declared dims beyond role and model, sorted. Role and model are the address of every cell and are never repeated here. A metric that declares no dim beyond them, and a name the document does not declare, answer empty.

func (*Index) Generated

func (x *Index) Generated() time.Time

Generated is the document's "generated" day in UTC. A missing or unreadable date is the zero time, which sorts as the oldest thing there is.

func (*Index) Judges

func (x *Index) Judges() []string

Judges answers with a copy of the document's judges.

func (*Index) Kind

func (x *Index) Kind(metric string) (string, bool)

Kind answers with the kind word the document spells for the metric, lowercased, whether or not this build knows it.

func (*Index) Metrics

func (x *Index) Metrics() []string

Metrics lists the declared metric names, sorted.

func (*Index) MinInstalls

func (x *Index) MinInstalls() int

MinInstalls is the document's floor on the installs behind a measurement, which a cell that carries none meets on its rows.

func (*Index) Rubrics

func (x *Index) Rubrics() map[string]int

Rubrics answers with a copy of the document's rubrics.

func (*Index) Schema

func (x *Index) Schema() int

Schema is the document's schema version. A missing schema reads as 0 and is accepted.

func (*Index) Unit

func (x *Index) Unit(metric string) string

Unit answers with the unit word the document spells for the metric, lowercased, whether or not this build knows it. A metric that spells no unit, and a name the document does not declare, answer empty.

func (*Index) Wanted

func (x *Index) Wanted() []Want

Wanted answers with a copy of the wanted list, sorted by weight descending, then by model ascending.

type Want

type Want struct {
	Role   string
	Model  string
	Weight float64
}

Want is one row of the document's wanted list, with the role normalised and the model resolved to its canonical id.

Directories

Path Synopsis
cmd
seedgen command
Command seedgen regenerates the seed index the binary carries from the live relay.
Command seedgen regenerates the seed index the binary carries from the live relay.

Jump to

Keyboard shortcuts

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