From 0cbe5ccb4a9ad7533d823b5601944295210490dd Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 20 Jul 2023 11:18:19 -0700 Subject: [PATCH] app/vmselect: rename promql.WriteActiveQueries() to promql.ActiveQueriesHandler() This makes it more consistent with the rest of handlers inside app/vmselect/main.go This is a follow-up for 6a96fd8ed5ba738f545dab8a3896ab4661eacbf7 Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4598 --- app/vmselect/main.go | 4 ++-- app/vmselect/promql/active_queries.go | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) 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) }