Skip to content

Commit

Permalink
Populate agent-info with vault
Browse files Browse the repository at this point in the history
Return Vault TTL info to /agent/self API and `nomad agent-info` command.
  • Loading branch information
Mahmood Ali committed Nov 2, 2018
1 parent 161e03a commit 650d04f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions nomad/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,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
24 changes: 19 additions & 5 deletions nomad/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/rand"
"strconv"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -127,7 +128,7 @@ type VaultClient interface {
Running() bool

// Stats returns the Vault clients statistics
Stats() *VaultStats
Stats() map[string]string

// EmitStats emits that clients statistics at the given period until stopCh
// is called.
Expand All @@ -140,6 +141,9 @@ type VaultStats struct {
// TrackedForRevoke is the count of tokens that are being tracked to be
// revoked since they could not be immediately revoked.
TrackedForRevoke int

// TokenTTL is the time-to-live duration for the current token
TokenTTL time.Duration
}

// PurgeVaultAccessor is called to remove VaultAccessors from the system. If
Expand Down Expand Up @@ -1208,15 +1212,25 @@ func (v *vaultClient) setLimit(l rate.Limit) {
v.limiter = rate.NewLimiter(l, int(l))
}

// Stats is used to query the state of the blocked eval tracker.
func (v *vaultClient) Stats() *VaultStats {
func (v *vaultClient) Stats() map[string]string {
stat := v.stats()

return map[string]string{
"tracked_for_revoked": strconv.Itoa(stat.TrackedForRevoke),
"token_ttl": stat.TokenTTL.String(),
}
}

func (v *vaultClient) stats() *VaultStats {
// Allocate a new stats struct
stats := new(VaultStats)

v.revLock.Lock()
stats.TrackedForRevoke = len(v.revoking)
v.revLock.Unlock()

stats.TokenTTL = tokenTTL(v.tokenData)

return stats
}

Expand All @@ -1225,9 +1239,9 @@ func (v *vaultClient) EmitStats(period time.Duration, stopCh chan struct{}) {
for {
select {
case <-time.After(period):
stats := v.Stats()
stats := v.stats()
metrics.SetGauge([]string{"nomad", "vault", "distributed_tokens_revoking"}, float32(stats.TrackedForRevoke))
metrics.SetGauge([]string{"nomad", "vault", "token_ttl"}, float32(tokenTTL(v.tokenData)/time.Millisecond))
metrics.SetGauge([]string{"nomad", "vault", "token_ttl"}, float32(stats.TokenTTL/time.Millisecond))
case <-stopCh:
return
}
Expand Down

0 comments on commit 650d04f

Please sign in to comment.