api: support ExecuteConnect

pull/4275/head
Mitchell Hashimoto 7 years ago committed by Jack Pearkes
parent 62d4aaa33e
commit b55f0641e6

@ -54,6 +54,14 @@ type ServiceQuery struct {
// pair is in this map it must be present on the node in order for the
// service entry to be returned.
NodeMeta map[string]string
// Connect if true will filter the prepared query results to only
// include Connect-capable services. These include both native services
// and proxies for matching services. Note that if a proxy matches,
// the constraints in the query above (Near, OnlyPassing, etc.) apply
// to the _proxy_ and not the service being proxied. In practice, proxies
// should be directly next to their services so this isn't an issue.
Connect bool
}
// QueryTemplate carries the arguments for creating a templated query.
@ -202,3 +210,26 @@ 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
}

@ -233,6 +233,11 @@ The table below shows this endpoint's support for
key/value pairs that will be used for filtering the query results to nodes
with the given metadata values present.
- `Connect` `(bool: false)` - If true, only [Connect-capable](/docs/connect/index.html) services
for the specified service name will be returned. This includes both
natively integrated services and proxies. For proxies, the proxy name
may not match `Service`, because the proxy destination will.
- `DNS` `(DNS: nil)` - Specifies DNS configuration
- `TTL` `(string: "")` - Specifies the TTL duration when query results are
@ -497,6 +502,11 @@ Token will be used.
- `limit` `(int: 0)` - Limit the size of the list to the given number of nodes.
This is applied after any sorting or shuffling.
- `connect` `(bool: false)` - If true, limit results to nodes that are
Connect-capable only. This can also be specified directly on the template
itself to force all executions of a query to be Connect-only. See the
template documentation for more information.
### Sample Request
```text

Loading…
Cancel
Save