From 6860037d68f51f482858b7269585e41ec4e6df8c Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Wed, 10 Jan 2018 11:28:44 -0800 Subject: [PATCH] Plumb config --- client/config/config.go | 8 ++++++++ client/rpc.go | 4 +--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/config/config.go b/client/config/config.go index 8a16eb8be..ff30f20c8 100644 --- a/client/config/config.go +++ b/client/config/config.go @@ -195,6 +195,13 @@ type Config struct { // BackwardsCompatibleMetrics determines whether to show methods of // displaying metrics for older verions, or to only show the new format BackwardsCompatibleMetrics bool + + // RPCHoldTimeout is how long an RPC can be "held" before it is errored. + // This is used to paper over a loss of leadership by instead holding RPCs, + // so that the caller experiences a slow response rather than an error. + // This period is meant to be long enough for a leader election to take + // place, and a small jitter is applied to avoid a thundering herd. + RPCHoldTimeout time.Duration } func (c *Config) Copy() *Config { @@ -228,6 +235,7 @@ func DefaultConfig() *Config { NoHostUUID: true, DisableTaggedMetrics: false, BackwardsCompatibleMetrics: false, + RPCHoldTimeout: 5 * time.Second, } } diff --git a/client/rpc.go b/client/rpc.go index df9dea968..31c1fc594 100644 --- a/client/rpc.go +++ b/client/rpc.go @@ -68,9 +68,7 @@ TRY: } // We can wait a bit and retry! - // TODO(alexdadgar): Plumb through the RPCHoldTimeout config - //if time.Since(firstCheck) < c.config.RPCHoldTimeout { - if time.Since(firstCheck) < 5*time.Second { + if time.Since(firstCheck) < c.config.RPCHoldTimeout { jitter := lib.RandomStagger(5 * time.Second / nomad.JitterFraction) select { case <-time.After(jitter):