Repository navigation
Open
Labels
accuracyAccuracy requirements, guarantees, and propagationAccuracy requirements, guarantees, and propagationbugSomething isn't workingSomething isn't workingerror-estimationpromqlPromQL front-end lowering (L1→L2)PromQL front-end lowering (L1→L2)
Description
Example
sum by (job) (
quantile_over_time(0.9, data[5m])
/ on(instance, job, host, region)
quantile_over_time(0.9, neg[5m])
)
datais declarednon_negativeandnegis declarednon_positive. Each has 12 series with one sample per second.- Target: relative error 0.05, failure probability 0.3 over the whole result.
- Deployment:
{"raw_data_retained": false}. - Data: near zero. 30% of
neg's samples are-0.0, so the exactquantile_over_time(0.9, neg[5m])is-0.0.
| Head | Result for job j0, j1, j2 |
Exact reference |
|---|---|---|
| before the non-finite exact sums | stream: node 13 (SummaryAgg) failed: accumulator input must be finite |
-Inf, -Inf, -Inf |
| with the non-finite exact sums (exact Sum, Count, Min and Max take ±Inf and NaN, as PromQL does) | +Inf, +Inf, +Inf | -Inf, -Inf, -Inf |
With raw data retained, the plan already returned +Inf before that change. The answer is silently wrong in both deployments. Seeds 0, 1 and 2 behave the same.
Why it happens
- The DDSketch readout of
quantile_over_time(0.9, neg[5m])returns+0.0where the exact value is-0.0. A relative error of 0 lets the sign of zero change:|(+0) − (−0)| = 0 ≤ ε · |−0|. x / +0is +Inf andx / −0is -Inf. So a divisor's signed-zero error, which the contract allows, flips the sign of the quotient's infinity.- The relative error contract of
/(error_contract,ArithmeticOpKind::DivunderAccuracyMetric::Relativeincrates/accuracy/src/error_contract/mod.rs) caps the divisor's relative error atRELATIVE_OPERAND_VALIDITY_CAP. It does not require the divisor to be nonzero. BinaryOperator::checked_relative_division(crates/types/src/ir/operator/non_asap.rs) is meant for exactly this case: "Execute division only for finite operands, a nonzero divisor, and a normal finite result". The executor checks it (crates/executor/src/expressions/arithmetic.rs). No planner code sets it totrue; only executor tests do (grep -rn "checked_relative_division: true" crates).
Proposal
Two options, for a decision:
- The planner sets
checked_relative_divisionon a/whenever its divisor reads an estimate. A divisor of exactly zero then takes the exact path instead of dividing by an estimate. The executor's checked division fails today rather than taking an exact path, so this option also needs that path in the executor. - The
/contract requires a divisor known to be nonzero.ValueSign(crates/types/src/stages/logical/group/column_properties.rs) hasNonNegative,NonPositiveandUnknownonly, and both signed variants allow a zero. So this option needs a new fact for a value that is never zero (a newValueSignvariant or a declared bound), to be agreed before code. A divisor that may be zero then gets no relative error contract, and the readout edge into it is cut.
Option 1 keeps plans that option 2 would cut. Option 2 needs no executor change.
A related gap: ValueSign::NonPositive says every non-NaN value has its sign bit set, -0.0 included. The DDSketch readout's +0.0 breaks that fact for neg. Whichever option is chosen, a readout of a NonPositive column could return -0.0 for a zero estimate.
Scope and acceptance
- In scope: the relative error contract of
/and the plans it allows. - Out of scope: what each kernel does with non-finite values (Non-finite values across the executor should follow PromQL #1311).
- Acceptance: the example above, run on near-zero data without raw data, returns -Inf for every
job, or has no sketch plan. A unit test pins the rule chosen: either the planner setschecked_relative_divisionon the/, or the contract isNonefor a divisor that may be zero.
Related
- Relative error through negation/abs/unless/label_replace; non-finite exact-sum input; finalize sign of rate accumulators #1307 (I1: exact accumulators take non-finite values) and fix(accuracy): relative error through negation, abs, set operators and relabels; readouts compose only through error-carrying inputs; exact accumulators take non-finite values and reject stale markers; finalize sign of counters #1309, which made this example execute.
- Non-finite values across the executor should follow PromQL #1311 (non-finite values per PromQL).
Metadata
Metadata
Assignees
Labels
accuracyAccuracy requirements, guarantees, and propagationAccuracy requirements, guarantees, and propagationbugSomething isn't workingSomething isn't workingerror-estimationpromqlPromQL front-end lowering (L1→L2)PromQL front-end lowering (L1→L2)
Activity