lighthouse

package
v0.33.15 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package lighthouse implements the sampler, scheduler, and runner used to capture Lighthouse performance audits for a small subset of pages during each crawl. See docs/plans/lighthouse-performance-reports.md for the full design.

Index

Constants

This section is empty.

Variables

View Source
var ErrMemoryShed = errors.New("lighthouse runner shed audit due to low memory")

ErrMemoryShed signals the consumer to leave the row in 'running' and skip XAck so XAUTOCLAIM redelivers once memory recovers.

View Source
var ErrRunnerNotImplemented = errors.New("lighthouse local runner not implemented yet")

Functions

func PerBand

func PerBand(completedPages int) int

PerBand uses Floor not Round so 10,000 pages lands exactly on the cap rather than overshooting it.

func SanitiseAuditURL

func SanitiseAuditURL(raw string) string

SanitiseAuditURL strips query and fragment before logging — audit URLs come from customer crawls and can carry session tokens or other low-entropy PII.

Types

type AuditRequest

type AuditRequest struct {
	RunID        int64
	JobID        string
	PageID       int
	SourceTaskID string
	URL          string
	Profile      Profile
	Timeout      time.Duration
}

SourceTaskID empty when FK was NULLed via ON DELETE SET NULL; runner then falls back to a run-id-keyed path so the report isn't lost.

type AuditResult

type AuditResult struct {
	PerformanceScore *int
	LCPMs            *int
	CLS              *float64
	INPMs            *int
	TBTMs            *int
	FCPMs            *int
	SpeedIndexMs     *int
	TTFBMs           *int
	TotalByteWeight  *int64
	ReportKey        string
	Duration         time.Duration
}

Metric fields are pointers to distinguish "not produced" from "produced as zero" — Lighthouse occasionally omits metrics on pages it can't audit cleanly.

func ParseReport

func ParseReport(raw []byte) (AuditResult, error)

Missing audits produce nil pointers, preserving the "not measured" semantics of the lighthouse_runs columns. Duration and ReportKey are left zero — the runner stamps them from the outside.

type CompletedTask

type CompletedTask struct {
	PageID       int
	TaskID       string
	ResponseTime int64
}

CompletedTask carries the task fields the sampler needs. ResponseTime is HTTP response time in milliseconds.

type LocalRunner

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

func NewLocalRunner

func NewLocalRunner(cfg LocalRunnerConfig) (*LocalRunner, error)

func (*LocalRunner) Run

At most one retry on a transient Chromium failure detected via stderr substring match.

type LocalRunnerConfig

type LocalRunnerConfig struct {
	LighthouseBin string
	ChromiumBin   string
	Provider      archive.ColdStorageProvider
	Bucket        string
	MemoryShedMB  int
	ProfilePreset Profile // defaults to ProfileMobile if empty
}

type Profile

type Profile string

v1 only schedules mobile; desktop reserved for Phase 5.

const (
	ProfileMobile  Profile = "mobile"
	ProfileDesktop Profile = "desktop"
)

type Runner

type Runner interface {
	Run(ctx context.Context, req AuditRequest) (AuditResult, error)
}

type Sample

type Sample struct {
	Task CompletedTask
	Band SelectionBand
}

func SelectSamples

func SelectSamples(completed []CompletedTask, milestone int, alreadySampled map[int]SelectionBand) []Sample

SelectSamples tops up fastest/slowest quotas to PerBand(len(completed)). alreadySampled is consulted for both dedupe (page never appears twice) and quota accounting (existing band counts subtracted from target). BandReconcile rows count toward dedupe but not quotas. On contention, fastest takes priority over slowest.

type Scheduler

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

func NewScheduler

func NewScheduler(database SchedulerDB, queue TxRunner) *Scheduler

func (*Scheduler) OnMilestone

func (s *Scheduler) OnMilestone(ctx context.Context, jobID string, milestone int) error

At milestone == 100, samples are tagged 'reconcile' so analytics can distinguish opportunistic per-decade picks from the catch-up pass at job completion.

type SchedulerDB

type SchedulerDB interface {
	GetCompletedTasksForLighthouseSampling(ctx context.Context, jobID string) ([]db.CompletedTaskForSampling, error)
	GetLighthouseRunPageBands(ctx context.Context, jobID string) (map[int]db.LighthouseSelectionBand, error)
}

type SelectionBand

type SelectionBand string

SelectionBand identifies which response-time extreme a sample came from. Reconcile is reserved for the 100% pass at job completion.

const (
	BandFastest   SelectionBand = "fastest"
	BandSlowest   SelectionBand = "slowest"
	BandReconcile SelectionBand = "reconcile"
)

type StubRunner

type StubRunner struct{}

StubRunner returns canned metrics without launching Chromium so the schedule → enqueue → record pipeline can be exercised end-to-end.

func NewStubRunner

func NewStubRunner() *StubRunner

func (*StubRunner) Run

type TxRunner

type TxRunner interface {
	ExecuteWithContext(ctx context.Context, fn func(ctx context.Context, tx *sql.Tx) error) error
}

Jump to

Keyboard shortcuts

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