fix(monit-query): normalize raw-mode time args for loki/victorialogs - #144
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
monit-query rows's raw-mode time window is supplied via free-form--args <ds-type>.start/<ds-type>.endentries, forwarded to the server verbatim with no client-side parsing. The raw query path requires unix-seconds strings and rejects anything else withinvalid <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
normalizeRawTimeArgs, applied uniformly to everymonit-query rowscall for theloki/victorialogsds-types (the two that consume this args contract): it converts<ds-type>.start/<ds-type>.endto unix seconds before the request is sent, reusingtimeutil.Parse— the same helperdiagnose's--time-start/--time-endalready uses. No per-mode forking: raw and stats both go through the same normalization; stats simply ignores the (now-normalized) keys as before.timeutil.Parsegains 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.--args,--time-start, and--time-endhelp 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: newnormalizeRawTimeArgsunit tests covering RFC3339 (with/without offset), unix seconds, unix milliseconds, thelokiprefix, non-loki/victorialogs ds-types (untouched), unrelated arg keys (untouched), and invalid input. Amonit-query rowsend-to-end test asserts the outgoing raw-mode request carries unix-secondsvictorialogs.start/.endwhen 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).