@@ -136,6 +136,19 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
136
136
resp , err := f .roundTripper .RoundTrip (r )
137
137
queryResponseTime := time .Since (startTime )
138
138
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
+
139
152
if err != nil {
140
153
writeError (w , err )
141
154
return
@@ -156,19 +169,6 @@ func (f *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
156
169
if err != nil && ! errors .Is (err , syscall .EPIPE ) {
157
170
level .Error (util_log .WithContext (r .Context (), f .log )).Log ("msg" , "write response body error" , "bytesCopied" , bytesCopied , "err" , err )
158
171
}
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
- }
172
172
}
173
173
174
174
// reportSlowQuery reports slow queries.
0 commit comments