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>
vmselect moves an instant query evaluated near the current time back by
-search.latencyOffset (30s). With a tiny explicit step the lookback
bound did not cover that shift, so a window ending at the retention
edge could still be sent to the short-term store.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The short-term store was picked from the request window alone, so an
instant increase(x[7d]) or x offset 10d went to the store that keeps
72h and silently returned a wrong number.
A lexical scan of the query now bounds how far back it reads: the sum
of every [...] window and subquery step, positive offsets, and the
step and silence interval vmselect reads before each rollup. An @
modifier, step-multiple units or any duration the scan cannot read
make the bound unknown and pick the long-term store, which receives
the same writes. The scan sees quoted label values too, so a false
hit only moves a query to the long-term store. The query is still
forwarded unchanged.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The logs root answers 429 when a user has too many requests in flight,
so clients back off instead of treating the refusal as a bad query.
The metrics root kept its own 422 for the same limit; it now matches.
The rate limit is shared and already answers 429 with Retry-After,
which the metrics test now expects too.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Rounding a duration up to the millisecond overflows for values within
a millisecond of the largest one, which turned such a step or timeout
negative and let it past the range, points and timeout limits. vmselect
refuses durations above 100 years itself, so the proxy now answers 400
for them before rounding.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The per-user concurrency cap on the metrics root had no test, so
dropping it from the handler went unnoticed. The new test holds one
request in the upstream, expects the same user's second one to be
refused and another user's to go through. Overrides of the metrics
flags were only checked for their defaults and refusals.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect reads step and timeout in whole milliseconds and drops the
remainder, so a step of 1.9ms passed the points check as 1.9ms and
then ran as 1ms, close to twice the points the limit allows. The
duration is now rounded up before the limits are checked, so they see
the value vmselect will use.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The proxy authorizes the namespace metrics root with a
SubjectAccessReview for list on cozystack.io metrics, which no role
grants yet. Aggregating it into the tenant view role reaches every
tenant group and ancestor subject without a tenant chart change.
The Deployment passes the metrics store names and short-term
retention from values, so a platform that renames or resizes its
metricsStorages can keep the proxy's store choice in step.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The store names and the short-term retention mirror metricsStorages in
the monitoring package, which an operator can rename or resize; they
are flags so the chart can follow such a change without a rebuild. The
cost limit defaults are the ones the metrics proposal settles on: 30d
range, 11000 points per series, 30s timeout.
Store names become part of a Service host name, so they are checked
as DNS labels at startup.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The namespace metrics root shares the logs root's authorization path:
the SubjectAccessReview comes from the path alone, so a POST query,
which Grafana sends by default, is authorized exactly like a GET. Both
roots also share the per-user rate and concurrency limits and the way
an unreachable store (502) is told apart from a slow one (504); the
upstream call moves into one helper so the two stay identical.
Every namespace resolves to the root tenant's vmselect for now,
because the series the graphs need are only scraped there.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vmselect ORs repeated extra_filters, so a client-supplied value would
widen the tenant scope. The upstream request is therefore built from
scratch: only query, start, end, step, time, match[] and a clamped
timeout are read from the client, and the namespace selector is sent
as the single extra_filters[] value. The query itself is not parsed;
vmselect ANDs that filter into every selector.
The label endpoints always carry a match[] (the namespace selector
when the client sent none), because a vmselect started with
-search.ignoreExtraFiltersAtLabelsAPI applies extra filters there only
when a match[] is present.
Range, points per series and step are bounded with 422 per the cost
limits of the metrics proposal. Times are accepted only in the two
forms the Prometheus API defines, since vmselect guesses the unit of a
numeric timestamp from its digit count. The window start picks the
short-term store when it lies within that store's retention.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The flag now also bounds the body read and the token and access
reviews, and 0 lifts all of those at once; an operator raising it for
slow store queries needs to know that. The store comment named a
design document the repository does not have.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The package and serve comments described a delivery plan rather than
the code: the command named metrics it does not serve, and serve gave a
plan as the reason to refuse unknown roots before authenticating.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Both reviews ran on the request context, which net/http cancels for a
dropped client only once the body is read. A POST whose body was still
unread therefore waited on a stalled kube-apiserver past every request
limit. The reviews now share the request timeout and answer 503 when it
passes.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Polling for a slot that lives only until a 200ms deadline misses it when
the test goroutine is descheduled for longer, as under -race on a busy
runner. The tail and stalled-query tests now read the slot when the
request reaches the store, which the proxy does while holding it; the
slow-body test, which never reaches the store, gets a wider deadline.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Calling allowed twice in one condition reads as a duplicated expression
to staticcheck, which cannot see that each call takes a token.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
When both bounds were out of range the answer named one of them at
random, as the check walked a map, and it printed the instant without
its fraction, so a time one nanosecond past the last one vlselect can
hold was shown as a time inside the range. The end is now checked
first and the instant is printed in full; tests pin the inclusive
bound.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The 1970..2262 check refused times on parsing, including a start that
the window clamps to the maximum range before anything is sent and a
since that only becomes a capped start_offset, so an old start or a
tail resume from before 1970 answered 400 where the documented answer
is to clamp. It had also detached the parseTime doc comment.
The check now applies to the times actually sent, after clamping, and
uses the range vlselect can hold, int64 nanoseconds (1677..2262); 1970
is not a limit of vlselect.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The slow-body and stalled-client tests checked the slot by sending
requests of their own, which competed for the one slot under test: a
probe that held the slot when the request under test arrived got that
request refused, and the test failed. The tests now read the limiter's
slot count directly.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The second nginx of the not-installed test reused the stand-in port
of the first one right after killing it, behind a fixed sleep, so a
slow exit could leave the port taken. It now waits for the first nginx
to exit and takes a new port. The file header also names the fourth
property it now checks.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
An empty fields_limit answered 400, but an empty limit or facets cap
fell back to the default, so one malformed parameter got two answers
depending on its name. Every cap now refuses an empty value with 400:
a cap the client sent but left blank is a client bug, and reading it
as the default would hide it.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The proxy sends vlselect RFC3339 times, which it never reads as a
guessed-unit number, but it accepted any RFC3339 year and unix
seconds up to 2286. vlselect keeps times as int64 nanoseconds through
time.UnixNano, which is undefined outside 1678..2262, so such a
window landed anywhere. An absolute time outside 1970..2262 now
answers 400; nothing was logged before 1970.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
A request refused before its body was read (401, 403, 405, or a rate
or concurrency 429) had no read deadline yet, and net/http drains up
to 256 KiB of an unread body before it sends the headers. A client
that declared a body and never sent it got no answer, and held the
handler, for as long as it kept the connection; for a second form POST
arriving while the concurrency slot was taken, that was more than five
request timeouts.
The read deadline is now set when the request arrives and lifted once
the body is read, so tails are not cut. A refusal sent with the body
still unread closes the connection instead of draining it, so it is
answered at once.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The 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. The note on the empty fields_limit
case now gives the reason it is refused.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Parsing the scheme with a case-insensitive split changed which header
forms reach the token review; a bare scheme, an empty token and a
scheme run into the token must still answer 401.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The fields_limit cap applied only when the client sent the parameter.
vlselect returns every group when it is absent, as it does for 0, so
leaving it out bypassed the cap. The capped value is now always sent.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Only the rate-limit 429 said when to retry. A concurrency or tail 429
came without it, so a client had no hint and could retry at once in a
loop. It now carries a one-second hint; when a slot frees depends on
the user's other requests, which the proxy cannot predict.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The authorization scheme is case-insensitive, and kube-apiserver
accepts "bearer" as well as "Bearer", so a client that works against
the API server got 401 from the proxy with the same header.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
An empty fields_limit fell back to the default of 0 and reached
vlselect as fields_limit=0, instead of being refused like any other
malformed limit.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The proxy can be left out of an installation, and then the console
nginx answered the observability roots with its own 502. The console
read that as an unreachable store: three errors, a Retry button and a
live tail reconnecting forever, instead of a notice that the feature
is not available on this cluster.
nginx now turns the 502 and 504 it generates itself, when it cannot
resolve or reach the proxy, into a 404 Kubernetes Status, which the
console already treats as not installed. Upstream errors are not
intercepted, so the proxy's own 502 and 504 for a store still reach
the console unchanged. The bats test runs the extracted locations in a
real nginx when one is installed.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
ParseForm reads no body on a GET or on a POST that is not a form. When
such a request declared a body and never sent it, net/http drained it
after the handler flushed the headers, with no read deadline, so the
request held its slot for as long as the client kept the connection.
The handler now reads the rest of the body itself, under the same
deadline and size cap as the form. Draining was chosen over refusing a
declared body so that clients which send one stay working. A body
over the cap now answers 413 instead of a generic 400.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The library is sourced by sh scripts and has no shebang, so shellcheck
could not tell which shell to check it as and refused the file.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The chart tests named the tenant egress policy as one of the parties
the pod label and port are pinned for. That policy is gone, so the
notes now name only the Service and the console nginx, which still
depend on them.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
go build ./cmd/observability-proxy drops the binary at the repository
root like every other command, and unlike them it was not ignored, so
git add . would commit it.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The default of 11000 buckets was justified by a metrics proxy that
does not exist on this branch. The number is Prometheus's cap on
points per series in a range query, which the metrics root reuses.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The rule was added for a tenant Grafana reading through the proxy, but
the tenant Grafana datasources still point straight at vlselect and
vmselect, and the console reaches the proxy from cozy-dashboard. The
rule therefore served no caller and only let every pod of every tenant
reach the proxy directly, outside the console route, where each
request with a fresh token costs a TokenReview.
It can come back together with a tenant client that needs it.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The background tail goes through the console route and the proxy's
reviews before it subscribes, so the early ingest can land first, and
a tail without start_offset returns only lines written after it
starts. The tail now replays the last minute, which still leaves the
hold and the late-line check meaningful.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
An absent namespace resolves to the root store, and before the
informer's first list every namespace is absent, so a request served
in that window read a labeled namespace's logs from the wrong store.
Readiness keeps the Service from routing there, but a client that
addresses the pod directly is not stopped by it.
The resolver now fails while the cache is unsynced, which answers
503 like any other resolution error.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
vlselect widens the window to step boundaries and returns a
zero-filled bucket for each one, so a start off a boundary yields one
bucket more than the span divided by the step. Sizing the step from
the unaligned span let hits and stats_query_range return MaxBuckets+1
buckets.
The minimum step now spans MaxBuckets-1 steps, and the smallest
accepted --logs-max-buckets rises to 4 so that this step still fits
the third-of-range cap that keeps alignment inside the window.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The flag parser stops at the first argument that is not a flag, so
a stray word in the container args made every flag after it fall back
to its default without an error, the root tenant included.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
NaN fails the negative check, as every comparison does, and +Inf
refills a bucket instantly, so either value switched the per-user rate
limit off while the flag looked set. Both now stop the proxy at
startup.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
When the bucket map was full and the sweep freed nothing, the new
user's bucket was added anyway, so the map grew past its bound and
every further newcomer paid a full scan under the limiter lock.
A newcomer is now refused with 429 until the first bucket refills,
and the Retry-After tells it when. Resetting the map instead would
hand every throttled user a fresh burst.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
A TokenReview whose authenticator failed comes back unauthenticated
with status.error set, and a SubjectAccessReview whose authorizer
failed comes back with an evaluation error and no decision. Both were
cached as refusals, so a valid caller stayed locked out for the cache
TTL after the outage ended.
Such answers are now refused for the current request only. A review
that failed to decide still answers 401 or 403 rather than 503: RBAC
sets an evaluation error for any binding to a missing role, which a
retryable status would turn into a permanent 503 for that user.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
Once the status line has gone out, a read error from the store left
the handler returning normally, so the chunked body ended cleanly and
the client took a partial answer for a complete one.
The handler now aborts the response in that case. The request is
counted before the abort, because the abort skips the rest of the
handler.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The tail idle timer started only once the store had sent its headers,
and a tail request carries no deadline, so a store that accepted the
request and stayed silent held the tail slot until the client left.
The timer now starts before the request, and the same timer bounds the
header wait and the gap between lines. A store that never answers
gets 504, like a non-tail request past its deadline.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
A client that stopped reading kept its slot for good: the first flush
ran before the tail idle timer started, and cancelling the upstream
request does not interrupt a write that is blocked on the client.
Every response now carries a write deadline. A tail renews it by the
idle timeout before each line, so a tail that keeps receiving stays
open while a stalled reader is cut and frees its slot; any other
response must be written by the request deadline.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>
The form was parsed before the concurrency slot was taken, and the
listener sets no body-read deadline, so a client that never finished a
POST body held a handler outside every limit for as long as it liked.
Tenant workloads reach the Service directly, so nginx buffering does
not cover this path.
The slot is now taken first and the body is read under the request
timeout; a body that does not arrive in time answers 408 and frees the
slot. The deadline is lifted once the body is read, because the
server's background read would take a later expiry for a client that
went away and cancel a live tail.
Assisted-by: LLM
Signed-off-by: ZverGuy <maximbel2003@gmail.com>