* Return reload status from http endpoint (#1152) * Use same reload messaging as prometheus
This commit is contained in:
parent
0b5af7510b
commit
3c61fe3fef
|
@ -345,7 +345,7 @@ func main() {
|
|||
router = router.WithPrefix(*routePrefix)
|
||||
}
|
||||
|
||||
webReload := make(chan struct{})
|
||||
webReload := make(chan chan error)
|
||||
|
||||
ui.Register(router, webReload, logger)
|
||||
|
||||
|
@ -367,9 +367,10 @@ func main() {
|
|||
for {
|
||||
select {
|
||||
case <-hup:
|
||||
case <-webReload:
|
||||
reload()
|
||||
case errc := <-webReload:
|
||||
errc <- reload()
|
||||
}
|
||||
reload()
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
11
ui/web.go
11
ui/web.go
|
@ -48,7 +48,7 @@ func serveAsset(w http.ResponseWriter, req *http.Request, fp string, logger log.
|
|||
}
|
||||
|
||||
// Register registers handlers to serve files for the web interface.
|
||||
func Register(r *route.Router, reloadCh chan<- struct{}, logger log.Logger) {
|
||||
func Register(r *route.Router, reloadCh chan<- chan error, logger log.Logger) {
|
||||
ihf := prometheus.InstrumentHandlerFunc
|
||||
|
||||
r.Get("/metrics", prometheus.Handler().ServeHTTP)
|
||||
|
@ -73,8 +73,13 @@ func Register(r *route.Router, reloadCh chan<- struct{}, logger log.Logger) {
|
|||
))
|
||||
|
||||
r.Post("/-/reload", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Write([]byte("Reloading configuration file..."))
|
||||
reloadCh <- struct{}{}
|
||||
errc := make(chan error)
|
||||
defer close(errc)
|
||||
|
||||
reloadCh <- errc
|
||||
if err := <-errc; err != nil {
|
||||
http.Error(w, fmt.Sprintf("failed to reload config: %s", err), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
|
||||
r.Get("/-/healthy", func(w http.ResponseWriter, _ *http.Request) {
|
||||
|
|
Loading…
Reference in New Issue