Skip to content

fix(data_plane): read query times as RFC 3339 too, as the Prometheus API does - #868

Merged
zzylol merged 3 commits into
feat/tiered-view-storagefrom
fix/prometheus-time-params
Nov 24, 2026
Merged

zzylol merged 3 commits into
feat/tiered-view-storagefrom
fix/prometheus-time-params

Conversation

@zzylol

@zzylol zzylol commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: the data plane answered /api/v1/query and /api/v1/query_range from its plan only when time, start and end were Unix seconds. RFC 3339 times, which the Prometheus HTTP API allows and vmalert sends (for example time=2026-11-24T05:00:00Z), were forwarded to the fallback instead.
  • Change: time, start and end are parsed the way Prometheus' parseTime does:
    • Unix seconds with an optional fraction;
    • otherwise RFC 3339 with optional fractional seconds and a Z or ±hh:mm offset.
    • A value in neither form gets Prometheus' 400: invalid parameter "time": cannot parse "x" to a valid timestamp.
  • Effect: an RFC 3339 instant or range query is answered from the plan, with the same answer as its Unix-seconds form. A rule evaluator no longer needs a proxy that rewrites the time.

Review guide

  • Base: feat/tiered-view-storage, the demo branch.
  • Read first: parse_time_ms and rfc3339_ms in data_plane/src/prometheus.rs, then the two parse functions that call them.
  • Mechanical:
    • BadTime and BadRange become one BadParameter;
    • the no_forward messages in lib.rs now also name Prometheus' min and max times.

Behavior: before → after

The query sum(sum_over_time(data[1m])) is planned every 10 s over data.

request before after
/api/v1/query?time=120 answered from the plan same
/api/v1/query?time=1970-01-01T00:02:00Z forwarded to the fallback (with --no-forward: 422 "no query parameter") answered from the plan, identical body to time=120
time=1970-01-01T01:02:00+01:00, .000000000Z, -00:30 offsets forwarded answered, identical
/api/v1/query_range?start=1970-01-01T00:02:30Z&end=180&step=10 forwarded answered, identical to start=150
time=yesterday, 1970-13-01T00:00:00Z, no zone, space instead of T forwarded 400 bad_data, invalid parameter "time": cannot parse "yesterday" to a valid timestamp
time= (empty) forwarded evaluated now, as Prometheus does
Prometheus' min/max time strings forwarded forwarded (the plan does not evaluate at them)

This serves the 4-system demo: the rule evaluator's queries are answered by the data plane, not the fallback.

Interfaces

data_plane/src/prometheus.rs

-/// Why an instant query's parameters are refused (400, bad_data).
-pub struct BadTime(pub String);
-/// Why a range query's parameters are refused (400, bad_data).
-pub struct BadRange(pub String);
+/// Why a query's parameters are refused (400, bad_data): the error text.
+pub struct BadParameter(pub String);
 impl InstantQuery {
-    pub fn parse(url_query: Option<&str>, form: &[u8]) -> Result<Option<Self>, BadTime>;
+    /// Reads query and time (empty or missing: now); Ok(None) when query is missing or
+    /// time is Prometheus' min or max time (forwarded).
+    pub fn parse(url_query: Option<&str>, form: &[u8]) -> Result<Option<Self>, BadParameter>;
 }
 impl RangeQuery {
-    pub fn parse(url_query: Option<&str>, form: &[u8]) -> Result<Option<Self>, BadRange>;
+    pub fn parse(url_query: Option<&str>, form: &[u8]) -> Result<Option<Self>, BadParameter>;
 }
+/// Query parameter name's time in ms since the epoch, as Prometheus reads it: Unix
+/// seconds, else RFC 3339; Ok(None) for Prometheus' min/max time; Err is the 400 text.
+pub fn parse_time_ms(name: &str, text: &str) -> Result<Option<i64>, BadParameter>;

The two error types were merged because both had become identical string wrappers.

Usage: a rule evaluator sends GET /api/v1/query?query=sum(sum_over_time(data[1m]))&time=2026-11-24T05:00:00Z. InstantQuery::parse → parse_time_ms("time", ..) gives Some(1_795_496_400_000). The engine evaluates the plan at that time, and the response carries x-asap-execution: plan.

Algorithm changes

Query time parsing.

  • Before: text.parse::<f64>(), otherwise forward.
  • After:
    1. Prometheus' min/max time strings are forwarded.

    2. A float is taken as seconds: whole seconds plus the fraction rounded to the millisecond, as Prometheus' Modf + Round.

    3. Otherwise rfc3339_ms reads the form Go's time.Parse(time.RFC3339Nano, ..) accepts:

      • four-digit year, T, a one- or two-digit hour;
      • a ./, fraction of any length, truncated to the millisecond as Prometheus truncates a parsed time;
      • Z or an offset of at most 24 h / 60 min;
      • day-of-month checked with leap years; seconds 0–59.

      Days since the epoch come from Hinnant's civil-date algorithm.

    4. Otherwise 400, with Prometheus' text.

  • Correctness:
    • Unit test parses_rfc3339_times: epoch-ms constants were computed independently, and it covers Go's lenient forms and rejected forms.
    • Integration test time_params.rs: answers match across forms.
  • Limits: these follow Go rather than Rust where the two differ, and may still differ from Prometheus in two places:
    • error-text quoting of control characters (Rust {:?} vs Go %q);
    • hex floats, which Go's ParseFloat accepts.

Decisions and open questions

  • Needs reviewer decision: None.
  • Decided: min/max time strings are forwarded, not refused, because the plan never evaluates at them.

Verification

scope result newly failing vs base notes
cargo test -p data_plane --test time_params 3 passed — new; the first two failed on the base (RFC 3339 → 422 "no query parameter" under --no-forward)
cargo test -p data_plane --lib prometheus:: 7 passed 0 parses_rfc3339_times new; two expectations updated (RFC 3339 now parsed)
server, range_queries 10 / 4 passed 0
cargo fmt --check, cargo clippy -p data_plane --all-targets -D warnings clean

New tests:

  • rfc3339_times_are_answered_from_the_plan_like_unix_seconds: instant and range queries in RFC 3339 forms are answered from the plan with the same body as the Unix-seconds form.
  • times_in_neither_form_are_refused_as_prometheus_refuses_them: 400 with Prometheus' text for time, start and end.
  • prometheus_min_and_max_times_are_not_answered_from_the_plan: the two special strings are not refused as unparsable.

Follow-ups

@zzylol zzylol added area: data plane Runtime ingestion, storage, and query-serving data paths bug Something isn't working feature: PromQL PromQL compatibility and execution semantics labels Nov 24, 2026
…API does

time, start and end were read only as Unix seconds; anything else, such as
the RFC 3339 times vmalert sends, was forwarded instead of answered from the
plan. They are now parsed as Prometheus parses them (Unix seconds with an
optional fraction, or RFC 3339 with optional fractional seconds and a zone
offset), and a time in neither form gets Prometheus' 400.
An empty time is now; Prometheus' min and max times are forwarded; Go's
lenient RFC 3339 forms are accepted; a numeric fraction is rounded on its
own, as Prometheus rounds it; one BadParameter error type.
@zzylol
zzylol force-pushed the fix/prometheus-time-params branch from d19ea6b to 28cdc8f Compare November 24, 2026 15:04
@zzylol
zzylol marked this pull request as ready for review November 24, 2026 15:05
@zzylol
zzylol merged commit 5daf770 into feat/tiered-view-storage Nov 24, 2026
1 check passed
zzylol added a commit that referenced this pull request Nov 24, 2026
…, label columns, RFC 3339 times, format 4 (#871)

Ports #865, #869, #868 and #866 from the tiered-view-storage branch to main: a read-back view window is charged its own bytes; label text columns are rebuilt from the series identity; query times are read as Unix seconds or RFC 3339; view fragments are compact and zstd-compressed (view file format 4; formats 2 and 3 are set aside at startup). Tests adapted to main's APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: data plane Runtime ingestion, storage, and query-serving data paths bug Something isn't working feature: PromQL PromQL compatibility and execution semantics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant