File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -225,16 +225,27 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
225
225
r .Body = io .NopCloser (& buf )
226
226
}
227
227
228
+ // Log request
229
+ if f .cfg .QueryStatsEnabled {
230
+ queryString = f .parseRequestQueryString (r , buf )
231
+ logMessage := append ([]interface {}{
232
+ "msg" , "query request" ,
233
+ "component" , "query-frontend" ,
234
+ "method" , r .Method ,
235
+ "path" , r .URL .Path ,
236
+ }, formatQueryString (queryString )... )
237
+ level .Info (util_log .WithContext (r .Context (), f .log )).Log (logMessage ... )
238
+ }
239
+
228
240
startTime := time .Now ()
229
241
resp , err := f .roundTripper .RoundTrip (r )
230
242
queryResponseTime := time .Since (startTime )
231
243
232
- // Check whether we should parse the query string.
244
+ // Check if we need to parse the query string to avoid parsing twice .
233
245
shouldReportSlowQuery := f .cfg .LogQueriesLongerThan != 0 && queryResponseTime > f .cfg .LogQueriesLongerThan
234
- if shouldReportSlowQuery || f .cfg .QueryStatsEnabled {
246
+ if shouldReportSlowQuery && ! f .cfg .QueryStatsEnabled {
235
247
queryString = f .parseRequestQueryString (r , buf )
236
248
}
237
-
238
249
if shouldReportSlowQuery {
239
250
f .reportSlowQuery (r , queryString , queryResponseTime )
240
251
}
You can’t perform that action at this time.
0 commit comments