diff --git a/app/vmselect/main.go b/app/vmselect/main.go index 61469fa21a..3ccf38085f 100644 --- a/app/vmselect/main.go +++ b/app/vmselect/main.go @@ -269,7 +269,7 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool { if path == "/api/v1/status/active_queries" { globalStatusActiveQueriesRequests.Inc() httpserver.EnableCORS(w, r) - promql.WriteActiveQueries(w, r) + promql.ActiveQueriesHandler(nil, w, r) return true } if path == "/admin/tenants" { @@ -507,7 +507,7 @@ func selectHandler(qt *querytracer.Tracer, startTime time.Time, w http.ResponseW case "prometheus/api/v1/status/active_queries": statusActiveQueriesRequests.Inc() httpserver.EnableCORS(w, r) - promql.WriteActiveQueriesForTenant(at, w, r) + promql.ActiveQueriesHandler(at, w, r) return true case "prometheus/api/v1/status/top_queries": topQueriesRequests.Inc() diff --git a/app/vmselect/promql/active_queries.go b/app/vmselect/promql/active_queries.go index b7320bcb06..4c46f51762 100644 --- a/app/vmselect/promql/active_queries.go +++ b/app/vmselect/promql/active_queries.go @@ -11,21 +11,23 @@ import ( "github.com/VictoriaMetrics/VictoriaMetrics/lib/auth" ) -// WriteActiveQueriesForTenant writes active queries for the given (accountID, projectID) to w. -func WriteActiveQueriesForTenant(at *auth.Token, w http.ResponseWriter, r *http.Request) { +// ActiveQueriesHandler returns response to /api/v1/status/active_queries +// +// It writes a JSON with active queries to w. +// +// If at is nil, then all the active queries across all the tenants are written. +func ActiveQueriesHandler(at *auth.Token, w http.ResponseWriter, r *http.Request) { aqes := activeQueriesV.GetAll() - var dst []activeQueryEntry - for _, aqe := range aqes { - if aqe.accountID == at.AccountID && aqe.projectID == at.ProjectID { - dst = append(dst, aqe) + if at != nil { + // Filter out queries, which do not belong to at. + dst := aqes[:0] + for _, aqe := range aqes { + if aqe.accountID == at.AccountID && aqe.projectID == at.ProjectID { + dst = append(dst, aqe) + } } + aqes = dst } - writeActiveQueries(w, dst) -} - -// WriteActiveQueries writes active queries to w. -func WriteActiveQueries(w http.ResponseWriter, r *http.Request) { - aqes := activeQueriesV.GetAll() writeActiveQueries(w, aqes) }