Skip to content

Commit

Permalink
Use correct context on ES search methods (#1850)
Browse files Browse the repository at this point in the history
* Use correct context on ES search methods

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>

* Updte reader tests, now expect valueCtx

Signed-off-by: Ruben Vargas <ruben.vp8510@gmail.com>
  • Loading branch information
rubenvp8510 authored and pavolloffay committed Oct 10, 2019
1 parent 2cb3a2b commit 6b5c9e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ var (

// SpanReader can query for and load traces from ElasticSearch
type SpanReader struct {
ctx context.Context
client es.Client
logger *zap.Logger
// The age of the oldest service/operation we will look for. Because indices in ElasticSearch are by day,
Expand Down Expand Up @@ -119,9 +118,7 @@ type SpanReaderParams struct {

// NewSpanReader returns a new SpanReader with a metrics.
func NewSpanReader(p SpanReaderParams) *SpanReader {
ctx := context.Background()
return &SpanReader{
ctx: ctx,
client: p.Client,
logger: p.Logger,
maxSpanAge: p.MaxSpanAge,
Expand Down Expand Up @@ -337,7 +334,7 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
}
// set traceIDs to empty
traceIDs = nil
results, err := s.client.MultiSearch().Add(searchRequests...).Index(indices...).Do(s.ctx)
results, err := s.client.MultiSearch().Add(searchRequests...).Index(indices...).Do(ctx)

if err != nil {
logErrorToSpan(childSpan, err)
Expand Down Expand Up @@ -471,7 +468,6 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
// }
aggregation := s.buildTraceIDAggregation(traceQuery.NumTraces)
boolQuery := s.buildFindTraceIDsQuery(traceQuery)

jaegerIndices := s.timeRangeIndices(s.spanIndexPrefix, traceQuery.StartTimeMin, traceQuery.StartTimeMax)

searchService := s.client.Search(jaegerIndices...).
Expand All @@ -480,7 +476,7 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
IgnoreUnavailable(true).
Query(boolQuery)

searchResult, err := searchService.Do(s.ctx)
searchResult, err := searchService.Do(ctx)
if err != nil {
return nil, errors.Wrap(err, "Search service failed")
}
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 @@ -803,15 +803,15 @@ func mockMultiSearchService(r *spanReaderTest) *mock.Call {
multiSearchService.On("Index", mock.AnythingOfType("string"), mock.AnythingOfType("string"),
mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(multiSearchService)
r.client.On("MultiSearch").Return(multiSearchService)
return multiSearchService.On("Do", mock.AnythingOfType("*context.emptyCtx"))
return multiSearchService.On("Do", mock.AnythingOfType("*context.valueCtx"))
}

func mockArchiveMultiSearchService(r *spanReaderTest, indexName string) *mock.Call {
multiSearchService := &mocks.MultiSearchService{}
multiSearchService.On("Add", mock.Anything, mock.Anything, mock.Anything).Return(multiSearchService)
multiSearchService.On("Index", indexName).Return(multiSearchService)
r.client.On("MultiSearch").Return(multiSearchService)
return multiSearchService.On("Do", mock.AnythingOfType("*context.emptyCtx"))
return multiSearchService.On("Do", mock.AnythingOfType("*context.valueCtx"))
}

func mockSearchService(r *spanReaderTest) *mock.Call {
Expand Down

0 comments on commit 6b5c9e4

Please sign in to comment.