Prometheus: Fix passing query timeout to upstream queries (#95104)

* remove queryTimeout from constructor

* use queryTimeout for range and instant queries

* remove comment

* remove default query timeout

* fix linting
This commit is contained in:
ismail simsek
2024-10-23 16:16:00 +02:00
committed by GitHub
parent 0872eb2791
commit 78a00d09cd
5 changed files with 28 additions and 18 deletions
+12 -5
View File
@@ -24,13 +24,14 @@ type doer interface {
// objects, we have to go through them and then serialize again into DataFrame which isn't very efficient. Using custom
// client we can parse response directly into DataFrame.
type Client struct {
doer doer
method string
baseUrl string
doer doer
method string
baseUrl string
queryTimeout string
}
func NewClient(d doer, method, baseUrl string) *Client {
return &Client{doer: d, method: method, baseUrl: baseUrl}
func NewClient(d doer, method, baseUrl, queryTimeout string) *Client {
return &Client{doer: d, method: method, baseUrl: baseUrl, queryTimeout: queryTimeout}
}
func (c *Client) QueryRange(ctx context.Context, q *models.Query) (*http.Response, error) {
@@ -41,6 +42,9 @@ func (c *Client) QueryRange(ctx context.Context, q *models.Query) (*http.Respons
"end": formatTime(tr.End),
"step": strconv.FormatFloat(tr.Step.Seconds(), 'f', -1, 64),
}
if c.queryTimeout != "" {
qv["timeout"] = c.queryTimeout
}
req, err := c.createQueryRequest(ctx, "api/v1/query_range", qv)
if err != nil {
@@ -58,6 +62,9 @@ func (c *Client) QueryInstant(ctx context.Context, q *models.Query) (*http.Respo
// Instead of aligning we use time point directly.
// https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries
qv := map[string]string{"query": q.Expr, "time": formatTime(q.End)}
if c.queryTimeout != "" {
qv["timeout"] = c.queryTimeout
}
req, err := c.createQueryRequest(ctx, "api/v1/query", qv)
if err != nil {
return nil, err