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 6a96fd8ed5

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4598
This commit is contained in:
Aliaksandr Valialkin 2023-07-20 11:18:19 -07:00
parent 992c300ce9
commit 0cbe5ccb4a
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1
2 changed files with 16 additions and 14 deletions

View File

@ -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()

View File

@ -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)
}