-
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
The implementation of FindTraceIDs function for ElasticSearch reader. #1280
Merged
vprithvi
merged 19 commits into
jaegertracing:master
from
monitoring-tools:find_trace_ids_for_es_reader
Jan 31, 2019
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
23bbaf5
The implementations of "FindTraceIDs" function for ElasticSearch reader.
c55fde1
The using validation of query and added default numTraces value.
4350e3a
The tests for FindTraceIDs were added.
0ace6df
The test for checking incorrect traceID.
d4a2644
The tests are fixed.
e90848d
The improvements by code-review.
ae75936
The new function validateQueryAndFindTraceIDs.
8a1ec2e
Merge branch 'master' into find_trace_ids_for_es_reader
vlamug 0c399da
Merge branch 'master' into find_trace_ids_for_es_reader
vprithvi 424bc31
The span validateQueryAndFindTraceIDs was removed.
5aae75f
The using slice of model.TraceID instead slice of string in multiRead…
7a70584
Merge remote-tracking branch 'origin/find_trace_ids_for_es_reader' in…
2600634
The converting slice of string to slice of mode.TraceID was extracted…
b108809
The method "convertTraceIDsModelsToStrings" was added to convert slic…
debd4d6
The fix of passing traceID into NewTermQuery function.
66f1851
Merge branch 'master' into find_trace_ids_for_es_reader
vprithvi 75c30d3
The convertTraceIDsModelsToStrings method was remove, because it is r…
0e7139a
Merge remote-tracking branch 'origin/find_trace_ids_for_es_reader' in…
49a132a
Merge branch 'master' into find_trace_ids_for_es_reader
vprithvi 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 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 |
---|---|---|
|
@@ -179,7 +179,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, []model.TraceID{traceID}, currentTime.Add(-s.maxSpanAge), currentTime) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -251,25 +251,34 @@ func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *spanstore.Trace | |
span, ctx := opentracing.StartSpanFromContext(ctx, "FindTraces") | ||
defer span.Finish() | ||
|
||
uniqueTraceIDs, err := s.FindTraceIDs(ctx, traceQuery) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.multiRead(ctx, uniqueTraceIDs, traceQuery.StartTimeMin, traceQuery.StartTimeMax) | ||
} | ||
|
||
// FindTraceIDs retrieves traces IDs that match the traceQuery | ||
func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]model.TraceID, error) { | ||
span, ctx := opentracing.StartSpanFromContext(ctx, "FindTraceIDs") | ||
defer span.Finish() | ||
|
||
if err := validateQuery(traceQuery); err != nil { | ||
return nil, err | ||
} | ||
if traceQuery.NumTraces == 0 { | ||
traceQuery.NumTraces = defaultNumTraces | ||
} | ||
uniqueTraceIDs, err := s.findTraceIDs(ctx, traceQuery) | ||
|
||
esTraceIDs, err := s.findTraceIDs(ctx, traceQuery) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return s.multiRead(ctx, uniqueTraceIDs, traceQuery.StartTimeMin, traceQuery.StartTimeMax) | ||
} | ||
|
||
// FindTraceIDs is not implemented. | ||
func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]model.TraceID, error) { | ||
return nil, errors.New("not implemented") // TODO: Implement | ||
return convertTraceIDsStringsToModels(esTraceIDs) | ||
} | ||
|
||
func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime, endTime time.Time) ([]*model.Trace, error) { | ||
func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, startTime, endTime time.Time) ([]*model.Trace, error) { | ||
|
||
childSpan, _ := opentracing.StartSpanFromContext(ctx, "multiRead") | ||
childSpan.LogFields(otlog.Object("trace_ids", traceIDs)) | ||
|
@@ -286,16 +295,16 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime | |
indices := s.timeRangeIndices(s.spanIndexPrefix, startTime.Add(-time.Hour), endTime.Add(time.Hour)) | ||
nextTime := model.TimeAsEpochMicroseconds(startTime.Add(-time.Hour)) | ||
|
||
searchAfterTime := make(map[string]uint64) | ||
totalDocumentsFetched := make(map[string]int) | ||
tracesMap := make(map[string]*model.Trace) | ||
searchAfterTime := make(map[model.TraceID]uint64) | ||
totalDocumentsFetched := make(map[model.TraceID]int) | ||
tracesMap := make(map[model.TraceID]*model.Trace) | ||
for { | ||
if len(traceIDs) == 0 { | ||
break | ||
} | ||
|
||
for i, traceID := range traceIDs { | ||
query := elastic.NewTermQuery("traceID", traceID) | ||
query := elastic.NewTermQuery("traceID", traceID.String()) | ||
if val, ok := searchAfterTime[traceID]; ok { | ||
nextTime = val | ||
} | ||
|
@@ -333,18 +342,17 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime | |
return nil, err | ||
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. I noticed that the integration tests failed. Perhaps L298 requires a 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. Fixed. Thanks 👍 |
||
} | ||
lastSpan := spans[len(spans)-1] | ||
lastSpanTraceID := lastSpan.TraceID.String() | ||
|
||
if traceSpan, ok := tracesMap[lastSpanTraceID]; ok { | ||
if traceSpan, ok := tracesMap[lastSpan.TraceID]; ok { | ||
traceSpan.Spans = append(traceSpan.Spans, spans...) | ||
} else { | ||
tracesMap[lastSpanTraceID] = &model.Trace{Spans: spans} | ||
tracesMap[lastSpan.TraceID] = &model.Trace{Spans: spans} | ||
} | ||
|
||
totalDocumentsFetched[lastSpanTraceID] = totalDocumentsFetched[lastSpanTraceID] + len(result.Hits.Hits) | ||
if totalDocumentsFetched[lastSpanTraceID] < int(result.TotalHits()) { | ||
traceIDs = append(traceIDs, lastSpanTraceID) | ||
searchAfterTime[lastSpanTraceID] = model.TimeAsEpochMicroseconds(lastSpan.StartTime) | ||
totalDocumentsFetched[lastSpan.TraceID] = totalDocumentsFetched[lastSpan.TraceID] + len(result.Hits.Hits) | ||
if totalDocumentsFetched[lastSpan.TraceID] < int(result.TotalHits()) { | ||
traceIDs = append(traceIDs, lastSpan.TraceID) | ||
searchAfterTime[lastSpan.TraceID] = model.TimeAsEpochMicroseconds(lastSpan.StartTime) | ||
} | ||
} | ||
} | ||
|
@@ -355,6 +363,20 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []string, startTime | |
return traces, nil | ||
} | ||
|
||
func convertTraceIDsStringsToModels(traceIDs []string) ([]model.TraceID, error) { | ||
traceIDsModels := make([]model.TraceID, len(traceIDs)) | ||
for i, ID := range traceIDs { | ||
traceID, err := model.TraceIDFromString(ID) | ||
if err != nil { | ||
return nil, errors.Wrap(err, fmt.Sprintf("Making traceID from string '%s' failed", ID)) | ||
} | ||
|
||
traceIDsModels[i] = traceID | ||
} | ||
|
||
return traceIDsModels, nil | ||
} | ||
|
||
func validateQuery(p *spanstore.TraceQueryParameters) error { | ||
if p == nil { | ||
return ErrMalformedRequestObject | ||
|
This file contains 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
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.
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.
I see a lot of repeated code between
FindTraces
andFindTraceIDs
, are we able to refactor such that the initial validation and retrieval are shared?Also, could you create a new span here - similar to L221
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.
Ok, thanks.