Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Custom Timeout for Queries #2474

Merged
merged 3 commits into from
Mar 12, 2017

Conversation

gouthamve
Copy link
Member

This is a WIP, tests are yet to be added. Just wanted to get feedback if this was the right approach.

Some tests I added were failing as a lot of time (>30secs) was being spent here: https://github.com/prometheus/prometheus/blob/master/storage/local/storage.go#L547 and context was ignored there. Any reason for ignoring context?

Closes #1399

@fabxc
Copy link
Contributor

fabxc commented Mar 6, 2017

Generally contexts are per request. The timeout the query engine wraps the provided context with is merely a upper bound applied to guard against too-high user-defined timeouts. Whether this should be set in the query engine or rather the client boundary (e.g. API or rule evaluation code) is a different question :)

For the introduction of custom timeouts though, this should not happen in the query engine itself but rather by the caller setting a timeout on the context passed to Query.Exec(ctx).
That would make things a bit simpler too, as we'd not have to change anything in the usage of templating and rule evaluation.

@gouthamve
Copy link
Member Author

// WithTimeout returns a copy of parent whose Done channel is closed as soon as
// parent.Done is closed, cancel is called, or timeout elapses. The new
// Context's Deadline is the sooner of now+timeout and the parent's deadline, if
// any. If the timer is still running, the cancel function releases its
// resources.

Did not know that before! Will make a lot of things easy!

@gouthamve
Copy link
Member Author

@fabxc Fixed it.

But, I find sometimes that I am stuck here: https://github.com/prometheus/prometheus/blob/master/storage/local/storage.go#L547 for more than 10mins when running a heavy server. Just trying to understand why we are not cancelling and cleaning up midway.

@fabxc
Copy link
Contributor

fabxc commented Mar 6, 2017

Yes, that code path should respect cancelation as well. Just nobody got around to making use of the cancelation signal throughout that bit of code yet.

@fabxc
Copy link
Contributor

fabxc commented Mar 6, 2017

Code looks good in general. @brian-brazil final concerns on HTTP API extension?

@@ -345,6 +369,7 @@ func (api *API) dropSeries(r *http.Request) (interface{}, *apiError) {
return res, nil
}

// Target has the information for 1 target.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 -> one

@@ -386,10 +412,12 @@ func (api *API) targets(r *http.Request) (interface{}, *apiError) {
return res, nil
}

// AlertmanagerDiscovery has all the active alert-managers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Alertmanagers" is how we write it.
Sentence should end with period.

type AlertmanagerDiscovery struct {
ActiveAlertmanagers []*AlertmanagerTarget `json:"activeAlertmanagers"`
}

// AlertmanagerTarget has info on 1 AM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 -> one, terminate with period.

@brian-brazil
Copy link
Contributor

Seems fine from an API standpoint.

I've been considering having scrapes pass down their timeout via a header, and remote read could do the same, but I think those APIs will necessarily be different.

@fabxc
Copy link
Contributor

fabxc commented Mar 12, 2017

Okay, this one seems good to go then. 👍

@fabxc fabxc merged commit de1e432 into prometheus:master Mar 12, 2017
@gouthamve gouthamve deleted the custom-timeouts-1399 branch March 12, 2017 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants