The 5-minute lookback is a server flag, --query.lookback-delta. Since Prometheus 3.0 a window is open on its left: a sample exactly on the left edge is left out. A [1m] window at a 15-second interval therefore holds at most 4 samples, never 5.
An instant query, /api/v1/query, evaluates an expression at one time. A range query, /api/v1/query_range, takes start, end and step, evaluates the same expression at every step and returns one line per series. That is what a graph is. A subquery does the same inside an expression. max_over_time(sum(rate(http_requests_total{job="checkout"}[1m]))[10m:15s]) evaluates the inner sum every 15 seconds for 10 minutes and keeps the largest result: 16.04 here, from 1,600 samples read.
offset 1h moves a selector back an hour. @ pins it to a Unix time, or to the edges of a range query with @ start() and @ end(). Durations use the units ms, s, m, h, d, w and y. A # starts a comment.
More functions worth recognising: delta and idelta (the gauge versions of increase and irate), changes and resets (how often a value changed or fell), absent_over_time, label_replace and label_join (rewrite the labels of a result), clamp_min, round and sort_desc. limitk and limit_ratio are experimental aggregators that return a sample of the series. The flag --query.max-samples caps how many samples one query may load into memory.
ON THE EXAM
- “type a selector returns” → instant vector
- “type metric[5m] returns” → range vector
- “can a range vector be graphed” → no
- “per-second average increase of a counter” →
rate - “uses the last two samples” →
irate, for graphs of fast-moving counters - “total growth over the window” →
increase - “handle counter resets” →
rate, irate and increase all do - “order of rate and sum” →
rate first, then sum - “slope or forecast of a gauge” →
deriv, predict_linear - “keep only these labels” →
by - “drop these labels” →
without - “the 3 largest series” →
topk(3, …) - “average of a gauge over 5 minutes” →
avg_over_time(x[5m]) - “how old may a sample be for an instant selector” → 5 minutes
- “the value an hour ago” →
offset 1h