mirror of https://github.com/status-im/consul.git
Adds status information about failovers to query results.
This commit is contained in:
parent
86ead892ab
commit
30a18220af
|
@ -386,6 +386,9 @@ func (p *PreparedQuery) execute(query *structs.PreparedQuery,
|
||||||
reply.Nodes = nodes
|
reply.Nodes = nodes
|
||||||
reply.DNS = query.DNS
|
reply.DNS = query.DNS
|
||||||
|
|
||||||
|
// Stamp the result for this datacenter.
|
||||||
|
reply.Datacenter = p.srv.config.Datacenter
|
||||||
|
|
||||||
return nil
|
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
|
// the limit since it can be applied remotely to save bandwidth. We also
|
||||||
// pass along the consistency mode information we were given, so that
|
// pass along the consistency mode information we were given, so that
|
||||||
// applies to the remote query as well.
|
// applies to the remote query as well.
|
||||||
for _, dc := range dcs {
|
for i, dc := range dcs {
|
||||||
remote := &structs.PreparedQueryExecuteRemoteRequest{
|
remote := &structs.PreparedQueryExecuteRemoteRequest{
|
||||||
Datacenter: dc,
|
Datacenter: dc,
|
||||||
Query: *query,
|
Query: *query,
|
||||||
Limit: args.Limit,
|
Limit: args.Limit,
|
||||||
QueryOptions: args.QueryOptions,
|
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)
|
q.GetLogger().Printf("[WARN] consul.prepared_query: Failed querying for service '%s' in datacenter '%s': %s", query.Service.Service, dc, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep track of the number of failovers.
|
||||||
|
reply.Failovers = i + 1
|
||||||
|
|
||||||
// We can stop if we found some nodes.
|
// We can stop if we found some nodes.
|
||||||
if len(reply.Nodes) > 0 {
|
if len(reply.Nodes) > 0 {
|
||||||
break
|
break
|
||||||
|
|
|
@ -180,6 +180,16 @@ func (q *PreparedQueryExecuteRemoteRequest) RequestDatacenter() string {
|
||||||
|
|
||||||
// PreparedQueryExecuteResponse has the results of executing a query.
|
// PreparedQueryExecuteResponse has the results of executing a query.
|
||||||
type PreparedQueryExecuteResponse struct {
|
type PreparedQueryExecuteResponse struct {
|
||||||
|
// Nodes has the nodes that were output by the query.
|
||||||
Nodes CheckServiceNodes
|
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…
Reference in New Issue