app/vmselect: show query origin (aka remote_addr or client address) on the /api/v1/status/active_queries page for every query

This commit is contained in:
Aliaksandr Valialkin 2020-07-28 15:12:48 +03:00
parent 2f1e7298ce
commit 79c30cf4cb
3 changed files with 14 additions and 8 deletions

View file

@ -693,6 +693,7 @@ func QueryHandler(startTime time.Time, w http.ResponseWriter, r *http.Request) e
Start: start, Start: start,
End: start, End: start,
Step: step, Step: step,
RemoteAddr: r.RemoteAddr,
Deadline: deadline, Deadline: deadline,
LookbackDelta: lookbackDelta, LookbackDelta: lookbackDelta,
} }
@ -777,6 +778,7 @@ func queryRangeHandler(startTime time.Time, w http.ResponseWriter, query string,
Start: start, Start: start,
End: end, End: end,
Step: step, Step: step,
RemoteAddr: r.RemoteAddr,
Deadline: deadline, Deadline: deadline,
MayCache: mayCache, MayCache: mayCache,
LookbackDelta: lookbackDelta, LookbackDelta: lookbackDelta,

View file

@ -20,7 +20,8 @@ func WriteActiveQueries(w io.Writer) {
now := time.Now() now := time.Now()
for _, aqe := range aqes { for _, aqe := range aqes {
d := now.Sub(aqe.startTime) d := now.Sub(aqe.startTime)
fmt.Fprintf(w, "\tduration: %.3fs, id=%016X, query=%q, start=%d, end=%d, step=%d\n", d.Seconds(), aqe.qid, aqe.q, aqe.start, aqe.end, aqe.step) fmt.Fprintf(w, "\tduration: %.3fs, id=%016X, remote_addr=%q, query=%q, start=%d, end=%d, step=%d\n",
d.Seconds(), aqe.qid, aqe.remoteAddr, aqe.q, aqe.start, aqe.end, aqe.step)
} }
} }
@ -32,12 +33,13 @@ type activeQueries struct {
} }
type activeQueryEntry struct { type activeQueryEntry struct {
start int64 start int64
end int64 end int64
step int64 step int64
qid uint64 qid uint64
q string remoteAddr string
startTime time.Time q string
startTime time.Time
} }
func newActiveQueries() *activeQueries { func newActiveQueries() *activeQueries {
@ -52,6 +54,7 @@ func (aq *activeQueries) Add(ec *EvalConfig, q string) uint64 {
aqe.end = ec.End aqe.end = ec.End
aqe.step = ec.Step aqe.step = ec.Step
aqe.qid = atomic.AddUint64(&nextActiveQueryID, 1) aqe.qid = atomic.AddUint64(&nextActiveQueryID, 1)
aqe.remoteAddr = ec.RemoteAddr
aqe.q = q aqe.q = q
aqe.startTime = time.Now() aqe.startTime = time.Now()

View file

@ -75,7 +75,8 @@ type EvalConfig struct {
End int64 End int64
Step int64 Step int64
Deadline netstorage.Deadline RemoteAddr string
Deadline netstorage.Deadline
MayCache bool MayCache bool