Merge pull request #16437 from zenador/unwrap-read-client-error

remote: Allow unwrapping of errors when reading from remote client
pull/16441/head
George Krajcsovits 9 months ago committed by GitHub
commit f379e2eac7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      storage/remote/client.go
  2. 13
      storage/remote/client_test.go

@ -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…
Cancel
Save