@@ -136,6 +136,19 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
136136 resp , err := f .roundTripper .RoundTrip (r )
137137 queryResponseTime := time .Since (startTime )
138138
139+ // Check whether we should parse the query string.
140+ shouldReportSlowQuery := f .cfg .LogQueriesLongerThan != 0 && queryResponseTime > f .cfg .LogQueriesLongerThan
141+ if shouldReportSlowQuery || f .cfg .QueryStatsEnabled {
142+ queryString = f .parseRequestQueryString (r , buf )
143+ }
144+
145+ if shouldReportSlowQuery {
146+ f .reportSlowQuery (r , queryString , queryResponseTime )
147+ }
148+ if f .cfg .QueryStatsEnabled {
149+ f .reportQueryStats (r , queryString , queryResponseTime , stats )
150+ }
151+
139152 if err != nil {
140153 writeError (w , err )
141154 return
@@ -156,19 +169,6 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
156169 if err != nil && ! errors .Is (err , syscall .EPIPE ) {
157170 level .Error (util_log .WithContext (r .Context (), f .log )).Log ("msg" , "write response body error" , "bytesCopied" , bytesCopied , "err" , err )
158171 }
159-
160- // Check whether we should parse the query string.
161- shouldReportSlowQuery := f .cfg .LogQueriesLongerThan != 0 && queryResponseTime > f .cfg .LogQueriesLongerThan
162- if shouldReportSlowQuery || f .cfg .QueryStatsEnabled {
163- queryString = f .parseRequestQueryString (r , buf )
164- }
165-
166- if shouldReportSlowQuery {
167- f .reportSlowQuery (r , queryString , queryResponseTime )
168- }
169- if f .cfg .QueryStatsEnabled {
170- f .reportQueryStats (r , queryString , queryResponseTime , stats )
171- }
172172}
173173
174174// reportSlowQuery reports slow queries.
0 commit comments