Skip to content

Commit

Permalink
Merge pull request #4817 from hashicorp/b-vault-client-tweaks
Browse files Browse the repository at this point in the history
Vault API Client Tweaks
  • Loading branch information
notnoop committed Nov 20, 2018
2 parents 084693f + 3a57b9c commit d7f02ed
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 69 deletions.
9 changes: 9 additions & 0 deletions client/vaultclient/vaultclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"container/heap"
"fmt"
"math/rand"
"net/http"
"strings"
"sync"
"time"

"github.com/armon/go-metrics"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/hashicorp/nomad/nomad/structs/config"
Expand Down Expand Up @@ -157,6 +159,10 @@ func NewVaultClient(config *config.VaultConfig, logger hclog.Logger, tokenDerive
return nil, err
}

client.SetHeaders(http.Header{
"User-Agent": []string{"hashicorp/nomad"},
})

c.client = client

return c, nil
Expand Down Expand Up @@ -298,6 +304,7 @@ func (c *vaultClient) RenewToken(token string, increment int) (<-chan error, err
// error channel.
if err := c.renew(renewalReq); err != nil {
c.logger.Error("error during renewal of token", "error", err)
metrics.IncrCounter([]string{"client", "vault", "renew_token_failure"}, 1)
return nil, err
}

Expand Down Expand Up @@ -335,6 +342,7 @@ func (c *vaultClient) RenewLease(leaseId string, increment int) (<-chan error, e
// Renew the secret and send any error to the dedicated error channel
if err := c.renew(renewalReq); err != nil {
c.logger.Error("error during renewal of lease", "error", err)
metrics.IncrCounter([]string{"client", "vault", "renew_lease_error"}, 1)
return nil, err
}

Expand Down Expand Up @@ -531,6 +539,7 @@ func (c *vaultClient) run() {
case <-renewalCh:
if err := c.renew(renewalReq); err != nil {
c.logger.Error("error renewing token", "error", err)
metrics.IncrCounter([]string{"client", "vault", "renew_token_error"}, 1)
}
case <-c.updateCh:
continue
Expand Down
1 change: 1 addition & 0 deletions nomad/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ func (s *Server) Stats() map[string]map[string]string {
"raft": s.raft.Stats(),
"serf": s.serf.Stats(),
"runtime": stats.RuntimeStats(),
"vault": s.vault.Stats(),
}

return stats
Expand Down
Loading

0 comments on commit d7f02ed

Please sign in to comment.