Skip to content

fix(monit-query): normalize raw-mode time args for loki/victorialogs - #144

Merged
ysyneu merged 1 commit into
mainfrom
fix/victorialogs-raw-time-parity
Aug 12, 2026
Merged

fix(monit-query): normalize raw-mode time args for loki/victorialogs#144
ysyneu merged 1 commit into
mainfrom
fix/victorialogs-raw-time-parity

Conversation

@ysyneu

@ysyneu ysyneu commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Problem

monit-query rows's raw-mode time window is supplied via free-form --args <ds-type>.start / <ds-type>.end entries, forwarded to the server verbatim with no client-side parsing. The raw query path requires unix-seconds strings and rejects anything else with invalid <ds-type>.start: <value> (400). The stats path, by contrast, silently ignores these keys entirely and always uses the current time — so the same value that appears to "work" under stats mode (because it's never even inspected) fails once raw mode actually validates it. Users have to know to convert their timestamp to unix seconds by hand for raw mode, an inconsistency within a single command.

Fix

  • Add normalizeRawTimeArgs, applied uniformly to every monit-query rows call for the loki/victorialogs ds-types (the two that consume this args contract): it converts <ds-type>.start/<ds-type>.end to unix seconds before the request is sent, reusing timeutil.Parse — the same helper diagnose's --time-start/--time-end already uses. No per-mode forking: raw and stats both go through the same normalization; stats simply ignores the (now-normalized) keys as before.
  • timeutil.Parse gains explicit unix-millisecond support: a numeric value only plausible as milliseconds (i.e. it would be seconds past the year 5138) is now divided down instead of passed through unchanged.
  • Updated --args, --time-start, and --time-end help text to document the accepted formats (relative duration, now, date/RFC3339, unix seconds or milliseconds).

Testing

  • internal/timeutil: new cases for millisecond timestamps and the seconds/milliseconds magnitude boundary.
  • internal/cli: new normalizeRawTimeArgs unit tests covering RFC3339 (with/without offset), unix seconds, unix milliseconds, the loki prefix, non-loki/victorialogs ds-types (untouched), unrelated arg keys (untouched), and invalid input. A monit-query rows end-to-end test asserts the outgoing raw-mode request carries unix-seconds victorialogs.start/.end when given RFC3339 input.
  • make check (fmt, lint, test -race, build) — all green.
  • make check-cards — no generated-card drift (help text isn't part of the generated fence).

monit-query rows' raw-mode time window is passed as free-form
--args <ds-type>.start / <ds-type>.end strings, forwarded to the server
without any client-side parsing. The raw query path requires unix
seconds and rejects any other format, while the stats path silently
ignores these keys entirely — so a value that appeared to work under
stats mode would 400 once raw mode actually validated it.

Add normalizeRawTimeArgs to convert <ds-type>.start/.end into unix
seconds before the request is sent, for the loki and victorialogs
ds-types that consume this args contract. It reuses timeutil.Parse,
the same helper already used for diagnose's --time-start/--time-end,
so relative durations, dates, RFC3339 (with or without an offset),
and unix seconds are all accepted uniformly across both commands.

timeutil.Parse also gains unix-millisecond support: a bare numeric
value that would only be a plausible unix-seconds timestamp past the
year 5138 is now treated as milliseconds and divided down, rather than
passed through as seconds.

Updated --args, --time-start, and --time-end help text to document the
accepted formats.
@ysyneu
ysyneu merged commit 70156e7 into main Aug 12, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant