From a82439c71378b0dcf05284f3293e5c5a85a7f194 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 11 Aug 2014 15:01:38 -0700 Subject: [PATCH] consul: Adding some metrics for ACL usage --- consul/acl.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/consul/acl.go b/consul/acl.go index 2909fea8f7..8921047dc6 100644 --- a/consul/acl.go +++ b/consul/acl.go @@ -5,6 +5,7 @@ import ( "strings" "time" + "github.com/armon/go-metrics" "github.com/hashicorp/consul/acl" "github.com/hashicorp/consul/consul/structs" ) @@ -28,6 +29,7 @@ type aclCacheEntry struct { // aclFault is used to fault in the rules for an ACL if we take a miss func (s *Server) aclFault(id string) (string, error) { + defer metrics.MeasureSince([]string{"consul", "acl", "fault"}, time.Now()) state := s.fsm.State() _, acl, err := state.ACLGet(id) if err != nil { @@ -46,6 +48,7 @@ func (s *Server) resolveToken(id string) (acl.ACL, error) { if len(authDC) == 0 { return nil, nil } + defer metrics.MeasureSince([]string{"consul", "acl", "resolveToken"}, time.Now()) // Handle the anonymous token if len(id) == 0 { @@ -74,7 +77,10 @@ func (s *Server) lookupACL(id, authDC string) (acl.ACL, error) { // Check for live cache if cached != nil && time.Now().Before(cached.Expires) { + metrics.IncrCounter([]string{"consul", "acl", "cache_hit"}, 1) return cached.ACL, nil + } else { + metrics.IncrCounter([]string{"consul", "acl", "cache_miss"}, 1) } // Attempt to refresh the policy