Return reload status from http endpoint (#1152) (#1180)

* Return reload status from http endpoint (#1152)

* Use same reload messaging as prometheus
This commit is contained in:
stuart nelson 2018-01-08 11:51:05 +01:00 committed by GitHub
parent 0b5af7510b
commit 3c61fe3fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -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()
}
}()

View File

@ -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) {