Skip to content

Time

Partial

Everything 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.

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.

loopeverywhat time passing does
event rule sweep, with command settlement5 sfires or clears a rule whose sustain has run out on an input that reports only on change; settles or times out commands
rule reconcile1 minre-judges each rule’s newest sample, and every trend rule’s window, healing a missed decision
calc tick1 sdrains pending calc rule marks, and marks owners whose windowed input has aged out
notification tick2 ssends due notifications and their retries, and ends expired snoozes, announcing an alarm still raised
outpost check-in age15 swrites each claimed outpost’s checkin-age, which outpost-silent reads
sweep ages10 swrites each server’s rule-sweep-age, which rule-sweep-stalled reads
sample retention1 hdrops 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.

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 ts to 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.

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.