Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vault API Client Tweaks #4817

Merged
merged 14 commits into from
Nov 20, 2018
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