Skip to content

Commit 6a439bd

Browse files
authored
remote read: Use more informative error msg for timeouts (prometheus#16157)
* Use more informative error msg for timeouts on remote read Signed-off-by: Jeanette Tan <[email protected]>
1 parent 37a41cc commit 6a439bd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

storage/remote/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ func (c *Client) Read(ctx context.Context, query *prompb.Query, sortSeries bool)
365365
httpReq.Header.Set("User-Agent", UserAgent)
366366
httpReq.Header.Set("X-Prometheus-Remote-Read-Version", "0.1.0")
367367

368-
ctx, cancel := context.WithTimeout(ctx, c.timeout)
368+
errTimeout := fmt.Errorf("%w: request timed out after %s", context.DeadlineExceeded, c.timeout)
369+
ctx, cancel := context.WithTimeoutCause(ctx, c.timeout, errTimeout)
369370

370371
ctx, span := otel.Tracer("").Start(ctx, "Remote Read", trace.WithSpanKind(trace.SpanKindClient))
371372
defer span.End()

storage/remote/client_test.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ func TestReadClient(t *testing.T) {
220220
name string
221221
query *prompb.Query
222222
httpHandler http.HandlerFunc
223+
timeout time.Duration
223224
expectedLabels []map[string]string
224225
expectedSamples [][]model.SamplePair
225226
expectedErrorContains string
@@ -329,6 +330,12 @@ func TestReadClient(t *testing.T) {
329330
}),
330331
expectedErrorContains: "unsupported content type",
331332
},
333+
{
334+
name: "timeout",
335+
httpHandler: sampledResponseHTTPHandler(t),
336+
timeout: time.Nanosecond,
337+
expectedErrorContains: "context deadline exceeded: request timed out after 1ns",
338+
},
332339
}
333340

334341
for _, test := range tests {
@@ -339,9 +346,13 @@ func TestReadClient(t *testing.T) {
339346
u, err := url.Parse(server.URL)
340347
require.NoError(t, err)
341348

349+
if test.timeout == 0 {
350+
test.timeout = 5 * time.Second
351+
}
352+
342353
conf := &ClientConfig{
343354
URL: &config_util.URL{URL: u},
344-
Timeout: model.Duration(5 * time.Second),
355+
Timeout: model.Duration(test.timeout),
345356
ChunkedReadLimit: config.DefaultChunkedReadLimit,
346357
}
347358
c, err := NewReadClient("test", conf)

0 commit comments

Comments
 (0)