From 0fc84f4cfb0a0602ef0bca5b88c795aa490da717 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Thu, 1 Nov 2018 08:40:28 -0400 Subject: [PATCH] address review comments --- client/vaultclient/vaultclient.go | 2 +- nomad/vault.go | 11 ++++------- nomad/vault_test.go | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/client/vaultclient/vaultclient.go b/client/vaultclient/vaultclient.go index 7494fb2c9..8d9dff28d 100644 --- a/client/vaultclient/vaultclient.go +++ b/client/vaultclient/vaultclient.go @@ -160,7 +160,7 @@ func NewVaultClient(config *config.VaultConfig, logger hclog.Logger, tokenDerive } client.SetHeaders(http.Header{ - "User-Agent": []string{"HashiCorp/nomad"}, + "User-Agent": []string{"hashicorp/nomad"}, }) c.client = client diff --git a/nomad/vault.go b/nomad/vault.go index 5f21081df..0033c7f32 100644 --- a/nomad/vault.go +++ b/nomad/vault.go @@ -515,11 +515,11 @@ func (v *vaultClient) renewalLoop() { // nextBackoff returns the delay for the next auto renew interval, in seconds. // Returns negative value if past expiration // -// It should increaes the amount of backoff each time, with the following rules: +// It should increase the amount of backoff each time, with the following rules: // // * If we have an existing authentication that is going to expire, // never back off more than half of the amount of time remaining -// until expiration (with 1s floor) +// until expiration (with 5s floor) // * Never back off more than 30 seconds multiplied by a random // value between 1 and 2 // * Use randomness so that many clients won't keep hitting Vault @@ -531,8 +531,6 @@ func nextBackoff(backoff float64, expiry time.Time) float64 { } switch { - case backoff < 5: - backoff = 5 case backoff >= 24: backoff = 30 default: @@ -546,9 +544,8 @@ func nextBackoff(backoff float64, expiry time.Time) float64 { backoff = maxBackoff.Seconds() } - // avoid hammering Vault - if backoff < 1 { - backoff = 1 + if backoff < 5 { + backoff = 5 } return backoff diff --git a/nomad/vault_test.go b/nomad/vault_test.go index 191eea9df..3de2e079f 100644 --- a/nomad/vault_test.go +++ b/nomad/vault_test.go @@ -1285,8 +1285,8 @@ func TestVaultClient_nextBackoff(t *testing.T) { // some edge cases t.Run("close to expiry", func(t *testing.T) { b := nextBackoff(20, time.Now().Add(1100*time.Millisecond)) - if !(1.0 <= b && b <= 3) { - t.Fatalf("Expected backoff within [1, 3] but found %v", b) + if b != 5.0 { + t.Fatalf("Expected backoff is 5 but found %v", b) } })