Skip to content
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

Read trace ID from ES without leading zeros #1

Merged
merged 2 commits into from
Dec 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,17 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
}
searchRequests := make([]*elastic.SearchRequest, len(traceIDs))
for i, traceID := range traceIDs {
query := elastic.NewTermQuery("traceID", traceID.String())
// TODO remove in newer versions, added in Jaeger 1.16
// read ID without leading zeros
// https://github.com/jaegertracing/jaeger/pull/1956 added leading zeros to IDs
var legacyTraceID string
if traceID.High == 0 {
legacyTraceID = fmt.Sprintf("%x", traceID.Low)
} else {
legacyTraceID = fmt.Sprintf("%x%016x", traceID.High, traceID.Low)
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only want to do that if the normal ID string starts with a 0, otherwise issue a single query.

query := elastic.NewBoolQuery().
Should( elastic.NewTermQuery(traceIDField, traceID.String()).Boost(2), elastic.NewTermQuery(traceIDField, legacyTraceID))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure what goes on in this query, but is there any reason to not simply add the legacy ID to searchRequests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically or statement and the new ID has a higher priority https://www.elastic.co/guide/en/elasticsearch/reference/6.6//query-dsl-term-query.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather do this than running a separate query. It might be more effective.

if val, ok := searchAfterTime[traceID]; ok {
nextTime = val
}
Expand Down Expand Up @@ -394,16 +404,23 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
}

func convertTraceIDsStringsToModels(traceIDs []string) ([]model.TraceID, error) {
traceIDsModels := make([]model.TraceID, len(traceIDs))
for i, ID := range traceIDs {
traceIDsMap := map[model.TraceID]bool{}
for _, 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
if _, ok := traceIDsMap[traceID]; !ok {
traceIDsMap[traceID] = true
}
}

traceIDsModels := make([]model.TraceID, len(traceIDsMap))
i := 0
for id, _ := range traceIDsMap {
traceIDsModels[i] = id
i++
}
return traceIDsModels, nil
}

Expand Down