app/vmselect: show X-Forwarded-For contents on /api/v1/status/active_queries page

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/659
This commit is contained in:
Aliaksandr Valialkin
2020-07-31 18:00:21 +03:00
parent 5e71fab8a6
commit 509d12643b
4 changed files with 37 additions and 28 deletions

View File

@@ -481,13 +481,19 @@ var (
requestsTotal = metrics.NewCounter(`vm_http_requests_all_total`)
)
// Errorf writes formatted error message to w and to logger.
func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...interface{}) {
errStr := fmt.Sprintf(format, args...)
// GetQuotedRemoteAddr returns quoted remote address.
func GetQuotedRemoteAddr(r *http.Request) string {
remoteAddr := strconv.Quote(r.RemoteAddr) // quote remoteAddr and X-Forwarded-For, since they may contain untrusted input
if addr := r.Header.Get("X-Forwarded-For"); addr != "" {
remoteAddr += ", X-Forwarded-For: " + strconv.Quote(addr)
}
return remoteAddr
}
// Errorf writes formatted error message to w and to logger.
func Errorf(w http.ResponseWriter, r *http.Request, format string, args ...interface{}) {
errStr := fmt.Sprintf(format, args...)
remoteAddr := GetQuotedRemoteAddr(r)
errStr = fmt.Sprintf("remoteAddr: %s; %s", remoteAddr, errStr)
logger.WarnfSkipframes(1, "%s", errStr)