Skip to content

Commit

Permalink
convert interfaces/fields/methods to private for frontend package
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben Vargas <[email protected]>
  • Loading branch information
rubenvp8510 committed Nov 30, 2023
1 parent fdff0b1 commit a01fa49
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 72 deletions.
2 changes: 1 addition & 1 deletion modules/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func newSearchMiddleware(cfg Config, o overrides.Interface, reader tempodb.Reade
}

// newSearchTagsMiddleware creates a new frontend middleware to handle search tags requests.
func newSearchTagsMiddleware(cfg Config, o overrides.Interface, reader tempodb.Reader, logger log.Logger, TagShardHandler TagResultHandlerFactory) Middleware {
func newSearchTagsMiddleware(cfg Config, o overrides.Interface, reader tempodb.Reader, logger log.Logger, TagShardHandler tagResultHandlerFactory) Middleware {
return MiddlewareFunc(func(next http.RoundTripper) http.RoundTripper {
ingesterSearchRT := NewRoundTripper(next, newTagsSharding(reader, o, cfg.Search.Sharder, TagShardHandler, logger))

Expand Down
62 changes: 31 additions & 31 deletions modules/frontend/tagsharding.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ import (
"github.com/opentracing/opentracing-go"
)

type TagResultsHandler interface {
ParseRequest(*http.Request) (tagSearchReq, error)
ShouldQuit(limit int) bool
AddResponse(io.ReadCloser) error
MarshalResult() (string, error)
type tagResultsHandler interface {
parseRequest(*http.Request) (tagSearchReq, error)
shouldQuit(limit int) bool
addResponse(io.ReadCloser) error
marshalResult() (string, error)
}

type TagResultHandlerFactory func(limit int) TagResultsHandler
type tagResultHandlerFactory func(limit int) tagResultsHandler

type tagSearchReq interface {
Start() uint32
End() uint32
AdjustRange(start, end uint32)
BuildSearchTagRequest(subR *http.Request) (*http.Request, error)
BuildTagSearchBlockRequest(*http.Request, string, int, int, *backend.BlockMeta) (*http.Request, error)
start() uint32
end() uint32
adjustRange(start, end uint32)
buildSearchTagRequest(subR *http.Request) (*http.Request, error)
buildTagSearchBlockRequest(*http.Request, string, int, int, *backend.BlockMeta) (*http.Request, error)
}

type tagResultCollector struct {
delegate TagResultsHandler
delegate tagResultsHandler
mtx sync.Mutex
err error
statusCode int
Expand All @@ -52,7 +52,7 @@ type searchTagSharder struct {
next http.RoundTripper
reader tempodb.Reader
overrides overrides.Interface
tagShardHandlerFactory TagResultHandlerFactory
tagShardHandlerFactory tagResultHandlerFactory
cfg SearchSharderConfig
logger log.Logger
}
Expand All @@ -66,7 +66,7 @@ type tagResults struct {
}

func (r *tagResultCollector) ParseRequest(re *http.Request) (tagSearchReq, error) {
return r.delegate.ParseRequest(re)
return r.delegate.parseRequest(re)
}

func (r *tagResultCollector) shouldQuit() bool {
Expand All @@ -81,7 +81,7 @@ func (r *tagResultCollector) shouldQuit() bool {
if r.statusCode/100 != 2 {
return true
}
if r.delegate.ShouldQuit(r.limit) {
if r.delegate.shouldQuit(r.limit) {
return true
}
return false
Expand All @@ -98,14 +98,14 @@ func (r *tagResultCollector) setStatus(statusCode int, statusMsg string) {
func (r *tagResultCollector) addResponseToResult(ic io.ReadCloser) error {
r.mtx.Lock()
defer r.mtx.Unlock()
return r.delegate.AddResponse(ic)
return r.delegate.addResponse(ic)
}

func (r *tagResultCollector) Result() *tagResults {
r.mtx.Lock()
defer r.mtx.Unlock()

response, err := r.delegate.MarshalResult()
response, err := r.delegate.marshalResult()
return &tagResults{
statusCode: r.statusCode,
statusMsg: r.statusMsg,
Expand All @@ -115,7 +115,7 @@ func (r *tagResultCollector) Result() *tagResults {
}
}

func newTagResultCollector(ctx context.Context, factory TagResultHandlerFactory, limit int) *tagResultCollector {
func newTagResultCollector(ctx context.Context, factory tagResultHandlerFactory, limit int) *tagResultCollector {
return &tagResultCollector{
statusCode: http.StatusOK,
limit: limit,
Expand Down Expand Up @@ -157,9 +157,9 @@ func (s searchTagSharder) RoundTrip(r *http.Request) (*http.Response, error) {

// calculate and enforce max search duration
maxDuration := s.maxDuration(tenantID)
if maxDuration != 0 && time.Duration(searchReq.End()-searchReq.Start())*time.Second > maxDuration {
if maxDuration != 0 && time.Duration(searchReq.end()-searchReq.start())*time.Second > maxDuration {
return s.httpErrorResponse(fmt.Errorf("range specified by start and end exceeds %s."+
" received start=%d end=%d", maxDuration, searchReq.Start(), searchReq.End())), nil
" received start=%d end=%d", maxDuration, searchReq.start(), searchReq.end())), nil
}

// build request to search ingester based on query_ingesters_until config and time range
Expand Down Expand Up @@ -292,13 +292,13 @@ func (s searchTagSharder) backendRequests(ctx context.Context, tenantID string,
var blocks []*backend.BlockMeta

// request without start or end, search only in ingester
if searchReq.Start() == 0 || searchReq.End() == 0 {
if searchReq.start() == 0 || searchReq.end() == 0 {
close(reqCh)
return
}

// calculate duration (start and end) to search the backend blocks
start, end := backendRange(searchReq.Start(), searchReq.End(), s.cfg.QueryBackendAfter)
start, end := backendRange(searchReq.start(), searchReq.end(), s.cfg.QueryBackendAfter)

// no need to search backend
if start == end {
Expand Down Expand Up @@ -331,7 +331,7 @@ func (s searchTagSharder) buildBackendRequests(ctx context.Context, tenantID str
for startPage := 0; startPage < int(m.TotalRecords); startPage += pages {
subR := parent.Clone(ctx)
subR.Header.Set(user.OrgIDHeaderName, tenantID)
subR, err := searchReq.BuildTagSearchBlockRequest(subR, blockID, startPage, pages, m)
subR, err := searchReq.buildTagSearchBlockRequest(subR, blockID, startPage, pages, m)
if err != nil {
reqCh <- &backendReqMsg{err: err}
return
Expand All @@ -352,10 +352,10 @@ func (s searchTagSharder) buildBackendRequests(ctx context.Context, tenantID str
// unexpectedly changing the passed searchReq.
func (s searchTagSharder) ingesterRequest(ctx context.Context, tenantID string, parent *http.Request, searchReq tagSearchReq) (*http.Request, error) {
// request without start or end, search only in ingester
if searchReq.Start() == 0 || searchReq.End() == 0 {
if searchReq.start() == 0 || searchReq.end() == 0 {
subR := parent.Clone(ctx)
subR.Header.Set(user.OrgIDHeaderName, tenantID)
subR, err := searchReq.BuildSearchTagRequest(subR) // api.BuildSearchTagRequest(subR, &searchReq)
subR, err := searchReq.buildSearchTagRequest(subR) // api.BuildSearchTagRequest(subR, &searchReq)
if err != nil {
return nil, err
}
Expand All @@ -368,12 +368,12 @@ func (s searchTagSharder) ingesterRequest(ctx context.Context, tenantID string,
ingesterUntil := uint32(now.Add(-s.cfg.QueryIngestersUntil).Unix())

// if there's no overlap between the query and ingester range just return nil
if searchReq.End() < ingesterUntil {
if searchReq.end() < ingesterUntil {
return nil, nil
}

ingesterStart := searchReq.Start()
ingesterEnd := searchReq.End()
ingesterStart := searchReq.start()
ingesterEnd := searchReq.end()

// adjust ingesterStart if necessary
if ingesterStart < ingesterUntil {
Expand All @@ -385,12 +385,12 @@ func (s searchTagSharder) ingesterRequest(ctx context.Context, tenantID string,
return nil, nil
}

searchReq.AdjustRange(ingesterStart, ingesterEnd)
searchReq.adjustRange(ingesterStart, ingesterEnd)

subR := parent.Clone(ctx)

subR.Header.Set(user.OrgIDHeaderName, tenantID)
subR, err := searchReq.BuildSearchTagRequest(subR)
subR, err := searchReq.buildSearchTagRequest(subR)
if err != nil {
return nil, err
}
Expand All @@ -413,7 +413,7 @@ func (s searchTagSharder) maxDuration(tenantID string) time.Duration {
// newTagsSharding creates a sharding middleware for search
func newTagsSharding(
reader tempodb.Reader, o overrides.Interface,
cfg SearchSharderConfig, tagShardHandler TagResultHandlerFactory, logger log.Logger,
cfg SearchSharderConfig, tagShardHandler tagResultHandlerFactory, logger log.Logger,
) Middleware {
return MiddlewareFunc(func(next http.RoundTripper) http.RoundTripper {
return searchTagSharder{
Expand Down
Loading

0 comments on commit a01fa49

Please sign in to comment.