Repository navigation
fix(#9883): PromQL aggregations and math functions refuse an argument of the wrong type - #9923
Conversation
… of the wrong type
sum(m[5m]) and sum(1) answered an empty vector, abs(m[5m]) returned the range vector
unchanged, abs("a") became a NaN scalar and a non-scalar round precision was silently
replaced with 1. Each is now refused with Prometheus' type-check wording, as are a wrong
argument count and a non-range-vector argument to a range function.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 5 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
ReviewOverall this is a clean, well-scoped fix. The type checks run on the evaluated argument (consistent with #9723/#9743/#9788), the error wording follows Prometheus, and the PR description gives a clear ledger of what was and wasn't changed. Looks good
Suggestions / minor points
Security / performanceNo security concerns. The added checks are No blocking issues from my side. LGTM once you have considered items 2 and 4. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 11 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
…, add a range() test helper Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ReviewOverall this is a clean, well-scoped fix. The inner type is checked before the topk/bottomk parameter, as Prometheus does. The error wording matches Prometheus. The ledger and completeness table in the description are helpful. The test coverage is thorough: it covers instant, range and SQL entry points, nested expressions, and "valid still works" cases. I didn't build or run the tests. Observations
Performance/security: no concerns. The checks are on already-evaluated results, with no extra allocation on the hot path. Behavior change to note: queries that previously returned empty results for LGTM pending those minor points. |
…nge-function arity and the aggregate() helper Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ReviewOverall this is a solid, well-scoped fix. It reuses the existing Minor observations
CLAUDE.md conventions
LGTM, with the optional nits above. |
… are wrong, document the range-function arity and the matrix type name Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Review of #9923Overall this is a clean, well-scoped fix. I read the diff only and did not build or run the tests. What looks good
Suggestions (non-blocking)
There are no performance or security concerns. The added checks are LGTM, pending CI. |
… of the wrong type (#9923) * fix(#9883): PromQL aggregations and math functions refuse an argument of the wrong type sum(m[5m]) and sum(1) answered an empty vector, abs(m[5m]) returned the range vector unchanged, abs("a") became a NaN scalar and a non-scalar round precision was silently replaced with 1. Each is now refused with Prometheus' type-check wording, as are a wrong argument count and a non-range-vector argument to a range function. (cherry picked from commit 1e13a69)
Closes #9883
PromQLEvaluatoranswered silently where Prometheus' type checker refuses: an aggregation over a range vector, a scalar or a string answered an empty vector, a math function (abs,ceil,floor,round) over a range vector returned it unchanged and over a string answered a NaN scalar, and a non-scalarroundprecision was replaced with 1. Each now raises anIllegalArgumentExceptionin Prometheus' wording, on the evaluated argument like #9723, #9743 and #9788. The same function call path also refused nothing on a wrong argument count (abs()threwNoSuchElementException,abs(m, 1)ignored the extra), and the range-function argument refusal used non-Prometheus wording; both are aligned here.Finding ledger
sum(m[5m])answers an empty vectorexpected type instant vector in aggregation expression, got range vectorsum(1)answers an empty vector... got scalar(andgot stringforsum("a"))abs(m[5m])returns the range vectorexpected type instant vector in call to function "abs", got range vectorabs("a")evaluates to a NaN scalar... got stringroundprecision silently defaults to 1expected type scalar in call to function "round", got <type>Completeness
Invariant: every argument of an aggregation or a function call is evaluated and checked against the type Prometheus requires before it is used; nothing of the wrong type is answered silently.
evaluateAggregationinner expression (sum/avg/min/max/count/topk/bottomk, by/without)evaluateScalarFunctionfirst argument (abs/ceil/floor/round)extractSecondParam(round precision)promql()evaluate(); tested throughevaluateInstant,evaluateRangeandRETURN promql(...)/prometheus/api/v1/query(_range)PromQLEvaluator;IllegalArgumentExceptionalready maps to a 400 there (as for #9788)Known gaps: #9922 (top-level expression type of a range query), #9924 (math functions still accept a scalar argument).
Deliberately kept: a scalar argument to a math function (
abs(-1)) stays accepted. Prometheus refuses it (got scalar), but existing tests (#9723, #9743) and queries rely onabs(-1)being a scalar; tightening it is a behavior change beyond this issue, tracked in #9924.Test plan
Issue9883PromQLFunctionArgumentTypeTest(12 tests): red before the fix (10/11 failing, the valid-arguments test green), green afterenginetests incom.arcadedb.engine.timeseries.promql(15 classes, 185 tests) green, incl. PromQL: a binary operator with a range-vector operand answers a scalar NaN where Prometheus rejects it #9788, PromQL: a scalar-scalar comparison without bool answers 0/1 where Prometheus rejects it #9723, PromQL: a set operator (and/or/unless) with a scalar operand answers NaN where Prometheus rejects it #9743, PromQL vector-to-vector matching never excludes__name__, soa / bbetween two different metrics returns nothing andand/unlessanswer backwards #8926, The PromQLboolmodifier is not implemented, andup > bool 0fails with "Unexpected token" instead of saying so #9644Issue7740TimeSeriesBuilderParityTest,PerTypeAclTimeSeriesPathsTest,Issue8043*,Issue7354*,Issue7660*,Issue7675*,Issue7710*,Issue7334*) greenAdversarial pass
Not run as an independent pass: this session had no subagent-spawning tool. An in-session check covered a parenthesized string (
abs(("a")), the parser drops the parens, so the expression is still aStringLiteral), a string as an aggregation inner (topk(1, "a"), reported asgot string, notgot scalar), and the top-level range query (filed as #9922).Review cycles
5d169d1d02IllegalStateException, arange()test helper, release notes, a follow-up for scalar leniency26cd160149range()helper; filed #9924aggregate(), HTTP 400 confirmationfa54c65bbe("a")argument tests, arity and helper commentsround()args are wrong, document"matrix", pointer inisRangeFunction318f3ad24bround(m[5m], "a")test, both commentsDeferred items
GetPromQLQueryHandler(line 113) andGetPromQLQueryRangeHandler(line 119) catchIllegalArgumentExceptionaround evaluation and answer 400bad_data, the same path PromQL: a binary operator with a range-vector operand answers a scalar NaN where Prometheus rejects it #9788's refusals take.sum(m[5m]),sum(1),abs(m[5m]),abs("a")and a non-scalarroundprecision now answer 400 instead of an empty or unchanged result.checkArgumentCount... could be flattened a little" - skipped, stylistic.theSqlFunctionIsRefusedToo... asserting on the root cause message only may be more robust" - skipped, same assertion shape as PromQL: a binary operator with a range-vector operand answers a scalar NaN where Prometheus rejects it #9788's passing test.isRangeFunctionname refuses 2 arguments; Codecov may flag the unreachable"matrix"branch; confirm the parser rejectssum()/topk(1);round(m, 1, 2)through a range query.Final state: max-cycles-reached (every bot review was LGTM; only non-blocking suggestions remain).
🤖 Generated with Claude Code