Skip to content

Allow passing timeout parameter in Prometheus queries #999

@prymitive

Description

@prymitive

Prometheus HTTP API allows to pass timeout parameter for queries: https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries but API doesn't allow to pass it.
One easy way would be to add a new parameter to Query and QueryRange but that would be incompatible.
Another way could to to check if passed context has a deadline and set a timeout smaller than that deadline, like:

func (h *httpAPI) Query(ctx context.Context, query string, ts time.Time) (model.Value, Warnings, error) {
	u := h.client.URL(epQuery, nil)
	q := u.Query()

	q.Set("query", query)
	if !ts.IsZero() {
		q.Set("time", formatTime(ts))
	}
	if deadline, ok := ctx.Deadline(); ok {
		q.Set("timeout", fmt.Sprintf("%ds", int(time.Until(deadline).Truncate(time.Millisecond*500).Seconds())))
	}
[...]

but smaller by what duration? So one way or another extra information is needed I think.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions