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 ¶
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.
var ErrRunnerNotImplemented = errors.New("lighthouse local runner not implemented yet")
Functions ¶
func PerBand ¶
PerBand uses Floor not Round so 10,000 pages lands exactly on the cap rather than overshooting it.
func SanitiseAuditURL ¶
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 ¶
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 ¶
func (l *LocalRunner) Run(ctx context.Context, req AuditRequest) (AuditResult, error)
At most one retry on a transient Chromium failure detected via stderr substring match.
type LocalRunnerConfig ¶
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
type SchedulerDB ¶
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 ¶
func (s *StubRunner) Run(ctx context.Context, req AuditRequest) (AuditResult, error)