don't return empty responses to lifecycle api requests

Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
glightfoot 2021-01-26 13:29:23 -05:00
parent 64dd103e3f
commit 6a9749cd42

11
main.go
View file

@ -477,9 +477,14 @@ func main() {
</body> </body>
</html>`)) </html>`))
}) })
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
if *enableLifecycle { if *enableLifecycle {
mux.HandleFunc("/-/reload", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/-/reload", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPut || r.Method == http.MethodPost { if r.Method == http.MethodPut || r.Method == http.MethodPost {
fmt.Fprintf(w, "Requesting reload")
if *mappingConfig == "" { if *mappingConfig == "" {
level.Warn(logger).Log("msg", "Received lifecycle api reload but no mapping config to reload") level.Warn(logger).Log("msg", "Received lifecycle api reload but no mapping config to reload")
return return
@ -490,8 +495,9 @@ func main() {
}) })
mux.HandleFunc("/-/quit", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/-/quit", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPut || r.Method == http.MethodPost { if r.Method == http.MethodPut || r.Method == http.MethodPost {
fmt.Fprintf(w, "Requesting termination... Goodbye!")
level.Info(logger).Log("msg", "Received lifecycle api quit, exiting") level.Info(logger).Log("msg", "Received lifecycle api quit, exiting")
os.Exit(0) signals <- os.Kill
} }
}) })
} }
@ -514,9 +520,6 @@ func main() {
go serveHTTP(mux, *listenAddress, logger) go serveHTTP(mux, *listenAddress, logger)
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
go sighupConfigReloader(*mappingConfig, mapper, *cacheSize, logger, cacheOption) go sighupConfigReloader(*mappingConfig, mapper, *cacheSize, logger, cacheOption)
go exporter.Listen(events) go exporter.Listen(events)