From 2bf7048dbb1a60e36b0e41fc3a7ad58ecb3a8c4e Mon Sep 17 00:00:00 2001 From: Jan Berktold Date: Tue, 11 Aug 2015 09:08:17 +0200 Subject: [PATCH 1/2] Add reload handler to web --- cmd/prometheus/main.go | 6 +++++- web/web.go | 13 +++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cmd/prometheus/main.go b/cmd/prometheus/main.go index f8d8aa993d..529211eb3d 100644 --- a/cmd/prometheus/main.go +++ b/cmd/prometheus/main.go @@ -104,7 +104,11 @@ func Main() int { signal.Notify(hup, syscall.SIGHUP) go func() { <-hupReady - for range hup { + for { + select { + case <-hup: + case <-webHandler.Reload(): + } reloadConfig(cfg.configFile, status, targetManager, ruleManager) } }() diff --git a/web/web.go b/web/web.go index 5fe92cf5d8..34de6eec18 100644 --- a/web/web.go +++ b/web/web.go @@ -61,6 +61,7 @@ type Handler struct { router *route.Router quitCh chan struct{} + reloadCh chan bool // boolean saves as placeholder, actual value does not matter options *Options statusInfo *PrometheusStatus @@ -111,6 +112,7 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh h := &Handler{ router: router, quitCh: make(chan struct{}), + reloadCh: make(chan bool), options: o, statusInfo: status, @@ -171,6 +173,7 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh router.Post("/-/quit", h.quit) } + router.Post("/reload", h.reload) router.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP) return h @@ -181,6 +184,11 @@ func (h *Handler) Quit() <-chan struct{} { return h.quitCh } + +func (h *Handler) Reload() <-chan bool { + return h.reloadCh +} + // Run serves the HTTP endpoints. func (h *Handler) Run() { log.Infof("Listening on %s", h.options.ListenAddress) @@ -293,6 +301,11 @@ func (h *Handler) quit(w http.ResponseWriter, r *http.Request) { close(h.quitCh) } +func (h *Handler) reload(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Reloading configuration file...") + h.reloadCh <- true +} + func (h *Handler) getTemplateFile(name string) (string, error) { if h.options.UseLocalAssets { file, err := ioutil.ReadFile(fmt.Sprintf("web/blob/templates/%s.html", name)) From fa929a8345123b59f68dcad6a733edaeb3f567f6 Mon Sep 17 00:00:00 2001 From: Jan Berktold Date: Tue, 11 Aug 2015 12:26:41 +0200 Subject: [PATCH 2/2] Change /reload to /-/reload & and fix channel type --- web/web.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/web/web.go b/web/web.go index 34de6eec18..1d603c2dbe 100644 --- a/web/web.go +++ b/web/web.go @@ -61,7 +61,7 @@ type Handler struct { router *route.Router quitCh chan struct{} - reloadCh chan bool // boolean saves as placeholder, actual value does not matter + reloadCh chan struct{} options *Options statusInfo *PrometheusStatus @@ -112,7 +112,7 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh h := &Handler{ router: router, quitCh: make(chan struct{}), - reloadCh: make(chan bool), + reloadCh: make(chan struct{}), options: o, statusInfo: status, @@ -173,7 +173,7 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh router.Post("/-/quit", h.quit) } - router.Post("/reload", h.reload) + router.Post("/-/reload", h.reload) router.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP) return h @@ -184,8 +184,7 @@ func (h *Handler) Quit() <-chan struct{} { return h.quitCh } - -func (h *Handler) Reload() <-chan bool { +func (h *Handler) Reload() <-chan struct{} { return h.reloadCh } @@ -303,7 +302,7 @@ func (h *Handler) quit(w http.ResponseWriter, r *http.Request) { func (h *Handler) reload(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Reloading configuration file...") - h.reloadCh <- true + h.reloadCh <- struct{}{} } func (h *Handler) getTemplateFile(name string) (string, error) {