Skip to content

Commit

Permalink
Add multi-tenant middleware in multi-tenant routes
Browse files Browse the repository at this point in the history
  • Loading branch information
electron0zero committed Nov 8, 2023
1 parent 6df6ee2 commit cb0cc4f
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions modules/frontend/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/golang/protobuf/jsonpb" //nolint:all //deprecated
"github.com/golang/protobuf/proto" //nolint:all //deprecated
"github.com/grafana/dskit/user"
"github.com/grafana/tempo/modules/frontend/combiner"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"

Expand Down Expand Up @@ -54,25 +55,46 @@ func New(cfg Config, next http.RoundTripper, o overrides.Interface, reader tempo

retryWare := newRetryWare(cfg.MaxRetries, registerer)

// tracebyid middleware
traceByIDMiddleware := MergeMiddlewares(newTraceByIDMiddleware(cfg, o, logger), retryWare)
searchMiddleware := MergeMiddlewares(newSearchMiddleware(cfg, o, reader, logger), retryWare)
searchTagsMiddleware := MergeMiddlewares(newSearchTagsMiddleware(), retryWare)
// TODO: return error for routes that don't support multi-tenant queries

// inject multi-tenant middleware in multi-tenant routes
traceByIDMiddleware := MergeMiddlewares(
newMultiTenantMiddleware(cfg, combiner.NewTraceByID, logger),
newTraceByIDMiddleware(cfg, o, logger), retryWare)

searchMiddleware := MergeMiddlewares(
newMultiTenantMiddleware(cfg, combiner.NewSearch, logger),
newSearchMiddleware(cfg, o, reader, logger), retryWare)

searchTagsMiddleware := MergeMiddlewares(
newMultiTenantMiddleware(cfg, combiner.NewSearchTags, logger),
newSearchTagsMiddleware(), retryWare)

searchTagsValuesMiddleware := MergeMiddlewares(
newMultiTenantMiddleware(cfg, combiner.NewSearchTagValues, logger),
newSearchTagsMiddleware(), retryWare)

searchTagsValuesV2Middleware := MergeMiddlewares(
newMultiTenantMiddleware(cfg, combiner.NewSearchTagValuesV2, logger),
newSearchTagsMiddleware(), retryWare)

spanMetricsMiddleware := MergeMiddlewares(newSpanMetricsMiddleware(), retryWare)

traces := traceByIDMiddleware.Wrap(next)
search := searchMiddleware.Wrap(next)
searchTags := searchTagsMiddleware.Wrap(next)
searchTagValues := searchTagsValuesMiddleware.Wrap(next)
searchTagValuesV2 := searchTagsValuesV2Middleware.Wrap(next)

metrics := spanMetricsMiddleware.Wrap(next)

return &QueryFrontend{
TraceByIDHandler: newHandler(traces, traceByIDSLOPostHook(cfg.TraceByID.SLO), nil, logger),
SearchHandler: newHandler(search, searchSLOPostHook(cfg.Search.SLO), searchSLOPreHook, logger),
SearchTagsHandler: newHandler(searchTags, nil, nil, logger),
SearchTagsV2Handler: newHandler(searchTags, nil, nil, logger),
SearchTagsValuesHandler: newHandler(searchTags, nil, nil, logger),
SearchTagsValuesV2Handler: newHandler(searchTags, nil, nil, logger),
SearchTagsValuesHandler: newHandler(searchTagValues, nil, nil, logger),
SearchTagsValuesV2Handler: newHandler(searchTagValuesV2, nil, nil, logger),

SpanMetricsSummaryHandler: newHandler(metrics, nil, nil, logger),
SearchWSHandler: newSearchStreamingWSHandler(cfg, o, retryWare.Wrap(next), reader, apiPrefix, logger),
Expand Down

0 comments on commit cb0cc4f

Please sign in to comment.