diff --git a/agent/catalog_endpoint.go b/agent/catalog_endpoint.go index 1eb30fc3a6..7fec171513 100644 --- a/agent/catalog_endpoint.go +++ b/agent/catalog_endpoint.go @@ -5,12 +5,14 @@ import ( "net/http" "strings" + metrics "github.com/armon/go-metrics" "github.com/hashicorp/consul/agent/structs" ) var durations = NewDurationFixer("interval", "timeout", "deregistercriticalserviceafter") func (s *HTTPServer) CatalogRegister(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + metrics.IncrCounter([]string{"client", "api", "catalog_register"}, 1) if req.Method != "PUT" { return nil, MethodNotAllowedError{req.Method, []string{"PUT"}} } @@ -31,12 +33,15 @@ func (s *HTTPServer) CatalogRegister(resp http.ResponseWriter, req *http.Request // Forward to the servers var out struct{} if err := s.agent.RPC("Catalog.Register", &args, &out); err != nil { + metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_register"}, 1) return nil, err } + metrics.IncrCounter([]string{"client", "api", "success", "catalog_register"}, 1) return true, nil } func (s *HTTPServer) CatalogDeregister(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + metrics.IncrCounter([]string{"client", "api", "catalog_deregister"}, 1) if req.Method != "PUT" { return nil, MethodNotAllowedError{req.Method, []string{"PUT"}} } @@ -57,24 +62,30 @@ func (s *HTTPServer) CatalogDeregister(resp http.ResponseWriter, req *http.Reque // Forward to the servers var out struct{} if err := s.agent.RPC("Catalog.Deregister", &args, &out); err != nil { + metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_deregister"}, 1) return nil, err } + metrics.IncrCounter([]string{"client", "api", "success", "catalog_deregister"}, 1) return true, nil } func (s *HTTPServer) CatalogDatacenters(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + metrics.IncrCounter([]string{"client", "api", "catalog_datacenters"}, 1) if req.Method != "GET" { return nil, MethodNotAllowedError{req.Method, []string{"GET"}} } var out []string if err := s.agent.RPC("Catalog.ListDatacenters", struct{}{}, &out); err != nil { + metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_datacenters"}, 1) return nil, err } + metrics.IncrCounter([]string{"client", "api", "success", "catalog_datacenters"}, 1) return out, nil } func (s *HTTPServer) CatalogNodes(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + metrics.IncrCounter([]string{"client", "api", "catalog_nodes"}, 1) if req.Method != "GET" { return nil, MethodNotAllowedError{req.Method, []string{"GET"}} } @@ -84,6 +95,7 @@ func (s *HTTPServer) CatalogNodes(resp http.ResponseWriter, req *http.Request) ( s.parseSource(req, &args.Source) args.NodeMetaFilters = s.parseMetaFilter(req) if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done { + metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_nodes"}, 1) return nil, nil } @@ -98,10 +110,12 @@ func (s *HTTPServer) CatalogNodes(resp http.ResponseWriter, req *http.Request) ( if out.Nodes == nil { out.Nodes = make(structs.Nodes, 0) } + metrics.IncrCounter([]string{"client", "api", "success", "catalog_nodes"}, 1) return out.Nodes, nil } func (s *HTTPServer) CatalogServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + metrics.IncrCounter([]string{"client", "api", "catalog_services"}, 1) if req.Method != "GET" { return nil, MethodNotAllowedError{req.Method, []string{"GET"}} } @@ -116,6 +130,7 @@ func (s *HTTPServer) CatalogServices(resp http.ResponseWriter, req *http.Request var out structs.IndexedServices defer setMeta(resp, &out.QueryMeta) if err := s.agent.RPC("Catalog.ListServices", &args, &out); err != nil { + metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_services"}, 1) return nil, err } @@ -123,10 +138,12 @@ func (s *HTTPServer) CatalogServices(resp http.ResponseWriter, req *http.Request if out.Services == nil { out.Services = make(structs.Services, 0) } + metrics.IncrCounter([]string{"client", "api", "success", "catalog_services"}, 1) return out.Services, nil } func (s *HTTPServer) CatalogServiceNodes(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + metrics.IncrCounter([]string{"client", "api", "catalog_service_nodes"}, 1) if req.Method != "GET" { return nil, MethodNotAllowedError{req.Method, []string{"GET"}} } @@ -158,6 +175,7 @@ func (s *HTTPServer) CatalogServiceNodes(resp http.ResponseWriter, req *http.Req var out structs.IndexedServiceNodes defer setMeta(resp, &out.QueryMeta) if err := s.agent.RPC("Catalog.ServiceNodes", &args, &out); err != nil { + metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_service_nodes"}, 1) return nil, err } s.agent.TranslateAddresses(args.Datacenter, out.ServiceNodes) @@ -171,10 +189,12 @@ func (s *HTTPServer) CatalogServiceNodes(resp http.ResponseWriter, req *http.Req s.ServiceTags = make([]string, 0) } } + metrics.IncrCounter([]string{"client", "api", "success", "catalog_service_nodes"}, 1) return out.ServiceNodes, nil } func (s *HTTPServer) CatalogNodeServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) { + metrics.IncrCounter([]string{"client", "api", "catalog_node_services"}, 1) if req.Method != "GET" { return nil, MethodNotAllowedError{req.Method, []string{"GET"}} } @@ -197,6 +217,7 @@ func (s *HTTPServer) CatalogNodeServices(resp http.ResponseWriter, req *http.Req var out structs.IndexedNodeServices defer setMeta(resp, &out.QueryMeta) if err := s.agent.RPC("Catalog.NodeServices", &args, &out); err != nil { + metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_node_services"}, 1) return nil, err } if out.NodeServices != nil && out.NodeServices.Node != nil { @@ -211,5 +232,6 @@ func (s *HTTPServer) CatalogNodeServices(resp http.ResponseWriter, req *http.Req } } } + metrics.IncrCounter([]string{"client", "api", "success", "catalog_node_services"}, 1) return out.NodeServices, nil }