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 825a2dd554
commit 432187ac3b
3 changed files with 18 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

@ -19,6 +19,7 @@ import (
influxserver "github.com/VictoriaMetrics/VictoriaMetrics/lib/ingestserver/influx"
opentsdbserver "github.com/VictoriaMetrics/VictoriaMetrics/lib/ingestserver/opentsdb"
opentsdbhttpserver "github.com/VictoriaMetrics/VictoriaMetrics/lib/ingestserver/opentsdbhttp"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/procutil"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promscrape"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
"github.com/VictoriaMetrics/VictoriaMetrics/lib/writeconcurrencylimiter"
@ -130,6 +131,11 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
w.Header().Set("Content-Type", "text/plain")
promscrape.WriteHumanReadableTargetsStatus(w)
return true
case "/-/reload":
promscrapeConfigReloadRequests.Inc()
procutil.SelfSIGHUP()
w.WriteHeader(http.StatusNoContent)
return true
default:
// This is not our link
return false
@ -152,4 +158,6 @@ var (
influxQueryRequests = metrics.NewCounter(`vm_http_requests_total{path="/query", protocol="influx"}`)
promscrapeTargetsRequests = metrics.NewCounter(`vm_http_requests_total{path="/targets"}`)
promscrapeConfigReloadRequests = metrics.NewCounter(`vm_http_requests_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)
}
}