From 3c61fe3fefff4ed28ae7a0d7ba3dd20e56bd0d13 Mon Sep 17 00:00:00 2001 From: stuart nelson Date: Mon, 8 Jan 2018 11:51:05 +0100 Subject: [PATCH] Return reload status from http endpoint (#1152) (#1180) * Return reload status from http endpoint (#1152) * Use same reload messaging as prometheus --- cmd/alertmanager/main.go | 7 ++++--- ui/web.go | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index e22a8134..0957c049 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -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() } }() diff --git a/ui/web.go b/ui/web.go index 321a92e9..5f17ef2c 100644 --- a/ui/web.go +++ b/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) {