-
Notifications
You must be signed in to change notification settings - Fork 692
Query Frontend: Job weights #4076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5d33f7d
push down pipelineResponse to the frontend
joe-elliott 42e1d11
early exit on ctx.Err()
joe-elliott 791b6b8
added weights to request
joe-elliott f062280
remove unused roundtripper
joe-elliott dde6193
notes cleanup
joe-elliott e1a8363
fix documentation
javiermolinar b2c4e4c
fix tests
javiermolinar 36d4725
added test for weights picking request batches
javiermolinar 4b980ca
fix ast tests
javiermolinar d6afbbb
fix panic in test
javiermolinar a114967
fix another panic
javiermolinar 18fdf16
Add weight test
zalegrala 9535ef9
move weight functionality as a middleware
javiermolinar f78838f
cleanup
javiermolinar 0b190b2
more cleanup
javiermolinar 3188260
rollback some unneded changes
javiermolinar 5f294c1
fix tests
javiermolinar dd78c7e
fix traceql errors by propagating the start and end to the fetchspanr…
javiermolinar 2e611e7
add config to disable the feature
javiermolinar f480a62
propatage weights to sharded requests
javiermolinar 76570b1
simplify logic
javiermolinar bf64d78
simplify query passthrough
javiermolinar 727ec8e
improve weights configuration
javiermolinar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| package pipeline | ||
|
|
||
| import ( | ||
| "github.com/grafana/tempo/modules/frontend/combiner" | ||
| "github.com/grafana/tempo/pkg/traceql" | ||
| ) | ||
|
|
||
| type RequestType int | ||
|
|
||
| type WeightRequest interface { | ||
| SetWeight(int) | ||
| Weight() int | ||
| } | ||
|
|
||
| type WeightsConfig struct { | ||
| RequestWithWeights bool `yaml:"request_with_weights,omitempty"` | ||
| RetryWithWeights bool `yaml:"retry_with_weights,omitempty"` | ||
| MaxTraceQLConditions int `yaml:"max_traceql_conditions,omitempty"` | ||
| MaxRegexConditions int `yaml:"max_regex_conditions,omitempty"` | ||
| } | ||
|
|
||
| type Weights struct { | ||
| DefaultWeight int | ||
| TraceQLSearchWeight int | ||
| TraceByIDWeight int | ||
| MaxTraceQLConditions int | ||
| MaxRegexConditions int | ||
| } | ||
|
|
||
| const ( | ||
| Default RequestType = iota | ||
| TraceByID | ||
| TraceQLSearch | ||
| TraceQLMetrics | ||
| ) | ||
|
|
||
| type weightRequestWare struct { | ||
| requestType RequestType | ||
| enabled bool | ||
| next AsyncRoundTripper[combiner.PipelineResponse] | ||
|
|
||
| weights Weights | ||
| } | ||
|
|
||
| // It increments the weight of a retriyed request | ||
| func IncrementRetriedRequestWeight(r WeightRequest) { | ||
| r.SetWeight(r.Weight() + 1) | ||
| } | ||
|
|
||
| // It returns a new weight request middleware | ||
| func NewWeightRequestWare(rt RequestType, cfg WeightsConfig) AsyncMiddleware[combiner.PipelineResponse] { | ||
| weights := Weights{ | ||
| DefaultWeight: 1, | ||
| TraceQLSearchWeight: 1, | ||
| TraceByIDWeight: 2, | ||
| MaxTraceQLConditions: cfg.MaxTraceQLConditions, | ||
| MaxRegexConditions: cfg.MaxRegexConditions, | ||
| } | ||
| return AsyncMiddlewareFunc[combiner.PipelineResponse](func(next AsyncRoundTripper[combiner.PipelineResponse]) AsyncRoundTripper[combiner.PipelineResponse] { | ||
| return &weightRequestWare{ | ||
| requestType: rt, | ||
| enabled: cfg.RequestWithWeights, | ||
| weights: weights, | ||
| next: next, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| func (c weightRequestWare) RoundTrip(req Request) (Responses[combiner.PipelineResponse], error) { | ||
| c.setWeight(req) | ||
| return c.next.RoundTrip(req) | ||
| } | ||
|
|
||
| func (c weightRequestWare) setWeight(req Request) { | ||
| if !c.enabled { | ||
| req.SetWeight(c.weights.DefaultWeight) | ||
| return | ||
| } | ||
| switch c.requestType { | ||
| case TraceByID: | ||
| req.SetWeight(c.weights.TraceByIDWeight) | ||
| case TraceQLSearch, TraceQLMetrics: | ||
| c.setTraceQLWeight(req) | ||
| default: | ||
| req.SetWeight(c.weights.DefaultWeight) | ||
| } | ||
| } | ||
|
|
||
| func (c weightRequestWare) setTraceQLWeight(req Request) { | ||
| var traceQLQuery string | ||
| query := req.HTTPRequest().URL.Query() | ||
| if query.Has("q") { | ||
| traceQLQuery = query.Get("q") | ||
| } | ||
| if query.Has("query") { | ||
| traceQLQuery = query.Get("query") | ||
| } | ||
|
|
||
| req.SetWeight(c.weights.TraceQLSearchWeight) | ||
|
|
||
| if traceQLQuery == "" { | ||
| return | ||
| } | ||
|
|
||
| _, _, _, spanRequest, err := traceql.Compile(traceQLQuery) | ||
| if err != nil || spanRequest == nil { | ||
| return | ||
| } | ||
|
|
||
| conditions := 0 | ||
| regexConditions := 0 | ||
|
|
||
| for _, c := range spanRequest.Conditions { | ||
| if c.Op != traceql.OpNone { | ||
| conditions++ | ||
| } | ||
| if c.Op == traceql.OpRegex || c.Op == traceql.OpNotRegex { | ||
| regexConditions++ | ||
| } | ||
| } | ||
| complexQuery := regexConditions >= c.weights.MaxRegexConditions || conditions >= c.weights.MaxTraceQLConditions | ||
| if complexQuery { | ||
| req.SetWeight(c.weights.TraceQLSearchWeight + 1) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.