Skip to content

Commit

Permalink
Add a QueryFrontendTripperware module (#3792)
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hollands <michel.hollands@grafana.com>
  • Loading branch information
MichelHollands authored Jun 3, 2021
1 parent 3940f05 commit 3c47735
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 51 deletions.
28 changes: 15 additions & 13 deletions pkg/loki/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ func (t *Loki) setupModuleManager() error {
mm.RegisterModule(Ingester, t.initIngester)
mm.RegisterModule(Querier, t.initQuerier)
mm.RegisterModule(IngesterQuerier, t.initIngesterQuerier)
mm.RegisterModule(QueryFrontendTripperware, t.initQueryFrontendTripperware, modules.UserInvisibleModule)
mm.RegisterModule(QueryFrontend, t.initQueryFrontend)
mm.RegisterModule(RulerStorage, t.initRulerStorage, modules.UserInvisibleModule)
mm.RegisterModule(Ruler, t.initRuler)
Expand All @@ -375,19 +376,20 @@ func (t *Loki) setupModuleManager() error {

// Add dependencies
deps := map[string][]string{
Ring: {RuntimeConfig, Server, MemberlistKV},
Overrides: {RuntimeConfig},
TenantConfigs: {RuntimeConfig},
Distributor: {Ring, Server, Overrides, TenantConfigs},
Store: {Overrides},
Ingester: {Store, Server, MemberlistKV, TenantConfigs},
Querier: {Store, Ring, Server, IngesterQuerier, TenantConfigs},
QueryFrontend: {Server, Overrides, TenantConfigs},
Ruler: {Ring, Server, Store, RulerStorage, IngesterQuerier, Overrides, TenantConfigs},
TableManager: {Server},
Compactor: {Server, Overrides},
IngesterQuerier: {Ring},
All: {Querier, Ingester, Distributor, TableManager, Ruler},
Ring: {RuntimeConfig, Server, MemberlistKV},
Overrides: {RuntimeConfig},
TenantConfigs: {RuntimeConfig},
Distributor: {Ring, Server, Overrides, TenantConfigs},
Store: {Overrides},
Ingester: {Store, Server, MemberlistKV, TenantConfigs},
Querier: {Store, Ring, Server, IngesterQuerier, TenantConfigs},
QueryFrontendTripperware: {Server, Overrides, TenantConfigs},
QueryFrontend: {QueryFrontendTripperware},
Ruler: {Ring, Server, Store, RulerStorage, IngesterQuerier, Overrides, TenantConfigs},
TableManager: {Server},
Compactor: {Server, Overrides},
IngesterQuerier: {Ring},
All: {Querier, Ingester, Distributor, TableManager, Ruler},
}

// Add IngesterQuerier as a dependency for store when target is either ingester or querier.
Expand Down
77 changes: 39 additions & 38 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,24 @@ const maxChunkAgeForTableManager = 12 * time.Hour

// The various modules that make up Loki.
const (
Ring string = "ring"
RuntimeConfig string = "runtime-config"
Overrides string = "overrides"
TenantConfigs string = "tenant-configs"
Server string = "server"
Distributor string = "distributor"
Ingester string = "ingester"
Querier string = "querier"
IngesterQuerier string = "ingester-querier"
QueryFrontend string = "query-frontend"
RulerStorage string = "ruler-storage"
Ruler string = "ruler"
Store string = "store"
TableManager string = "table-manager"
MemberlistKV string = "memberlist-kv"
Compactor string = "compactor"
All string = "all"
Ring string = "ring"
RuntimeConfig string = "runtime-config"
Overrides string = "overrides"
TenantConfigs string = "tenant-configs"
Server string = "server"
Distributor string = "distributor"
Ingester string = "ingester"
Querier string = "querier"
IngesterQuerier string = "ingester-querier"
QueryFrontend string = "query-frontend"
QueryFrontendTripperware string = "query-frontend-tripperware"
RulerStorage string = "ruler-storage"
Ruler string = "ruler"
Store string = "store"
TableManager string = "table-manager"
MemberlistKV string = "memberlist-kv"
Compactor string = "compactor"
All string = "all"
)

func (t *Loki) initServer() (services.Service, error) {
Expand Down Expand Up @@ -377,6 +378,26 @@ type disabledShuffleShardingLimits struct{}

func (disabledShuffleShardingLimits) MaxQueriersPerUser(userID string) int { return 0 }

func (t *Loki) initQueryFrontendTripperware() (_ services.Service, err error) {
level.Debug(util_log.Logger).Log("msg", "initializing query frontend tripperware")

tripperware, stopper, err := queryrange.NewTripperware(
t.Cfg.QueryRange,
util_log.Logger,
t.overrides,
t.Cfg.SchemaConfig.SchemaConfig,
t.Cfg.Querier.QueryIngestersWithin,
prometheus.DefaultRegisterer,
)
if err != nil {
return
}
t.stopper = stopper
t.QueryFrontEndTripperware = tripperware

return services.NewIdleService(nil, nil), nil
}

func (t *Loki) initQueryFrontend() (_ services.Service, err error) {
level.Debug(util_log.Logger).Log("msg", "initializing query frontend", "config", fmt.Sprintf("%+v", t.Cfg.Frontend))

Expand All @@ -394,27 +415,7 @@ func (t *Loki) initQueryFrontend() (_ services.Service, err error) {
frontendv1pb.RegisterFrontendServer(t.Server.GRPC, t.frontend)
}

level.Debug(util_log.Logger).Log("msg", "initializing query range tripperware",
"config", fmt.Sprintf("%+v", t.Cfg.QueryRange),
"limits", fmt.Sprintf("%+v", t.Cfg.LimitsConfig),
)
tripperware, stopper, err := queryrange.NewTripperware(
t.Cfg.QueryRange,
util_log.Logger,
t.overrides,
t.Cfg.SchemaConfig.SchemaConfig,
t.Cfg.Querier.QueryIngestersWithin,
prometheus.DefaultRegisterer,
)
if err != nil {
return
}
t.stopper = stopper

roundTripper = tripperware(roundTripper)
if t.QueryFrontEndTripperware != nil {
roundTripper = t.QueryFrontEndTripperware(roundTripper)
}
roundTripper = t.QueryFrontEndTripperware(roundTripper)

frontendHandler := transport.NewHandler(t.Cfg.Frontend.Handler, roundTripper, util_log.Logger, prometheus.DefaultRegisterer)
if t.Cfg.Frontend.CompressResponses {
Expand Down

0 comments on commit 3c47735

Please sign in to comment.