diff --git a/api.go b/api.go index 3f2ce2a7..6a4a7af6 100644 --- a/api.go +++ b/api.go @@ -58,7 +58,6 @@ type API struct { config string resolveTimeout time.Duration uptime time.Time - reloadCh chan struct{} groups func() AlertOverview @@ -75,7 +74,6 @@ func NewAPI(alerts provider.Alerts, silences provider.Silences, gf func() AlertO silences: silences, groups: gf, uptime: time.Now(), - reloadCh: make(chan struct{}), } } @@ -84,9 +82,6 @@ func NewAPI(alerts provider.Alerts, silences provider.Silences, gf func() AlertO func (api *API) Register(r *route.Router) { ihf := prometheus.InstrumentHandlerFunc - // Register reload API for reload configuration. - r.Post("/-/reload", api.reload) - // Register legacy forwarder for alert pushing. r.Post("/alerts", ihf("legacy_add_alerts", api.legacyAddAlerts)) @@ -114,11 +109,6 @@ func (api *API) Update(config string, resolveTimeout time.Duration) { api.resolveTimeout = resolveTimeout } -// Reload returns the receive-only channel that signals configuration reload requests. -func (api *API) Reload() <-chan struct{} { - return api.reloadCh -} - type errorType string const ( @@ -383,11 +373,6 @@ func (api *API) listSilences(w http.ResponseWriter, r *http.Request) { respond(w, sils) } -func (api *API) reload(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Reloading configuration file...") - api.reloadCh <- struct{}{} -} - type status string const ( diff --git a/main.go b/main.go index 442b8fe4..52141e49 100644 --- a/main.go +++ b/main.go @@ -187,7 +187,8 @@ func main() { router := route.New() - RegisterWeb(router.WithPrefix(amURL.Path)) + webReload := make(chan struct{}) + RegisterWeb(router.WithPrefix(amURL.Path), webReload) api.Register(router.WithPrefix(path.Join(amURL.Path, "/api"))) log.Infoln("Listening on", *listenAddress) @@ -206,7 +207,7 @@ func main() { for { select { case <-hup: - case <-api.Reload(): + case <-webReload: } reload() } diff --git a/web.go b/web.go index 6e203849..887b3c2a 100644 --- a/web.go +++ b/web.go @@ -47,7 +47,7 @@ func serveAsset(w http.ResponseWriter, req *http.Request, fp string) { } // RegisterWeb registers handlers to serve files for the web interface. -func RegisterWeb(r *route.Router) { +func RegisterWeb(r *route.Router, reloadCh chan<- struct{}) { ihf := prometheus.InstrumentHandlerFunc r.Get("/app/*filepath", ihf("app_files", @@ -69,6 +69,11 @@ func RegisterWeb(r *route.Router) { serveAsset(w, req, "ui/app/index.html") })) + r.Post("/-/reload", func(w http.ResponseWriter, req *http.Request) { + w.Write([]byte("Reloading configuration file...")) + reloadCh <- struct{}{} + }) + r.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP) r.Post("/debug/*subpath", http.DefaultServeMux.ServeHTTP) }