-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[query] Truncate search results to prevent OOM on jaeger-query. #1202
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,14 @@ import ( | |
|
||
const ( | ||
defaultQueryLimit = 100 | ||
defaultSpansLimit = 10000 | ||
|
||
operationParam = "operation" | ||
tagParam = "tag" | ||
tagsParam = "tags" | ||
startTimeParam = "start" | ||
limitParam = "limit" | ||
limitSpansParam = "limitSpans" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/limitSpans/maxSpansPerTrace/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see the very last comment |
||
minDurationParam = "minDuration" | ||
maxDurationParam = "maxDuration" | ||
serviceParam = "service" | ||
|
@@ -105,6 +107,16 @@ func (p *queryParser) parse(r *http.Request) (*traceQueryParameters, error) { | |
limit = int(limitParsed) | ||
} | ||
|
||
limitSpansParam := r.FormValue(limitSpansParam) | ||
limitSpans := defaultSpansLimit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scope the string var to the if statement: var maxSpansPerTrace int
if maxSpansParam := r.FormValue(maxSpansPerTraceParam); maxSpansParam != "" {
} |
||
if limitSpansParam != "" { | ||
limitParsed, err := strconv.ParseInt(limitSpansParam, 10, 32) | ||
if err != nil { | ||
return nil, err | ||
} | ||
limitSpans = int(limitParsed) | ||
} | ||
|
||
minDuration, err := p.parseDuration(minDurationParam, r) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -137,6 +149,7 @@ func (p *queryParser) parse(r *http.Request) (*traceQueryParameters, error) { | |
StartTimeMax: endTime, | ||
Tags: tags, | ||
NumTraces: limit, | ||
NumSpans: limitSpans, | ||
DurationMin: minDuration, | ||
DurationMax: maxDuration, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ const ( | |
|
||
defaultDocCount = 10000 // the default elasticsearch allowed limit | ||
defaultNumTraces = 100 | ||
defaultNumSpans = 10000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has no effect currently since multi-read is already bound by defaultDocCount |
||
) | ||
|
||
var ( | ||
|
@@ -136,7 +137,7 @@ func (s *SpanReader) GetTrace(ctx context.Context, traceID model.TraceID) (*mode | |
span, ctx := opentracing.StartSpanFromContext(ctx, "GetTrace") | ||
defer span.Finish() | ||
currentTime := time.Now() | ||
traces, err := s.multiRead(ctx, []string{traceID.String()}, currentTime.Add(-s.maxSpanAge), currentTime) | ||
traces, err := s.multiRead(ctx, []string{traceID.String()}, currentTime.Add(-s.maxSpanAge), currentTime, defaultNumSpans) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -231,15 +232,14 @@ func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *spanstore.Trace | |
if err != nil { | ||
return nil, err | ||
} | ||
return s.multiRead(ctx, uniqueTraceIDs, traceQuery.StartTimeMin, traceQuery.StartTimeMax) | ||
return s.multiRead(ctx, uniqueTraceIDs, traceQuery.StartTimeMin, traceQuery.StartTimeMax, traceQuery.NumSpans) | ||
} | ||
|
||
func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]model.TraceID, error) { | ||
return nil, errors.New("not implemented") // TODO: Implement | ||
} | ||
|
||
func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime, endTime time.Time) ([]*model.Trace, error) { | ||
|
||
func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime, endTime time.Time, numSpans int) ([]*model.Trace, error) { | ||
childSpan, _ := opentracing.StartSpanFromContext(ctx, "multiRead") | ||
childSpan.LogFields(otlog.Object("trace_ids", traceIDs)) | ||
defer childSpan.Finish() | ||
|
@@ -269,7 +269,7 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime | |
if val, ok := searchAfterTime[traceID]; ok { | ||
nextTime = val | ||
} | ||
searchRequests[i] = elastic.NewSearchRequest().IgnoreUnavailable(true).Type(spanType).Source(elastic.NewSearchSource().Query(query).Size(defaultDocCount).Sort("startTime", true).SearchAfter(nextTime)) | ||
searchRequests[i] = elastic.NewSearchRequest().IgnoreUnavailable(true).Type(spanType).Source(elastic.NewSearchSource().Query(query).Size(defaultDocCount).TerminateAfter(numSpans).Sort("startTime", true).SearchAfter(nextTime)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the difference between Size() and TerminateAfter()? |
||
} | ||
// set traceIDs to empty | ||
traceIDs = nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,4 +51,5 @@ type TraceQueryParameters struct { | |
DurationMin time.Duration | ||
DurationMax time.Duration | ||
NumTraces int | ||
NumSpans int | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. however, why does this need to be passed from the interface? I think the overall feature is intended to protect storage from OOM, so the parameterization should be done via a parameter when instantiating the storage, not at query time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @yurishkuro, I think this particular issue was filed for OOM on the jaeger-query nodes, and we have a separate issue for handling overloading of the underlying storage - #960 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixing it in the storage will address query-service OOM. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. Will look into. Closing this PR. So do we want to restrict number of spans (per trace) at ingestion? @yurishkuro There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at ingestion (which isn't possible anyway since spans arrive async). We want the limit to be applied at query time, similar to the changes you made to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry its taking so many iterations to get this one right. Understood now, sending in a new, clean PR. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was no default previously, we should not introduce one. I.e. default should be 0, which is == unlimited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the very last comment