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

Fix range calculation on recent searches #2581

Merged
merged 4 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions modules/frontend/searchsharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (s searchSharder) RoundTrip(r *http.Request) (*http.Response, error) {

// build request to search ingester based on query_ingesters_until config and time range
// pass subCtx in requests so we can cancel and exit early
ingesterReq, err := s.ingesterRequest(subCtx, tenantID, r, searchReq)
ingesterReq, err := s.ingesterRequest(subCtx, tenantID, r, *searchReq)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -433,10 +433,10 @@ func pagesPerRequest(m *backend.BlockMeta, bytesPerRequest int) int {
// that covers the ingesters. If nil is returned for the http.Request then there is no ingesters query.
// since this function modifies searchReq.Start and End we are taking a value instead of a pointer to prevent it from
// unexpectedly changing the passed searchReq.
func (s *searchSharder) ingesterRequest(ctx context.Context, tenantID string, parent *http.Request, searchReq *tempopb.SearchRequest) (*http.Request, error) {
func (s *searchSharder) ingesterRequest(ctx context.Context, tenantID string, parent *http.Request, searchReq tempopb.SearchRequest) (*http.Request, error) {
// request without start or end, search only in ingester
if searchReq.Start == 0 || searchReq.End == 0 {
return buildIngesterRequest(ctx, tenantID, parent, searchReq)
return buildIngesterRequest(ctx, tenantID, parent, &searchReq)
}

now := time.Now()
Expand All @@ -463,7 +463,7 @@ func (s *searchSharder) ingesterRequest(ctx context.Context, tenantID string, pa
searchReq.Start = ingesterStart
searchReq.End = ingesterEnd

return buildIngesterRequest(ctx, tenantID, parent, searchReq)
return buildIngesterRequest(ctx, tenantID, parent, &searchReq)
}

func buildIngesterRequest(ctx context.Context, tenantID string, parent *http.Request, searchReq *tempopb.SearchRequest) (*http.Request, error) {
Expand Down
8 changes: 7 additions & 1 deletion modules/frontend/searchsharding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"reflect"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -388,7 +389,8 @@ func TestIngesterRequest(t *testing.T) {
searchReq, err := api.ParseSearchRequest(req)
require.NoError(t, err)

actualReq, err := s.ingesterRequest(context.Background(), "test", req, searchReq)
copyReq := searchReq
actualReq, err := s.ingesterRequest(context.Background(), "test", req, *searchReq)
if tc.expectedError != nil {
assert.Equal(t, tc.expectedError, err)
continue
Expand All @@ -399,6 +401,10 @@ func TestIngesterRequest(t *testing.T) {
} else {
assert.Equal(t, tc.expectedURI, actualReq.RequestURI)
}

// it may seem odd to test that the searchReq is not modified, but this is to prevent an issue that
// occurs if the ingesterRequest method is changed to take a searchReq pointer
require.True(t, reflect.DeepEqual(copyReq, searchReq))
}
}

Expand Down