Time
PartialEverything else in the pipeline is push-driven: a sample arrives, and something reacts. Time is the one input that arrives as nothing. “Ten minutes have passed”, “it is 8am on Monday” and above all “the data has stopped” produce no inbound message, so nothing would ever react to them unless the platform manufactures the reaction itself. This page covers how the server does that today, the rules every stored instant follows, and the one primitive that is to replace today’s separate loops.
Today: a loop per job
Section titled “Today: a loop per job”Time-driven work runs as independent loops on each server, each a goroutine with its own interval and
its own deadline per pass. Every one keeps its state in Postgres rows, so a restart loses nothing, and
every queued job is taken FOR UPDATE SKIP LOCKED, so replicas share the work without doing any of it
twice.
| loop | every | what time passing does |
|---|---|---|
| event rule sweep, with command settlement | 5 s | fires or clears a rule whose sustain has run out on an input that reports only on change; settles or times out commands |
| rule reconcile | 1 min | re-judges each rule’s newest sample, and every trend rule’s window, healing a missed decision |
| calc tick | 1 s | drains pending calc rule marks, and marks owners whose windowed input has aged out |
| notification tick | 2 s | sends due notifications and their retries, and ends expired snoozes, announcing an alarm still raised |
| outpost check-in age | 15 s | writes each claimed outpost’s checkin-age, which outpost-silent reads |
| sweep ages | 10 s | writes each server’s rule-sweep-age, which rule-sweep-stalled reads |
| sample retention | 1 h | drops and summarizes what has passed its window (storage) |
The pattern that makes absence visible is the age: rather than a timer that fires when something
stops, a loop writes how long it has been since something happened, as an ordinary metric, and an
ordinary event rule fires when the age passes a line. outpost-silent (a check-in older than 90 s) and
rule-sweep-stalled (a sweep older than 30 s) are built that way, so silence raises an alarm through
the same machinery as any other signal.
A sustain is timed by the server’s receipt of each sample, never by the sample’s own timestamp, so an outpost whose clock runs behind neither skips nor stretches a sustain. Which sample is newest is still decided by its timestamp.
Instants and timezones
Section titled “Instants and timezones”Every stored instant is a timestamptz: UTC, aware of its zone. A sample’s ts is the producer’s
clock; the server stamps its own receipt where that matters (a sustain, a batch receipt).
A metric’s timestamp is whole milliseconds
Section titled “A metric’s timestamp is whole milliseconds”A metric sample’s ts carries no digits below the millisecond, on metric and metric_declared, from
the outpost to the stored row (#1526):
- The outpost truncates every metric sample’s
tsto the millisecond as a batch leaves its spool, so no probe or driver has to remember to. - The ingest truncates again before the row lands, rather than refusing, so a spool replayed from an older outpost lands instead of failing its batch.
The reason is the clock, not the storage. An outpost’s clock is NTP-synced to a few milliseconds, so
microsecond digits are noise, and a raw row and the compacted block that later holds it (millisecond
offsets, #1265) then agree exactly. Two samples of one series may land in the same instant: there is no
unique key on (series_id, ts) (ADR-0061), and ids tell them apart. The
property, event and log lanes keep their timestamps as sent.
Storage
Section titled “Storage”Time has no table of its own today: each loop’s state is the row it works on (a streak, a calc mark, a notification, a snooze), on that subsystem’s page. The clock adds two tables, laid out on storage.