From 30a18220afcf3f2e72ec0892bd87e9d737cdf464 Mon Sep 17 00:00:00 2001 From: James Phillips Date: Tue, 10 Nov 2015 17:42:41 -0800 Subject: [PATCH] Adds status information about failovers to query results. --- consul/prepared_query_endpoint.go | 10 ++++++++-- consul/structs/prepared_query.go | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/consul/prepared_query_endpoint.go b/consul/prepared_query_endpoint.go index cbd7264ade..2a1599f2ef 100644 --- a/consul/prepared_query_endpoint.go +++ b/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 diff --git a/consul/structs/prepared_query.go b/consul/structs/prepared_query.go index 03efd078fc..dbd1c04ac2 100644 --- a/consul/structs/prepared_query.go +++ b/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 }