A cluster vmselect answers label values with isPartial when a storage
node does not respond, and the list it returns misses that node's
names. Scoping the query to it would drop those pods' series without a
word, which the lookup exists to prevent, so a partial list now fails
the request as any other failed lookup does.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Application roots take two access reviews before any body is read; a
POST to either must answer 503 within the request timeout when
kube-apiserver stalls on them.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The reason given for the second access review held only for the metrics
root. The log root needs it too, because an ownerless pod keeps the
lineage labels its creator set and can claim any application. The
tenant ClusterRole comment also named only the namespace roots, though
the application roots now depend on the same rule.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
An instant query without time had its application lookup sized at the
proxy's clock, but the time was not forwarded, so vmselect evaluated at
its own later clock. With lookups taking most of the request deadline,
the evaluation lands well past the end of the lookup and leaves out pods
first sampled in between. Forward the instant the lookup was sized for.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The string tracking treated a backslash inside backquotes as literal,
but metricsql's scanString lets a backslash escape the closing quote
in all three quote kinds, and a quoted label name keeps that escape
({`\``=""} parses). The proxy ended such a string early, read the rest
of the query as string content, and accepted an escaped
rollup_candlestick after it with the lookup ending too soon.
Inside any quote a backslash now skips the next character, as
scanString does, and the comment no longer claims metricsql refuses
an escaped backquote.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The second latency offset was added to the application lookup only,
so the other readers of the instant query's earliest read still
assumed time minus 30s: the store choice could send a query to the
short-term store up to 30 seconds too late near its retention edge,
the lookback cap compared against a start the lookup no longer used,
and the field no longer meant the earliest instant read.
The earliest read of an instant query now starts from time minus two
latency offsets, the earliest instant vmselect can evaluate it at, and
the lookup uses it as is.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The escape check tracked string literals but not comments: in
metricsql a "#" outside a string comments out the rest of the line, so
a quote inside a comment made the check treat the next line's code as
string content, and rollup\_candlestick there was accepted again. The
bracket and offset scans do not understand comments either.
A "#" outside a string now makes the lookahead unknown as well, which
answers 422 on the application root, rather than teaching every scan
about comments; API clients do not send them.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect evaluates an instant query whose time is within 30s of its
own clock at that clock minus 30s (queryOffset in prometheus.go), not
at time minus 30s. For a time slightly in the future the evaluation
starts earlier than the proxy assumed: time=now+29s with a 1s step
read from six minutes before, while the lookup started at five
minutes 32 seconds, and pods present only in that gap were missing
from a 200.
The evaluation instant is always within (time-60s, time], so the
lookup of an instant query now starts one more latency offset early.
That needs no assumption about the proxy's clock matching vmselect's.
The store choice on the namespace root is left as it is.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
metricsql unescapes identifiers (unescapeIdent in parser.go), so
rollup\_candlestick(x + y) is rollup_candlestick to vmselect while the
lexical scan saw another name: the lookup ended ten minutes past the
evaluation time and vmselect read nearly thirteen. Any escaped keyword
the scan looks for, offset included, had the same hole. A backslash
outside a string literal now makes the scan unknown, which answers 422
on the application root; escapes inside label values are unaffected.
With rollup_candlestick refused, two steps per "(" stay enough: a
subquery evaluates at most one step past its end plus the alignment of
that end to the step (evalRollupFuncWithSubquery), and the one step a
candlestick over a non-selector would add on top cannot occur.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
metricsql also reads a trailing $__interval as part of an offset's
duration: offset -1h$__interval is -(1h + step). The scan stopped at
the "$" and read one hour, so the lookup missed pods created in the
last step and the query answered 200 without them. Refusing a minus
alone left every other continuation open.
Only what certainly ends the duration token is now accepted after it:
whitespace, a closing bracket or separator, or a binary operator other
than minus; anything else answers 422 on the application root. The
grammar comment no longer claims upper-case offset units are refused,
as offsets are scanned lower-cased like metricsql reads them.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Since the lookup reaches subquery steps past the evaluation time, the
applicationScope comment still described only negative offsets, and a
query refused for a subquery step the scan cannot read got a 422 that
listed every other cause but that one.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The subquery sizing was tested only as "at least two hours", so which
step drives it, the fallback to the query step for an empty subquery
step, and its refusals (an unreadable step, an unclosed bracket, a sum
past the duration range) were not held by any test.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Telling a compound duration from a subtraction by a duration-part
pattern missed forms metricsql accepts after the minus: offset 5m-1.h
is 55 minutes forward and offset 5m-.5h is 25, yet both read as five
minutes back, and the lookup silently missed pods created in between.
A pattern that followed scanSingleDuration exactly would still be a
second copy of the grammar to keep in step, so any minus right after
an offset's duration is refused again; offset 1h-1 and offset 5m-y now
answer 422 as well, and metricsql cannot parse the latter anyway.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The compound-offset refusal took any minus right after an offset's
duration for a compound, so x offset 1h-1 or x offset 5m-y answered
422. metricsql continues a duration token only with a minus followed
by a duration part (scanSingleDuration), so only that form is refused
now; anything else is the subtraction it is.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect evaluates a subquery up to its end plus one subquery step,
rounded up to the step (evalRollupFuncWithSubquery in
app/vmselect/promql/eval.go), and range_* transforms (setLastValues)
and keep_next_value carry those later values back onto earlier points.
A series that starts after the evaluation time, such as a pod created
within that reach, can therefore appear in the answer, which the
earlier claim that only rollup_candlestick reads ahead missed. The
lookup stopped at the evaluation time and left such a pod out of a 200.
The lookahead now adds two steps per subquery level, counting every
"(" as a possible implicit subquery and using the largest step seen,
as the lookback already does. Overreaching only widens the lookup over
the application's own pods.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect evaluates rollup_candlestick one step ahead of the evaluation
time, with no offset in the query: evalRollupFuncWithoutAt adds the
step in effect to the window's start and end (app/vmselect/promql/
eval.go in v1.136.0-cluster, unchanged in v1.139.0). The lookahead
scan returned zero for it, so the lookup stopped at the evaluation time
and pods created during that step were left out of a 200.
The step in effect is the subquery's when the call is nested, so
rather than size it the application root answers 422. No other
function reads ahead: the subquery evaluation past its end in
evalRollupFuncWithSubquery is outside the outer rollup's window.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The offset scan read a duration up to its first sign and ignored the
rest. metricsql lexes 1h-30m as one duration and DurationValue makes
every part after the first negative one subtract, so offset -1h-30m
shifts samples 90 minutes forward while the scan covered 60, and
offset 1h-2h shifts them an hour forward while the scan counted it as
looking back. The pod and PVC lookup then missed pods created in the
gap and the query answered 200 without them.
A duration followed directly by a minus now makes the scan unknown,
which answers 422 on the application root. A plus or a spaced sign is
an operator after the offset in metricsql, not part of it, and is
still read.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The refusal named only the @ modifier and non-literal offsets, but the
same answer covers an @ inside a label value and WITH with a negative
offset, so a client could not tell why such a query was refused.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The series-limit refusal of a lookup reached the client with all of
cluster vmselect's wrapping, and that context can name vmstorage
nodes, the leak the generic 502 had just closed for other errors. The
client now gets the message from the limit on.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
A store error other than the series limit was built into the lookup's
502 message, and that text can name vmstorage nodes and addresses.
The handler happened to replace the message before it reached the
client, but nothing held it there. The text now goes to the log only.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The lookahead scan let @ start() and @ end() through and the 422 named
them as allowed, but the lookback scan cannot bound any @, so every @
query was refused anyway, with a message pointing at forms that would
not pass. Both scans now treat any @ as unknown and the message says
so. The lookback-cap test now exercises the cap with a window just past
it rather than an @ query.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The lookup now passes a 504 from the store through, where it used to
answer 502, but only the 504 read from a 422 body was tested.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect answers 422 to every error that carries no status of its own,
its query timeout and storage failures included, so passing every
lookup 422 through told the client to narrow a window when the store
was failing, and bypassed the 504 for a missed deadline.
Only vmselect's series-limit message stays a 422, with the message
taken from its JSON answer; its timeout becomes 504 and anything else
502. The request deadline is checked before the store's status.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
With the lookback refusal, the 24h default turned common application
queries into 422: a day's increase, and month-long panels at the step
a dashboard picks for them. The lookback estimate is a loose upper
bound, made for the store choice, and counts every "(" as an implicit
subquery, so it far exceeds what such queries read.
The lookback is only the refusal threshold, since the lookup itself
spans the window the query reads, so its default now matches
--metrics-max-range. The chart passes it from values, so an operator
can tune it.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect answers 422 when a label lookup exceeds its own series
limits. The application root turned that into a 502, which reads as a
broken store, while the client could have fixed it by narrowing the
window. The 422 and vmselect's message now reach the client.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The pod and PVC lookup never started earlier than --metrics-app-lookback
before the window. A query that read further back, such as rate(x[7d])
with the 24h default, or whose lookback is unknown (an @ modifier, WITH,
a step-multiple window), answered 200 without the series of pods that
existed only before the lookup start.
Such queries now answer 422 on the application root, matching how a
query whose latest sample cannot be covered is handled; the namespace
root has no lookup and still serves them.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Only a deadline hit before the lookup's response headers was reported
as 504. When the store sent its headers and then stalled, the deadline
expired while the body was decoded, and the decode error came back as
a generic 502, so a slow store looked like a broken one.
The request deadline is now checked whichever step of the lookup it
cut, and both cases are covered by a test.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect rounds a range query's end up to a whole step before
evaluating it, so the last point can read samples up to one step past
the end the client sent. The pod and PVC lookup stopped at that end
and could miss a pod created within the last step.
The lookup end of a range query now adds one step.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
When the pod or PVC lookup failed, its branch was dropped and the
query still answered 200, without the cAdvisor and volume series of
the application, so a store error showed up as an empty graph. That
is the same silently incomplete answer that a lookup over its cap is
refused for.
A failed lookup now fails the request: 504 when the store missed the
deadline, 502 otherwise.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Reviews was inserted between ResourceAttributes and its doc comment,
so go doc showed the ResourceAttributes text on Reviews, and that text
still called it the single review a route needs, which application
roots no longer are.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The pod and PVC lookup of the application metrics root ended at the
evaluation time, but a negative offset reads samples after it. An
instant query evaluated two hours ago with "offset -1h" reads samples
from one hour ago, so a pod created in between was missing from the
scope and its series were dropped while the request succeeded.
The lookup now ends at the latest instant the query reads, its window
end plus the sum of its negative offsets. A query whose latest sample
cannot be bounded, an @ modifier other than start() or end() or an
offset that is not a plain duration, is refused with 422 on the
application root; the namespace root has no lookup and still serves
it.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The application roots asked only for the application subresource. Their
pod and PVC branches select by namespace and name across the whole
lookup window, so a caller granted only application "a" received the
older series of application "b" whenever "b" had used one of the same
pod or PVC names. The lineage labels the scope rests on can also be set
by whoever creates an unowned pod.
Until the scope carries application identity on every branch, the
application roots also require read access to the namespace root, the
same review the namespace root asks. Every tenant role that reads
applications already holds it, so no current grant loses access; a
grant narrowed by resourceNames alone is refused instead of trusted.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The store cuts a lookup at the cap plus one value. Dropping empty
values first could bring such a cut list back under the cap and serve
it as complete, hiding the application's other pods without the 422
that asks for a shorter range.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
An empty name in a lookup answer would turn the pod branch into a
pattern that matches every series without a pod label, widening the
application scope to the namespace; nothing pinned the guard against
it. Malformed answers must only drop their branch, and the lookup must
start at the query's own lookback, or at the configured limit when that
lookback is unknown.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Graphs of one application need its series without the caller knowing
which pods and volumes it ran on. Exporter series carry the identity
the scrape class stamps, but cAdvisor and kubelet volume series do not,
so the scope ORs three branches: the identity, and the application's
pods and PVCs as kube-state-metrics labelled them over the window. Each
branch also carries the namespace, so the scope is never wider than the
namespace root.
The lookup reaches back by the query's own lookback, bounded by a flag,
so pods replaced inside an expression's range still count. A failed
lookup only drops its branch. A list over its cap answers 422 instead
of being truncated, which would hide series without saying so.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
A viewer of one application gets that application's lines without
writing a namespace query and filtering by hand, and a grant narrowed to
one application by resourceNames is honoured on every logs endpoint,
tail and the pickers included. The namespace filter stays and the
application's identity is ANDed next to it as a second stream filter,
so the result can only be narrower than the namespace root.
The plural is mapped to its kind only after the caller is authorized,
so an anonymous client cannot probe which applications exist, and the
proxy is not ready until the ApplicationDefinitions cache is.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Paths and RBAC name an application by its plural, while the lineage
labels that scope its logs and series carry the kind. The mapping comes
from ApplicationDefinitions, kept in one place so both application roots
scope by the same kind. A plural declared for two kinds is refused
rather than resolved by cache order.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The metrics handler shares the bounded review calls with the logs
handler; a POST to it with an unread body must answer 503 as well
rather than wait on a stalled kube-apiserver.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
staticcheck flags the negated disjunctions; naming the duration
characters and spelling out both word boundaries reads the same way the
rule is stated.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Only the upper half of the refused 1970..2262 range had a test, so
the lower check could be dropped unnoticed. vmselect clamps a time
before 1970 to 0, which would answer for a window other than the one
asked for.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Times went to vmselect as "%d.%03d" unix seconds. vmselect reads a
number without "-" as a unix time whose unit it guesses from its size,
so a time in the first 24.8 days of 1970 arrived as a thousand times
as many seconds: a window the proxy checked as 8.8 days and 30 points
reached vmselect as 2001..2025 and 30000 points, and the label and
series APIs, which have no points check, scanned the whole retention.
Times past 2038 were read as microseconds.
Times now go out as RFC3339 with milliseconds, which vmselect parses
as a date and never as a guessed unit, and times outside 1970..2262,
which vmselect cannot hold as nanoseconds, are refused. A test repeats
vmselect's parsing of the exact strings the proxy sends.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The metrics slow-body and stalled-client tests probed the slot with
requests of their own, which competed for the one slot under test and
made them fail at random, under one shuffle seed reliably. They now
read the limiter's slot count, as the logs tests do; 300 runs of the
test and 20 shuffled runs of the package pass.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The metrics concurrency test only checked that a Retry-After was
present, while the rate limit test pins its value, so a change to the
promised hint passed. It now expects the literal value.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect reads step and timeout as float seconds multiplied by 1000
and truncated, so a step the proxy checked as 1001ms and sent as
"1.001" arrived as 1000ms. The points limit was then checked against
a coarser step than vmselect used: a limit of 11000 let 11010 points
through, and many steps between 1ms and 100000s were affected.
Durations are now written so that the truncation lands on the
milliseconds the limits were checked with: the shortest form when it
reads back exactly, otherwise with half a millisecond added. Step and
timeout share the formatter, and a sweep test mirrors vmselect's
parsing.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The metrics root has its own admission, so the hint added to the logs
root did not reach it, and a console graph polling into the limit had
no back-off hint.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect's sample limit counts raw samples read, not the work of a
rollup that revisits each sample across overlapping windows, so for
that work the forwarded timeout is the limit that applies.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The comment claimed the limits bound everything a request makes
vmselect do, but windows and offsets inside the expression pass
through unchecked: they are bounded by the store's retention and by
vmselect's own series and sample limits, not by the proxy. A reader
taking the comment at its word would rely on a cost cap that does not
exist.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The points limit was checked on the parsed bounds, but vmselect gets
both cut to the millisecond. A start cut back by more than the end
widened the forwarded range, so a 1ms step admitted at 11000 points
reached vmselect as 11001.
Times are now cut to the millisecond when they are parsed, so the
range and points checks and the forwarded request see one window.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The metrics root parsed its form before taking a concurrency slot,
under no read deadline, and wrote its answer under no write deadline,
so a client that sent its body slowly or stopped reading held the
handler outside every limit. A store answer that broke off after the
status line still ended as a clean 200.
The metrics handler now follows the logs root: the slot is taken
before the body is read under the request timeout, the answer must be
taken by the request deadline, and a failed copy cuts the connection.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The lookback scan assumed every window and offset applies once and
explicitly. A rollup function or offset over anything but a selector is
an implicit subquery in vmselect, so every "(" now counts as one level;
a WITH template can apply one window several times, so WITH makes the
bound unknown; and an offset written with digit separators was read as
its first digits only, so "_" now ends in an unknown bound instead.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>