Repository navigation
Proposal: Binary operations between TraceQL metrics Pipelines #6102
Closed
Syedowais312
started this conversation in
Ideas
Replies: 1 comment
|
There are some changes needed, once done i will reopen the discussion |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Proposal: Enable Binary Operations Between TraceQL Metrics Pipelines
Reference: #5756
Summary
TraceQL currently supports:
However, it does not support binary operations between metrics pipelines, such as:
rate(duration) / rate()
Although the metrics engine already implements and tests series-level arithmetic (including division), there is no AST node that represents a binary operation combining two metrics pipelines. As a result, such queries cannot be planned or executed.
This proposal introduces a minimal, isolated AST-level change to bridge that gap.
Problem Statement
In TraceQL, metrics aggregation functions (rate, count_over_time, sum_over_time, etc.) convert spans into time series (SeriesSet). Scalar binary operations (e.g. a / b) are supported via BinaryOperation, but they operate only on per-span scalar values.
Currently, there is no AST construct that represents:
OP
Because of this, queries like:
rate(duration) / rate()
fail at the planning stage, even though:
The missing piece is an AST node that allows two metrics pipelines to be combined.
Proposed Solution
Introduce a new AST node called
MetricsBinaryOperation, which represents a binary operation between two metrics pipelines.This node will:
This design mirrors the existing
BinaryOperationused for scalar expressions, but operates at the metrics (time-series) level instead of the per-span scalar level.Example
TraceQL query:
rate(duration) / rate()
Execution flow:
rate(duration)
rate()
MetricsBinaryOperation(OpDiv)
This aligns with common PromQL-style semantics and unlocks meaningful metrics expressions without modifying the underlying engine.
Implementation Details
New AST Node
Add a new struct:
type MetricsBinaryOperation struct {
op Operator
lhs firstStageElement
rhs firstStageElement
}
This node will implement the existing
firstStageElementinterface.Execution
extractConditions,init,observe,observeExemplar, andobserveSerieswill delegate to both lhs and rhs pipelines.result(multiplier)will:No new math logic is introduced.
Validation
Parser Changes
Extend the grammar to allow binary operators between metrics expressions only (metricsExpr OP metricsExpr). Scalar expressions remain unchanged.
Scope and Non-Goals
In Scope
Out of Scope
Benefits
Implementation Plan
To keep review manageable, the work can be split into two PRs:
Conclusion
This proposal adds a missing but natural capability to TraceQL by enabling binary arithmetic between metrics pipelines. The change is intentionally small, leverages existing engine functionality, and fits cleanly into the current AST and execution model without introducing new complexity.
CC: @joe-elliott @mdisibio @ruslan-mikhailov
All reactions