mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-14 16:12:15 +01:00
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:
parent
3149af624d
commit
a2aa3a60eb
@ -18,6 +18,7 @@ import (
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/auth"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/fasttime"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/flagutil"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
||||
"github.com/VictoriaMetrics/VictoriaMetrics/lib/storage"
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
@ -770,13 +771,13 @@ func QueryHandler(startTime time.Time, at *auth.Token, w http.ResponseWriter, r
|
||||
}
|
||||
|
||||
ec := promql.EvalConfig{
|
||||
AuthToken: at,
|
||||
Start: start,
|
||||
End: start,
|
||||
Step: step,
|
||||
RemoteAddr: r.RemoteAddr,
|
||||
Deadline: deadline,
|
||||
LookbackDelta: lookbackDelta,
|
||||
AuthToken: at,
|
||||
Start: start,
|
||||
End: start,
|
||||
Step: step,
|
||||
QuotedRemoteAddr: httpserver.GetQuotedRemoteAddr(r),
|
||||
Deadline: deadline,
|
||||
LookbackDelta: lookbackDelta,
|
||||
|
||||
DenyPartialResponse: getDenyPartialResponse(r),
|
||||
}
|
||||
@ -858,14 +859,14 @@ func queryRangeHandler(startTime time.Time, at *auth.Token, w http.ResponseWrite
|
||||
}
|
||||
|
||||
ec := promql.EvalConfig{
|
||||
AuthToken: at,
|
||||
Start: start,
|
||||
End: end,
|
||||
Step: step,
|
||||
RemoteAddr: r.RemoteAddr,
|
||||
Deadline: deadline,
|
||||
MayCache: mayCache,
|
||||
LookbackDelta: lookbackDelta,
|
||||
AuthToken: at,
|
||||
Start: start,
|
||||
End: end,
|
||||
Step: step,
|
||||
QuotedRemoteAddr: httpserver.GetQuotedRemoteAddr(r),
|
||||
Deadline: deadline,
|
||||
MayCache: mayCache,
|
||||
LookbackDelta: lookbackDelta,
|
||||
|
||||
DenyPartialResponse: getDenyPartialResponse(r),
|
||||
}
|
||||
|
@ -20,8 +20,8 @@ func WriteActiveQueries(w io.Writer) {
|
||||
now := time.Now()
|
||||
for _, aqe := range aqes {
|
||||
d := now.Sub(aqe.startTime)
|
||||
fmt.Fprintf(w, "\tduration: %.3fs, id=%016X, remote_addr=%q, accountID=%d, projectID=%d, query=%q, start=%d, end=%d, step=%d\n",
|
||||
d.Seconds(), aqe.qid, aqe.remoteAddr, aqe.accountID, aqe.projectID, aqe.q, aqe.start, aqe.end, aqe.step)
|
||||
fmt.Fprintf(w, "\tduration: %.3fs, id=%016X, remote_addr=%s, accountID=%d, projectID=%d, query=%q, start=%d, end=%d, step=%d\n",
|
||||
d.Seconds(), aqe.qid, aqe.quotedRemoteAddr, aqe.accountID, aqe.projectID, aqe.q, aqe.start, aqe.end, aqe.step)
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,15 +33,15 @@ type activeQueries struct {
|
||||
}
|
||||
|
||||
type activeQueryEntry struct {
|
||||
accountID uint32
|
||||
projectID uint32
|
||||
start int64
|
||||
end int64
|
||||
step int64
|
||||
qid uint64
|
||||
remoteAddr string
|
||||
q string
|
||||
startTime time.Time
|
||||
accountID uint32
|
||||
projectID uint32
|
||||
start int64
|
||||
end int64
|
||||
step int64
|
||||
qid uint64
|
||||
quotedRemoteAddr string
|
||||
q string
|
||||
startTime time.Time
|
||||
}
|
||||
|
||||
func newActiveQueries() *activeQueries {
|
||||
@ -58,7 +58,7 @@ func (aq *activeQueries) Add(ec *EvalConfig, q string) uint64 {
|
||||
aqe.end = ec.End
|
||||
aqe.step = ec.Step
|
||||
aqe.qid = atomic.AddUint64(&nextActiveQueryID, 1)
|
||||
aqe.remoteAddr = ec.RemoteAddr
|
||||
aqe.quotedRemoteAddr = ec.QuotedRemoteAddr
|
||||
aqe.q = q
|
||||
aqe.startTime = time.Now()
|
||||
|
||||
|
@ -83,8 +83,10 @@ type EvalConfig struct {
|
||||
End int64
|
||||
Step int64
|
||||
|
||||
RemoteAddr string
|
||||
Deadline netstorage.Deadline
|
||||
// QuotedRemoteAddr contains quoted remote address.
|
||||
QuotedRemoteAddr string
|
||||
|
||||
Deadline netstorage.Deadline
|
||||
|
||||
MayCache bool
|
||||
|
||||
|
@ -430,13 +430,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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user