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
- func AllowPrivateTargets() bool
- func BrowserMode() string
- func BrowserWakeChannel() <-chan struct{}
- func EffectiveTimeout(check *models.SyntheticCheck) time.Duration
- func ExecuteOnce(ctx context.Context, now time.Time)
- func PlaywrightDir() string
- func ProcessOutcome(ctx context.Context, run *models.CheckRun, claimedBy string, outcome Outcome)
- func RegisterNotifier(fn NotifierFunc)
- func RunExpiry(scheduledFor time.Time, intervalSeconds int) time.Time
- func ScheduleOnce(ctx context.Context, now time.Time)
- func Start(ctx context.Context)
- func Wake()
- type HealthStats
- type NotifierFunc
- type Outcome
- type StateTransition
Constants ¶
const ( BrowserModeOff = "off" BrowserModeEmbedded = "embedded" BrowserModeRemote = "remote" )
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 ¶
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 ¶
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 ScheduleOnce ¶
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.
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).
Source Files
¶
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). |