Skip to content

lib/traceql: accept quantiles like .9 in quantile_over_time - #328

Open
Vandit1604 wants to merge 1 commit into
VictoriaMetrics:masterfrom
Vandit1604:327-quantile-leading-dot
Open

Vandit1604 wants to merge 1 commit into
VictoriaMetrics:masterfrom
Vandit1604:327-quantile-leading-dot

Conversation

@Vandit1604

Copy link
Copy Markdown
Contributor

Quantiles without a leading zero, like .9, now work in quantile_over_time, the same as in Tempo.

0.90 and 0.9 now give the same p label. A value outside [0..1] fails with a TraceQL error instead of a LogsQL one.

Fixes #327

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/traceql/pipe_metrics.go">

<violation number="1" location="lib/traceql/pipe_metrics.go:164">
P2: This check runs after float64 rounding, so `1.00000000000000001` becomes `1` and is accepted despite being outside the allowed range. Validate the original decimal before rounding so out-of-range inputs return a TraceQL error.</violation>

<violation number="2" location="lib/traceql/pipe_metrics.go:171">
P2: This fixed-point normalization lets valid very small quantiles through, but their expanded decimal exceeds the downstream LogsQL numeric-length limit and makes the translated query fail. Keep the generated quantile within the downstream parser’s supported representation, or reject/report this range during TraceQL parsing instead of deferring the failure to LogsQL.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

if err != nil {
return nil, fmt.Errorf("cannot parse quantile %q in quantile_over_time: %w", quantile, err)
}
if math.IsNaN(phi) || phi < 0 || phi > 1 {

@cubic-dev-ai cubic-dev-ai Bot Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This check runs after float64 rounding, so 1.00000000000000001 becomes 1 and is accepted despite being outside the allowed range. Validate the original decimal before rounding so out-of-range inputs return a TraceQL error.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/traceql/pipe_metrics.go, line 164:

<comment>This check runs after float64 rounding, so `1.00000000000000001` becomes `1` and is accepted despite being outside the allowed range. Validate the original decimal before rounding so out-of-range inputs return a TraceQL error.</comment>

<file context>
@@ -156,7 +157,18 @@ func parsePipeQuantileOverTime(lex *lexer) (pipe, error) {
+		if err != nil {
+			return nil, fmt.Errorf("cannot parse quantile %q in quantile_over_time: %w", quantile, err)
+		}
+		if math.IsNaN(phi) || phi < 0 || phi > 1 {
+			return nil, fmt.Errorf("quantile in quantile_over_time must be in the range [0..1]; got %q", quantile)
+		}
</file context>
Fix with cubic

// Drop the sign of -0.
phi = 0
}
quantiles = append(quantiles, strconv.FormatFloat(phi, 'f', -1, 64))

@cubic-dev-ai cubic-dev-ai Bot Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This fixed-point normalization lets valid very small quantiles through, but their expanded decimal exceeds the downstream LogsQL numeric-length limit and makes the translated query fail. Keep the generated quantile within the downstream parser’s supported representation, or reject/report this range during TraceQL parsing instead of deferring the failure to LogsQL.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/traceql/pipe_metrics.go, line 171:

<comment>This fixed-point normalization lets valid very small quantiles through, but their expanded decimal exceeds the downstream LogsQL numeric-length limit and makes the translated query fail. Keep the generated quantile within the downstream parser’s supported representation, or reject/report this range during TraceQL parsing instead of deferring the failure to LogsQL.</comment>

<file context>
@@ -156,7 +157,18 @@ func parsePipeQuantileOverTime(lex *lexer) (pipe, error) {
+			// Drop the sign of -0.
+			phi = 0
+		}
+		quantiles = append(quantiles, strconv.FormatFloat(phi, 'f', -1, 64))
 		if !lex.isKeyword(",") {
 			break
</file context>
Fix with cubic

@Vandit1604
Vandit1604 force-pushed the 327-quantile-leading-dot branch from 40b9006 to 3c91bda Compare November 17, 2026 12:43

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/traceql/pipe_metrics.go">

<violation number="1" location="lib/traceql/pipe_metrics.go:162">
P3: `ParseFloat` returns `ErrRange` for valid numeric input such as `1e999`, so this reports it as “expecting a number.” Treat overflow as an out-of-range quantile before handling syntax errors.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

quantiles = append(quantiles, quantile)
phi, err := strconv.ParseFloat(quantile, 64)
if err != nil {
return nil, fmt.Errorf("expecting a number for quantile in quantile_over_time; got %q", quantile)

@cubic-dev-ai cubic-dev-ai Bot Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: ParseFloat returns ErrRange for valid numeric input such as 1e999, so this reports it as “expecting a number.” Treat overflow as an out-of-range quantile before handling syntax errors.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/traceql/pipe_metrics.go, line 162:

<comment>`ParseFloat` returns `ErrRange` for valid numeric input such as `1e999`, so this reports it as “expecting a number.” Treat overflow as an out-of-range quantile before handling syntax errors.</comment>

<file context>
@@ -159,7 +159,7 @@ func parsePipeQuantileOverTime(lex *lexer) (pipe, error) {
 		phi, err := strconv.ParseFloat(quantile, 64)
 		if err != nil {
-			return nil, fmt.Errorf("cannot parse quantile %q in quantile_over_time: %w", quantile, err)
+			return nil, fmt.Errorf("expecting a number for quantile in quantile_over_time; got %q", quantile)
 		}
 		if math.IsNaN(phi) || phi < 0 || phi > 1 {
</file context>
Suggested change
return nil, fmt.Errorf("expecting a number for quantile in quantile_over_time; got %q", quantile)
if err != nil {
if math.IsInf(phi, 0) {
return nil, fmt.Errorf("quantile in quantile_over_time must be in the range [0..1]; got %q", quantile)
}
return nil, fmt.Errorf("expecting a number for quantile in quantile_over_time; got %q", quantile)
}
Fix with cubic

@Vandit1604
Vandit1604 force-pushed the 327-quantile-leading-dot branch from 3c91bda to d5f16f4 Compare November 30, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working vtselect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tempo API: quantile_over_time(duration, .9) returns 400

2 participants