diff --git a/pkg/frontend/transport/handler.go b/pkg/frontend/transport/handler.go index 19d65c302f..75719b7847 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) }