Skip to content

Commit

Permalink
[TraceQL Metrics] New baseline comparison function (#3695)
Browse files Browse the repository at this point in the history
* Initial working version of compare

* Clean/rename

* Redo meta labels for type and error. Add required parameter for max values

* Add selectAll support to vParquet4

* vp2 unsupported

* comment out test for now

* Rename select all field

* lint

* compare() return topN and make it optional

* Add callback version of AllAttributes to avoid map alloc

* Fix lookup table

* Hideous but working version with totals per attribute and classification

* less hideous, and restore full time series processing

* instant-ish query

* add selectall attributes

* Adding partial finished test for selectAll, blocked for now

* lint

* Review feedback, reenable using traceid and traceDuration in the filter

* changelog

* Finish vp4 selectall test, refactor some methods to share with test

* Fix comment and remove test hacks
  • Loading branch information
mdisibio authored Jun 21, 2024
1 parent 2a38bd1 commit 6b2c0b1
Show file tree
Hide file tree
Showing 15 changed files with 1,372 additions and 444 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [FEATURE] TraceQL support for link scope and link:traceID and link:spanID [#3741](https://github.com/grafana/tempo/pull/3741) (@stoewer)
* [FEATURE] TraceQL support for event scope and event:name intrinsic [#3708](https://github.com/grafana/tempo/pull/3708) (@stoewer)
* [FEATURE] Flush and query RF1 blocks for TraceQL metric queries [#3628](https://github.com/grafana/tempo/pull/3628) [#3691](https://github.com/grafana/tempo/pull/3691) [#3723](https://github.com/grafana/tempo/pull/3723) (@mapno)
* [FEATURE] Add new compare() metrics function [#3695](https://github.com/grafana/tempo/pull/3695) (@mdisibio)
* [ENHANCEMENT] Tag value lookup use protobuf internally for improved latency [#3731](https://github.com/grafana/tempo/pull/3731) (@mdisibio)
* [ENHANCEMENT] TraceQL metrics queries use protobuf internally for improved latency [#3745](https://github.com/grafana/tempo/pull/3745) (@mdisibio)
* [ENHANCEMENT] Improve use of OTEL semantic conventions on the service graph [#3711](https://github.com/grafana/tempo/pull/3711) (@zalegrala)
Expand Down
5 changes: 5 additions & 0 deletions modules/frontend/metrics_query_range_sharder.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ func (s *queryRangeSharder) toUpstreamRequest(ctx context.Context, req tempopb.Q
// Without alignment each refresh is shifted by seconds or even milliseconds and the time series
// calculations are sublty different each time. It's not wrong, but less preferred behavior.
func alignTimeRange(req *tempopb.QueryRangeRequest) {
if req.End-req.Start == req.Step {
// Instant query
return
}

// It doesn't really matter but the request fields are expected to be in nanoseconds.
req.Start = req.Start / req.Step * req.Step
req.End = req.End / req.Step * req.Step
Expand Down
6 changes: 6 additions & 0 deletions pkg/traceql/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ func (m *mockSpan) AllAttributes() map[Attribute]Static {
return m.attributes
}

func (m *mockSpan) AllAttributesFunc(cb func(Attribute, Static)) {
for k, v := range m.attributes {
cb(k, v)
}
}

func (m *mockSpan) ID() []byte {
return m.id
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/traceql/engine_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/grafana/tempo/pkg/tempopb"
commonv1proto "github.com/grafana/tempo/pkg/tempopb/common/v1"
v1 "github.com/grafana/tempo/pkg/tempopb/common/v1"
"github.com/grafana/tempo/pkg/util"
"github.com/prometheus/prometheus/model/labels"
)
Expand Down Expand Up @@ -77,6 +78,14 @@ type Label struct {

type Labels []Label

func LabelsFromProto(ls []v1.KeyValue) Labels {
out := make(Labels, 0, len(ls))
for _, l := range ls {
out = append(out, Label{Name: l.Key, Value: StaticFromAnyValue(l.Value)})
}
return out
}

// String returns the prometheus-formatted version of the labels. Which is downcasting
// the typed TraceQL values to strings, with some special casing.
func (ls Labels) String() string {
Expand All @@ -98,7 +107,7 @@ func (ls Labels) String() string {
}

type TimeSeries struct {
Labels []Label
Labels Labels
Values []float64
}

Expand Down Expand Up @@ -578,7 +587,7 @@ func (e *Engine) CompileMetricsQueryRange(req *tempopb.QueryRangeRequest, dedupe

// optimize numerous things within the request that is specific to metrics.
func optimize(req *FetchSpansRequest) {
if !req.AllConditions {
if !req.AllConditions || req.SecondPassSelectAll {
return
}

Expand Down
Loading

0 comments on commit 6b2c0b1

Please sign in to comment.