dns: refactor label by unrolling loop

This commit is contained in:
Frank Schroeder 2017-08-21 11:01:36 +02:00 committed by Frank Schröder
parent c35206db07
commit db8ad8922e
1 changed files with 14 additions and 9 deletions

View File

@ -692,22 +692,27 @@ func (d *DNSServer) serviceLookup(network, datacenter, service, tag string, req,
AllowStale: *d.config.AllowStale, AllowStale: *d.config.AllowStale,
}, },
} }
var out structs.IndexedCheckServiceNodes var out structs.IndexedCheckServiceNodes
RPC:
if err := d.agent.RPC("Health.ServiceNodes", &args, &out); err != nil { if err := d.agent.RPC("Health.ServiceNodes", &args, &out); err != nil {
d.logger.Printf("[ERR] dns: rpc error: %v", err) d.logger.Printf("[ERR] dns: rpc error: %v", err)
resp.SetRcode(req, dns.RcodeServerFailure) resp.SetRcode(req, dns.RcodeServerFailure)
return return
} }
// Verify that request is not too stale, redo the request if args.AllowStale && out.LastContact > staleCounterThreshold {
if args.AllowStale { metrics.IncrCounter([]string{"consul", "dns", "stale_queries"}, 1)
if out.LastContact > d.config.MaxStale { }
args.AllowStale = false
d.logger.Printf("[WARN] dns: Query results too stale, re-requesting") // redo the request the response was too stale
goto RPC if args.AllowStale && out.LastContact > d.config.MaxStale {
} else if out.LastContact > staleCounterThreshold { args.AllowStale = false
metrics.IncrCounter([]string{"consul", "dns", "stale_queries"}, 1) d.logger.Printf("[WARN] dns: Query results too stale, re-requesting")
if err := d.agent.RPC("Health.ServiceNodes", &args, &out); err != nil {
d.logger.Printf("[ERR] dns: rpc error: %v", err)
resp.SetRcode(req, dns.RcodeServerFailure)
return
} }
} }