scheduler: fix panic on hitting /scheduler/ring when ring is disabled (#8120)

Fixes nil pointer dereference that occurs on calling `/scheduler/ring`
endpoint when `use_scheduler_ring` is set to false.

```
/usr/local/go/src/runtime/panic.go:884 +0x212
github.com/grafana/dskit/ring.(*Ring).ServeHTTP(...)
/src/enterprise-logs/vendor/github.com/grafana/dskit/ring/ring.go:858
github.com/grafana/loki/pkg/scheduler.(*Scheduler).ServeHTTP(0xc00056ba00?, {0x2ca0068?, 0xc001d95140?}, 0xc0005752a8?)
/src/enterprise-logs/vendor/github.com/grafana/loki/pkg/scheduler/scheduler.go:765 +0x25
```

Signed-off-by: Ashwanth Goli <iamashwanth@gmail.com>
pull/8100/head
Ashwanth 2 years ago committed by GitHub
parent b8153d3108
commit 361e7f7f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 6
      pkg/scheduler/scheduler.go

@ -37,6 +37,7 @@
* [7966](https://github.com/grafana/loki/pull/7966) **sandeepsukhani**: Fix query-frontend request load balancing when using k8s service.
* [7988](https://github.com/grafana/loki/pull/7988) **ashwanthgoli** store: write overlapping chunks to multiple stores.
* [7925](https://github.com/grafana/loki/pull/7925) **sandeepsukhani**: Fix bugs in logs results caching causing query-frontend to return logs outside of query window.
* [8120](https://github.com/grafana/loki/pull/8120) **ashwanthgoli** fix panic on hitting /scheduler/ring when ring is disabled.
##### Changes

@ -762,5 +762,9 @@ func (s *Scheduler) OnRingInstanceHeartbeat(_ *ring.BasicLifecycler, _ *ring.Des
}
func (s *Scheduler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.ring.ServeHTTP(w, req)
if s.cfg.UseSchedulerRing {
s.ring.ServeHTTP(w, req)
} else {
_, _ = w.Write([]byte("QueryScheduler running with '-query-scheduler.use-scheduler-ring' set to false."))
}
}

Loading…
Cancel
Save