Skip to content

Commit

Permalink
BUG: Remove TerminateAfter from Elasticsearch/Opensearch query result…
Browse files Browse the repository at this point in the history
…ing in incomplete span count/list (#4336)

## Which problem is this PR solving?
Closes #4330 

## Short description of the changes
- Remove TerminateAfter from Elasticsearch/Opensearch query resulting in
incomplete span count/list.

---------

Signed-off-by: Jakob Hahn <[email protected]>
Co-authored-by: Albert <[email protected]>
  • Loading branch information
Jakob3xD and albertteoh authored May 15, 2023
1 parent d6b4482 commit 3021d31
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 1 addition & 2 deletions plugin/storage/es/spanstore/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ func getSourceFn(archive bool, maxDocCount int) sourceFn {
return func(query elastic.Query, nextTime uint64) *elastic.SearchSource {
s := elastic.NewSearchSource().
Query(query).
Size(maxDocCount).
TerminateAfter(maxDocCount)
Size(maxDocCount)
if !archive {
s.Sort("startTime", true).
SearchAfter(nextTime)
Expand Down
26 changes: 26 additions & 0 deletions plugin/storage/es/spanstore/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,3 +1296,29 @@ func TestBuildTraceByIDQuery(t *testing.T) {
assert.Equal(t, test.query, q)
}
}

func TestTerminateAfterNotSet(t *testing.T) {
srcFn := getSourceFn(false, 99)
searchSource := srcFn(elastic.NewMatchAllQuery(), 1)
sp, err := searchSource.Source()
require.NoError(t, err)

searchParams, ok := sp.(map[string]interface{})
require.True(t, ok)

termAfter, ok := searchParams["terminate_after"]
require.False(t, ok)
assert.Nil(t, termAfter)

query, ok := searchParams["query"]
require.True(t, ok)

queryMap, ok := query.(map[string]interface{})
require.True(t, ok)
_, ok = queryMap["match_all"]
require.True(t, ok)

size, ok := searchParams["size"]
require.True(t, ok)
assert.Equal(t, 99, size)
}

0 comments on commit 3021d31

Please sign in to comment.