Merge pull request #360 from glightfoot/quit

Don't return empty responses to lifecycle api requests
This commit is contained in:
Matthias Rampke 2021-01-29 10:08:05 +00:00 committed by GitHub
commit 799943cb47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

22
main.go
View file

@ -477,9 +477,13 @@ func main() {
</body>
</html>`))
})
quitChan := make(chan struct{}, 1)
if *enableLifecycle {
mux.HandleFunc("/-/reload", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPut || r.Method == http.MethodPost {
fmt.Fprintf(w, "Requesting reload")
if *mappingConfig == "" {
level.Warn(logger).Log("msg", "Received lifecycle api reload but no mapping config to reload")
return
@ -490,8 +494,8 @@ func main() {
})
mux.HandleFunc("/-/quit", func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodPut || r.Method == http.MethodPost {
level.Info(logger).Log("msg", "Received lifecycle api quit, exiting")
os.Exit(0)
fmt.Fprintf(w, "Requesting termination... Goodbye!")
quitChan <- struct{}{}
}
})
}
@ -514,11 +518,17 @@ func main() {
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 exporter.Listen(events)
<-signals
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
// quit if we get a message on either channel
select {
case sig := <-signals:
level.Info(logger).Log("msg", "Received os signal, exiting", "signal", sig.String())
case <-quitChan:
level.Info(logger).Log("msg", "Received lifecycle api quit, exiting")
}
}