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

skip nil and zero length hits, fix #556 #601

Merged
merged 1 commit into from
Dec 18, 2017

Conversation

NeoCN
Copy link
Contributor

@NeoCN NeoCN commented Dec 18, 2017

Focus on the flowing multiread function code snippet

	var traces []*model.Trace
	for _, result := range results.Responses {
		if result.Hits == nil {
			return nil, errNilHits
		}
		spans, err := s.collectSpans(result.Hits.Hits)
		if err != nil {
			return nil, err
		}
		traces = append(traces, &model.Trace{Spans: spans})
	}
	return traces, nil

when trace id is invalid or not in the es store, we got response json as follows:

{
   "responses":[
      {
         "took":2,
         "timed_out":false,
         "_shards":{
            "total":15,
            "successful":15,
            "failed":0
         },
         "hits":{
            "total":0,
            "max_score":null,
            "hits":[]
         },
         "status":200
      }
   ]
}

and then the response json is unmarshalled to the elastic.MultiSearchResult struct, you will notice that the snippet

"hits":{
    "total":0,
    "max_score":null,
    "hits":[]
},

will not get nil result.Hits, but a zero length result.Hits.Hits.

When len(result.Hits.Hits) == 0, collectSpans will return []*model.Span with zero length and no error.

In this case, got result traces as

[]*model.Trace{
    &model.Trace{
        Spans: {
        },
        Warnings: nil,
    },
}

this results that len(traces) == 0 not triggered, and then no errNoTraces is returned.

As explained above, neither nil result.Hits nor zero length result.Hits.Hits should do the following collectSpans, just skip them.

Signed-off-by: 马庆升 <mqs@meitu.com>
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 0ba832d on NeoCN:master into 05c9958 on jaegertracing:master.

@yurishkuro yurishkuro merged commit 0e117e0 into jaegertracing:master Dec 18, 2017
@yurishkuro
Copy link
Member

Thanks!

Fixes #556

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants