app/vminsert: add /-/reload handler in the same way as for vmagent

This commit is contained in:
Aliaksandr Valialkin 2020-04-30 02:15:39 +03:00
parent a970705d8e
commit b21b73115a
2 changed files with 10 additions and 7 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt"
"net/http"
"strings"
"syscall"
"time"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmagent/csvimport"
@ -160,11 +159,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
return true
case "/-/reload":
promscrapeConfigReloadRequests.Inc()
if err := syscall.Kill(syscall.Getpid(), syscall.SIGHUP); err != nil {
promscrapeConfigReloadErrors.Inc()
httpserver.Errorf(w, "Fail to reload config file, %s", err)
return true
}
procutil.SelfSIGHUP()
w.WriteHeader(http.StatusNoContent)
return true
}
@ -189,5 +184,4 @@ var (
promscrapeTargetsRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/targets"}`)
promscrapeConfigReloadRequests = metrics.NewCounter(`vmagent_http_requests_total{path="/-/reload"}`)
promscrapeConfigReloadErrors = metrics.NewCounter(`vmagent_http_request_errors_total{path="/-/reload"}`)
)

View File

@ -4,6 +4,8 @@ import (
"os"
"os/signal"
"syscall"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
)
// WaitForSigterm waits for either SIGTERM or SIGINT
@ -24,3 +26,10 @@ func WaitForSigterm() os.Signal {
return sig
}
}
// SelfSIGHUP sends SIGHUP signal to the current process.
func SelfSIGHUP() {
if err := syscall.Kill(syscall.Getpid(), syscall.SIGHUP); err != nil {
logger.Panicf("FATAL: cannot send SIGHUP to itself: %s", err)
}
}