From 50686ee9cde9be54e68982ca875955f453a23e6c Mon Sep 17 00:00:00 2001 From: Ahmed Hassan Date: Mon, 2 Dec 2024 13:31:22 -0800 Subject: [PATCH 1/2] log query string in QFE before executing query request Signed-off-by: Ahmed Hassan --- pkg/frontend/transport/handler.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/frontend/transport/handler.go b/pkg/frontend/transport/handler.go index 19d65c302f2..75719b78477 100644 --- a/pkg/frontend/transport/handler.go +++ b/pkg/frontend/transport/handler.go @@ -225,16 +225,27 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { r.Body = io.NopCloser(&buf) } + // Log request + if f.cfg.QueryStatsEnabled { + queryString = f.parseRequestQueryString(r, buf) + logMessage := append([]interface{}{ + "msg", "query request", + "component", "query-frontend", + "method", r.Method, + "path", r.URL.Path, + }, formatQueryString(queryString)...) + level.Info(util_log.WithContext(r.Context(), f.log)).Log(logMessage...) + } + startTime := time.Now() resp, err := f.roundTripper.RoundTrip(r) queryResponseTime := time.Since(startTime) - // Check whether we should parse the query string. + // Check if we need to parse the query string to avoid parsing twice. shouldReportSlowQuery := f.cfg.LogQueriesLongerThan != 0 && queryResponseTime > f.cfg.LogQueriesLongerThan - if shouldReportSlowQuery || f.cfg.QueryStatsEnabled { + if shouldReportSlowQuery && !f.cfg.QueryStatsEnabled { queryString = f.parseRequestQueryString(r, buf) } - if shouldReportSlowQuery { f.reportSlowQuery(r, queryString, queryResponseTime) } From 75289a810210f35a3b63a963602b3bd42813e5f6 Mon Sep 17 00:00:00 2001 From: Ahmed Hassan Date: Mon, 2 Dec 2024 13:38:23 -0800 Subject: [PATCH 2/2] fix formatting Signed-off-by: Ahmed Hassan --- pkg/frontend/transport/handler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/frontend/transport/handler.go b/pkg/frontend/transport/handler.go index 75719b78477..b4ecca59eed 100644 --- a/pkg/frontend/transport/handler.go +++ b/pkg/frontend/transport/handler.go @@ -234,7 +234,7 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { "method", r.Method, "path", r.URL.Path, }, formatQueryString(queryString)...) - level.Info(util_log.WithContext(r.Context(), f.log)).Log(logMessage...) + level.Info(util_log.WithContext(r.Context(), f.log)).Log(logMessage...) } startTime := time.Now()