api: change Connect to a query option

pull/4275/head
Mitchell Hashimoto 7 years ago committed by Jack Pearkes
parent 8d66d1045a
commit 77a8003475

@ -112,6 +112,10 @@ type QueryOptions struct {
// a value from 0 to 5 (inclusive).
RelayFactor uint8
// Connect filters prepared query execution to only include Connect-capable
// services. This currently affects prepared query execution.
Connect bool
// ctx is an optional context pass through to the underlying HTTP
// request layer. Use Context() and WithContext() to manage this.
ctx context.Context
@ -561,6 +565,9 @@ func (r *request) setQueryOptions(q *QueryOptions) {
if q.RelayFactor != 0 {
r.params.Set("relay-factor", strconv.Itoa(int(q.RelayFactor)))
}
if q.Connect {
r.params.Set("connect", "true")
}
r.ctx = q.ctx
}

@ -210,26 +210,3 @@ func (c *PreparedQuery) Execute(queryIDOrName string, q *QueryOptions) (*Prepare
}
return out, qm, nil
}
// ExecuteConnect is used to execute a specific prepared query and return
// only Connect-capable nodes.
func (c *PreparedQuery) ExecuteConnect(queryIDOrName string, q *QueryOptions) (*PreparedQueryExecuteResponse, *QueryMeta, error) {
r := c.c.newRequest("GET", "/v1/query/"+queryIDOrName+"/execute")
r.setQueryOptions(q)
r.params.Set("connect", "true")
rtt, resp, err := requireOK(c.c.doRequest(r))
if err != nil {
return nil, nil, err
}
defer resp.Body.Close()
qm := &QueryMeta{}
parseQueryMeta(resp, qm)
qm.RequestTime = rtt
var out PreparedQueryExecuteResponse
if err := decodeBody(resp, &out); err != nil {
return nil, nil, err
}
return &out, qm, nil
}

@ -144,7 +144,7 @@ func (cr *ConsulResolver) resolveService(ctx context.Context) (string, connect.C
}
func (cr *ConsulResolver) resolveQuery(ctx context.Context) (string, connect.CertURI, error) {
resp, _, err := cr.Client.PreparedQuery().ExecuteConnect(cr.Name, cr.queryOptions(ctx))
resp, _, err := cr.Client.PreparedQuery().Execute(cr.Name, cr.queryOptions(ctx))
if err != nil {
return "", nil, err
}
@ -193,6 +193,9 @@ func (cr *ConsulResolver) queryOptions(ctx context.Context) *api.QueryOptions {
// caching which is even more stale so...
AllowStale: true,
Datacenter: cr.Datacenter,
// For prepared queries
Connect: true,
}
return q.WithContext(ctx)
}

Loading…
Cancel
Save