Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Nov 1, 2018
1 parent 92a2e19 commit fa22827
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion client/vaultclient/vaultclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions nomad/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -531,8 +531,6 @@ func nextBackoff(backoff float64, expiry time.Time) float64 {
}

switch {
case backoff < 5:
backoff = 5
case backoff >= 24:
backoff = 30
default:
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions nomad/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})

Expand Down

0 comments on commit fa22827

Please sign in to comment.