mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-28 04:02:21 -04:00
Merge pull request #16437 from zenador/unwrap-read-client-error
remote: Allow unwrapping of errors when reading from remote client
This commit is contained in:
commit
f379e2eac7
2 changed files with 15 additions and 1 deletions
|
|
@ -384,7 +384,8 @@ func (c *Client) Read(ctx context.Context, query *prompb.Query, sortSeries bool)
|
|||
_ = httpResp.Body.Close()
|
||||
|
||||
cancel()
|
||||
return nil, fmt.Errorf("remote server %s returned http status %s: %s", c.urlString, httpResp.Status, string(body))
|
||||
err := errors.New(string(body))
|
||||
return nil, fmt.Errorf("remote server %s returned http status %s: %w", c.urlString, httpResp.Status, err)
|
||||
}
|
||||
|
||||
contentType := httpResp.Header.Get("Content-Type")
|
||||
|
|
|
|||
|
|
@ -225,6 +225,7 @@ func TestReadClient(t *testing.T) {
|
|||
expectedSamples [][]model.SamplePair
|
||||
expectedErrorContains string
|
||||
sortSeries bool
|
||||
unwrap bool
|
||||
}{
|
||||
{
|
||||
name: "sorted sampled response",
|
||||
|
|
@ -336,6 +337,14 @@ func TestReadClient(t *testing.T) {
|
|||
timeout: 5 * time.Millisecond,
|
||||
expectedErrorContains: "context deadline exceeded: request timed out after 5ms",
|
||||
},
|
||||
{
|
||||
name: "unwrap error",
|
||||
httpHandler: http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
http.Error(w, "test error", http.StatusBadRequest)
|
||||
}),
|
||||
expectedErrorContains: "test error\n",
|
||||
unwrap: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
@ -366,6 +375,10 @@ func TestReadClient(t *testing.T) {
|
|||
ss, err := c.Read(context.Background(), query, test.sortSeries)
|
||||
if test.expectedErrorContains != "" {
|
||||
require.ErrorContains(t, err, test.expectedErrorContains)
|
||||
if test.unwrap {
|
||||
err = errors.Unwrap(err)
|
||||
require.EqualError(t, err, test.expectedErrorContains)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue