Supprt for cancelling in-flight influx requests

If a request upstream is cancelled, we can propagate the cancellation
down to our queries to Influx using context's cancellation
functionality. This patch adds support for this.
pull/10616/head
Tim Raymond 2016-09-15 13:42:56 -04:00
parent 3116731abe
commit f6ac18b692
2 changed files with 17 additions and 3 deletions

View File

@ -29,9 +29,22 @@ func NewClient(host string) (*Client, error) {
// Query issues a request to a configured InfluxDB instance for time series
// information specified by query. Queries must be "fully-qualified," and
// include both the database and retention policy.
// include both the database and retention policy. In-flight requests can be
// cancelled using the provided context.
func (c *Client) Query(ctx context.Context, query mrfusion.Query) (mrfusion.Response, error) {
q := ixClient.NewQuery(string(query), "", "")
resp, err := c.ix.Query(q)
return response{resp}, err
resps := make(chan (response))
go func() {
resp, err := c.ix.Query(q)
resps <- response{resp, err}
}()
select {
case resp := <-resps:
return resp, resp.err
case <-ctx.Done():
return nil, nil
}
return nil, nil
}

View File

@ -9,6 +9,7 @@ import (
type response struct {
*client.Response
err error
}
func (r response) MarshalJSON() ([]byte, error) {