synthetics

package
v1.9.13 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package synthetics runs scheduled synthetic checks (http, tcp, browser) from a durable queue in the main DB. The scheduler enqueues due runs, the in-process executor claims and probes, and results land in the telemetry check_results table. Modeled on the notification outbox: guarded status transitions, stale-claim reclaim, advisory-locked ticks. Unlike the outbox there is no retry/backoff — a failed probe IS a result — and terminal queue rows are deleted; expired queued runs are recorded as missed, never executed late.

Index

Constants

View Source
const (
	BrowserModeOff      = "off"
	BrowserModeEmbedded = "embedded"
	BrowserModeRemote   = "remote"
)
View Source
const (
	MinIntervalSeconds       = 30
	DefaultTimeoutSeconds    = 30
	MaxTimeoutSeconds        = 120
	MaxBrowserTimeoutSeconds = 120
)

Browser execution limits; validation clamps to these.

Variables

This section is empty.

Functions

func AllowPrivateTargets

func AllowPrivateTargets() bool

func BrowserMode

func BrowserMode() string

BrowserMode returns the validated SYNTHETICS_BROWSER_MODE, defaulting to off.

func BrowserWakeChannel

func BrowserWakeChannel() <-chan struct{}

BrowserWakeChannel is drained by the runner long-poll endpoint so a freshly queued browser run answers a waiting runner immediately.

func EffectiveTimeout

func EffectiveTimeout(check *models.SyntheticCheck) time.Duration

EffectiveTimeout clamps a check's timeout to sane bounds.

func ExecuteOnce

func ExecuteOnce(ctx context.Context, now time.Time)

ExecuteOnce claims and executes every currently claimable run class this instance handles. Exported so tests can drive the executor deterministically.

func PlaywrightDir

func PlaywrightDir() string

PlaywrightDir is the harness directory holding node_modules with @playwright/test (baked into the :browser image, or operator-provided).

func ProcessOutcome

func ProcessOutcome(ctx context.Context, run *models.CheckRun, claimedBy string, outcome Outcome)

ProcessOutcome finalizes one executed run. Order matters: the main-DB transaction (state transition + incident + run-row delete) commits FIRST, then the telemetry insert, then the notify hook. A crash between the two DB writes loses one result row (an uptime gap), which is benign; the reverse order would re-execute after reclaim and double-apply the state transition. The notify hook runs with no transaction held: it opens its own, and the SQLite main DB has a single connection.

func RegisterNotifier

func RegisterNotifier(fn NotifierFunc)

func RunExpiry

func RunExpiry(scheduledFor time.Time, intervalSeconds int) time.Time

RunExpiry computes when a queued run stops being worth executing.

func ScheduleOnce

func ScheduleOnce(ctx context.Context, now time.Time)

ScheduleOnce runs a single scheduler tick: reclaim stale claims, expire overdue queued runs as missed, enqueue due checks, advance their next_run_at. Exported so tests can drive the scheduler deterministically.

func Start

func Start(ctx context.Context)

Start runs the scheduler and the in-process executor.

func Wake

func Wake()

Wake nudges the executor loops (and any waiting remote-runner long-poll) to look for claimable runs without waiting for the next tick. Call after the enqueueing transaction commits.

Types

type HealthStats

type HealthStats struct {
	BrowserMode        string `json:"browserMode"`
	QueuedRuns         int    `json:"queuedRuns"`
	ClaimedRuns        int    `json:"claimedRuns"`
	OldestQueuedAgeSec int64  `json:"oldestQueuedAgeSec"`
	ChecksDown         int    `json:"checksDown"`
	RunnersOnline      int    `json:"runnersOnline"`
	ExecutedTotal      uint64 `json:"executedTotal"`
	MissedTotal        uint64 `json:"missedTotal"`
}

func HealthSnapshot

func HealthSnapshot() (*HealthStats, error)

HealthSnapshot powers /api/health/deep. OldestQueuedAgeSec measures from scheduled_for, so a healthy queue shows near-zero even under load.

type NotifierFunc

type NotifierFunc func(transition StateTransition)

NotifierFunc is implemented by the notifications package and registered in cmd/run.go; the indirection avoids an import cycle.

type Outcome

type Outcome struct {
	Status           string // models.CheckResultUp or models.CheckResultDown
	LatencyMs        float64
	StatusCode       int
	ErrorMsg         string
	ScreenshotKey    string
	OutputKey        string
	TlsDaysRemaining int
	ExecutedBy       string
	ExecutedAt       time.Time
}

Outcome is one executed probe's result, produced by the in-process runners or posted by a remote runner.

type StateTransition

type StateTransition struct {
	Check    models.SyntheticCheck
	From     string
	To       string
	ErrorMsg string
	At       time.Time
}

StateTransition describes a check crossing up<->down, delivered to the notify hook AFTER the state transaction commits (the hook opens its own transactions; calling it with one held would deadlock the single-connection SQLite main DB).

Directories

Path Synopsis
Package browserexec runs @playwright/test specs by spawning Node against a prepared harness directory (package.json + node_modules with a pinned @playwright/test).
Package browserexec runs @playwright/test specs by spawning Node against a prepared harness directory (package.json + node_modules with a pinned @playwright/test).

Jump to

Keyboard shortcuts

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