Skip to content

Commit

Permalink
add SafeReadRing for instances when scheduler is not enabled on same …
Browse files Browse the repository at this point in the history
…instance
  • Loading branch information
trevorwhitney committed Oct 20, 2021
1 parent 5d15fc9 commit 61d035f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (t *Loki) initQuerier() (services.Service, error) {
QuerierWorkerConfig: &t.Cfg.Worker,
QueryFrontendEnabled: t.Cfg.isModuleEnabled(QueryFrontend),
QuerySchedulerEnabled: t.Cfg.isModuleEnabled(QueryScheduler),
SchedulerRing: t.queryScheduler.ReadRing(),
SchedulerRing: t.queryScheduler.SafeReadRing(),
}

var queryHandlers = map[string]http.Handler{
Expand Down Expand Up @@ -415,12 +415,20 @@ func (t *Loki) initQueryFrontendTripperware() (_ services.Service, err error) {
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))

roundTripper, frontendV1, frontendV2, err := frontend.InitFrontend(frontend.CombinedFrontendConfig{
combinedCfg := frontend.CombinedFrontendConfig{
Handler: t.Cfg.Frontend.Handler,
FrontendV1: t.Cfg.Frontend.FrontendV1,
FrontendV2: t.Cfg.Frontend.FrontendV2,
DownstreamURL: t.Cfg.Frontend.DownstreamURL,
}, t.queryScheduler.ReadRing(), disabledShuffleShardingLimits{}, t.Cfg.Server.GRPCListenPort, util_log.Logger, prometheus.DefaultRegisterer)
}
roundTripper, frontendV1, frontendV2, err := frontend.InitFrontend(
combinedCfg,
t.queryScheduler.SafeReadRing(),
disabledShuffleShardingLimits{},
t.Cfg.Server.GRPCListenPort,
util_log.Logger,
prometheus.DefaultRegisterer)

if err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,17 @@ func (s *Scheduler) getConnectedFrontendClientsMetric() float64 {
return float64(count)
}

// SafeReadRing does a nil check on the Scheduler before attempting to return it's ring
// this is necessary as many callers of this function will only have a valid Scheduler
// reference if the QueryScheduler target has been specified, which is not guaranteed
func (s *Scheduler) SafeReadRing() ring.ReadRing {
if s == nil {
return nil
}

return s.ReadRing()
}

// ReadRing returns the scheduler ring as a ReadRing interface,
// it returns nil if UseSchedulerRing == false
func (s *Scheduler) ReadRing() ring.ReadRing {
Expand Down

0 comments on commit 61d035f

Please sign in to comment.