Browse Source

Adds status information about failovers to query results.

pull/1389/head
James Phillips 9 years ago
parent
commit
30a18220af
  1. 10
      consul/prepared_query_endpoint.go
  2. 12
      consul/structs/prepared_query.go

10
consul/prepared_query_endpoint.go

@ -386,6 +386,9 @@ func (p *PreparedQuery) execute(query *structs.PreparedQuery,
reply.Nodes = nodes
reply.DNS = query.DNS
// Stamp the result for this datacenter.
reply.Datacenter = p.srv.config.Datacenter
return nil
}
@ -533,18 +536,21 @@ func queryFailover(q queryServer, query *structs.PreparedQuery,
// the limit since it can be applied remotely to save bandwidth. We also
// pass along the consistency mode information we were given, so that
// applies to the remote query as well.
for _, dc := range dcs {
for i, dc := range dcs {
remote := &structs.PreparedQueryExecuteRemoteRequest{
Datacenter: dc,
Query: *query,
Limit: args.Limit,
QueryOptions: args.QueryOptions,
}
if err := q.ForwardDC("PreparedQuery.ExecuteRemote", dc, remote, reply); err != nil {
if err := q.ForwardDC("PreparedQuery.ExecuteRemote", dc, &remote, &reply); err != nil {
q.GetLogger().Printf("[WARN] consul.prepared_query: Failed querying for service '%s' in datacenter '%s': %s", query.Service.Service, dc, err)
continue
}
// Keep track of the number of failovers.
reply.Failovers = i + 1
// We can stop if we found some nodes.
if len(reply.Nodes) > 0 {
break

12
consul/structs/prepared_query.go

@ -180,6 +180,16 @@ func (q *PreparedQueryExecuteRemoteRequest) RequestDatacenter() string {
// PreparedQueryExecuteResponse has the results of executing a query.
type PreparedQueryExecuteResponse struct {
// Nodes has the nodes that were output by the query.
Nodes CheckServiceNodes
DNS QueryDNSOptions
// DNS has the options for serving these results over DNS.
DNS QueryDNSOptions
// Datacenter is the datacenter that these results came from.
Datacenter string
// Failovers is a count of how many times we had to query a remote
// datacenter.
Failovers int
}

Loading…
Cancel
Save