DataProxy: Fix issue overriding response body when response status is 101 (#41364) (#41476)

When a request going through Grafana data source proxy responds with a websocket
upgrade response we cannot override the response body since it produces an error.
This problem seems to have been introduced in Grafana v8.0 by #38962.
In addition #40303 added same problem.

Fixes #41292

(cherry picked from commit 3be452f995)

Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-11-09 15:04:44 +01:00
committed by GitHub
co-authored by Marcus Efraimsson
parent af84e20232
commit fff0da8fe9
2 changed files with 5 additions and 2 deletions
@@ -96,7 +96,7 @@ func executeMiddleware(next http.RoundTripper, datasourceLabel prometheus.Labels
return nil, err
}
if res != nil {
if res != nil && res.StatusCode != http.StatusSwitchingProtocols {
res.Body = httpclient.CountBytesReader(res.Body, func(bytesRead int64) {
responseSizeSummary.Observe(float64(bytesRead))
})
@@ -21,7 +21,10 @@ func ResponseLimitMiddleware(limit int64) sdkhttpclient.Middleware {
return nil, err
}
res.Body = httpclient.MaxBytesReader(res.Body, limit)
if res != nil && res.StatusCode != http.StatusSwitchingProtocols {
res.Body = httpclient.MaxBytesReader(res.Body, limit)
}
return res, nil
})
})