Skip to content

Commit

Permalink
Skip nil and zero length hits (#601)
Browse files Browse the repository at this point in the history
Signed-off-by: 马庆升 <mqs@meitu.com>
  • Loading branch information
NeoCN authored and yurishkuro committed Dec 18, 2017
1 parent 05c9958 commit 0e117e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ var (
// ErrUnableToFindTraceIDAggregation occurs when an aggregation query for TraceIDs fail.
ErrUnableToFindTraceIDAggregation = errors.New("Could not find aggregation of traceIDs")

errNilHits = errors.New("No hits in read results found")

errNoTraces = errors.New("No trace with that ID found")

defaultMaxDuration = model.DurationAsMicroseconds(time.Hour * 24)
Expand Down Expand Up @@ -232,8 +230,8 @@ func (s *SpanReader) multiRead(traceIDs []string, startTime, endTime time.Time)

var traces []*model.Trace
for _, result := range results.Responses {
if result.Hits == nil {
return nil, errNilHits
if result.Hits == nil || len(result.Hits.Hits) == 0 {
continue
}
spans, err := s.collectSpans(result.Hits.Hits)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestSpanReader_GetTraceQueryError(t *testing.T) {
})
}

func TestSpanReader_GetTraceNilHitsError(t *testing.T) {
func TestSpanReader_GetTraceNilHits(t *testing.T) {
withSpanReader(func(r *spanReaderTest) {
var hits []*elastic.SearchHit
searchHits := &elastic.SearchHits{Hits: hits}
Expand All @@ -158,7 +158,7 @@ func TestSpanReader_GetTraceNilHitsError(t *testing.T) {
}, nil)

trace, err := r.reader.GetTrace(model.TraceID{Low: 1})
require.EqualError(t, err, "No hits in read results found")
require.EqualError(t, err, "No trace with that ID found")
require.Nil(t, trace)
})
}
Expand Down

0 comments on commit 0e117e0

Please sign in to comment.