scorer

package
v0.3.0-20260807201250-... Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

scorer

A Scorer returns the probability that a batch ultimately succeeds — reaches its terminal Succeeded state with its changes landed, not merely a passing build — as a number between 0.0 and 1.0. It is handed the batch identity and resolves the batch's changes itself through an injected changeset.Resolver, so callers pass an entity.Batch and nothing more.

Callers may score every batch a queue is waiting on, so implementations should be cheap. A speculation run scores each batch at most once, but it does not carry results across runs; anything expensive belongs behind the implementation's own cache.

Like the other extensions, a Scorer is selected per queue by the wiring layer through the Config (queue name) and Factory interface.

Implementations

heuristic scores a batch by extracting one number from its changes and matching that against ordered buckets, each mapping a [Min, Max] range to a probability. The extraction is a caller-supplied ValueFunc over the resolved entity.BatchChanges, so the same bucketing works for files touched, lines changed, or any other metric.

composite runs several named scorers and reduces their scores to one. The reduce function receives the scores keyed by scorer name, so it can weigh sources differently rather than treating them as interchangeable; Min, Max, and Avg are provided.

Adding a backend

Create a package under scorer/<backend>/ whose New(...) returns a scorer.Scorer, injecting whatever it needs at construction — a changeset.Resolver to reach the batch's changes, a metrics scope, any client. Do not add a Config or Factory implementation here; per-queue routing and the factory adapter live in the wiring layer.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// QueueName identifies the queue this Scorer serves.
	QueueName string
}

Config carries the per-queue identity handed to a Factory. The system knows only the queue name; everything an implementation needs is injected at construction by the integrator.

type Factory

type Factory interface {
	// For returns the Scorer for the given queue.
	For(cfg Config) (Scorer, error)
}

Factory builds the Scorer for a queue. Implementations are provided by integrators (and tests) and inject whatever they need at construction.

type Scorer

type Scorer interface {
	// Score returns a probability between 0.0 and 1.0 that the given batch
	// ultimately succeeds — reaches its terminal Succeeded state with its
	// changes landed, rather than Failed or Cancelled. A passing build is
	// necessary but not sufficient: a batch whose build already passed can
	// still fail to merge, so this is the probability of the final outcome,
	// not of the build alone. It is handed the batch identity and resolves the
	// batch's changes itself through an injected changeset.Resolver.
	//
	// Callers may score every batch a queue is waiting on, so implementations
	// should be cheap: a speculation run scores each batch at most once, but it
	// does not carry results over to the next run, so anything expensive to
	// compute belongs behind the implementation's own cache.
	Score(ctx context.Context, batch entity.Batch) (float64, error)
}

Scorer computes the probability that a batch ultimately succeeds, based on its changes.

Directories

Path Synopsis
Package fake provides a scorer.Scorer that decorates an existing scorer: it delegates to the wrapped implementation for the happy path, but injects an error when a change URI carries a failure marker of the form "sq-fake=<token>":
Package fake provides a scorer.Scorer that decorates an existing scorer: it delegates to the wrapped implementation for the happy path, but injects an error when a change URI carries a failure marker of the form "sq-fake=<token>":
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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