Help us shape the future of Go! Take the 2026 Go Developer Survey

backlog

package
v2.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package backlog provides shared backlog analytics types, constants, and algorithms used by both the Admin API and MCP server.

Index

Constants

View Source
const (
	// MaxListLimit is the upper bound for list/query limit parameters.
	MaxListLimit = 1000

	// DefaultTrendWindow is the default time window for backlog trend queries.
	DefaultTrendWindow = time.Hour

	// DefaultTrendStep is the default bucket step for backlog trend queries.
	DefaultTrendStep = 5 * time.Minute

	// MinTrendStep is the minimum allowed trend bucket step.
	MinTrendStep = time.Minute

	// MaxTrendStep is the maximum allowed trend bucket step.
	MaxTrendStep = time.Hour

	// MaxTrendWindow is the maximum allowed trend query window.
	MaxTrendWindow = 7 * 24 * time.Hour

	// MaxTrendSamples is the maximum number of trend samples returned per query.
	MaxTrendSamples = 20000
)

Shared constants for backlog analytics queries.

Variables

View Source
var DefaultSummaryStates = []queue.State{
	queue.StateQueued,
	queue.StateLeased,
	queue.StateDead,
}

DefaultSummaryStates is the default set of queue states included in backlog summary queries when no explicit states are specified.

Functions

func AgePercentileNearestRank

func AgePercentileNearestRank(ordered []int, percentile int) int

AgePercentileNearestRank returns the value at the given percentile using nearest-rank interpolation. The input slice must be sorted in ascending order.

func ObserveAgeWindow

func ObserveAgeWindow(ageSeconds int, windows *AgeWindows)

ObserveAgeWindow increments the appropriate age bucket in windows based on the given age in seconds.

func ReferenceNow

func ReferenceNow(stats queue.Stats) time.Time

ReferenceNow derives a stable "now" timestamp from queue stats, falling back to time.Now().UTC() when no age/lag data is available. Using stats-derived timestamps ensures consistent age/lag calculations across a single response.

Types

type AgePercentiles

type AgePercentiles struct {
	P50 int `json:"p50"`
	P90 int `json:"p90"`
	P99 int `json:"p99"`
}

AgePercentiles holds P50/P90/P99 age percentiles in seconds, computed from a sample of queued item ages.

func AgePercentilesFromSamples

func AgePercentilesFromSamples(samples []int) (AgePercentiles, bool)

AgePercentilesFromSamples computes P50/P90/P99 from a slice of age-in-seconds samples. Returns false when samples is empty.

type AgeWindows

type AgeWindows struct {
	LE5M      int `json:"le_5m"`
	GT5MLE15M int `json:"gt_5m_le_15m"`
	GT15MLE1H int `json:"gt_15m_le_1h"`
	GT1HLE6H  int `json:"gt_1h_le_6h"`
	GT6H      int `json:"gt_6h"`
}

AgeWindows counts items by age bucket: ≤5m, 5m–15m, 15m–1h, 1h–6h, >6h.

type StateScanSummary

type StateScanSummary struct {
	Scanned   int  `json:"scanned"`
	Truncated bool `json:"truncated"`
}

StateScanSummary reports how many items were scanned for a given queue state and whether the scan was truncated by the query limit.

Jump to

Keyboard shortcuts

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