mirror of https://github.com/hashicorp/consul
Added telemetry around Catalog APIs
parent
b73ad8b68e
commit
006eab2394
|
@ -5,12 +5,14 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
metrics "github.com/armon/go-metrics"
|
||||||
"github.com/hashicorp/consul/agent/structs"
|
"github.com/hashicorp/consul/agent/structs"
|
||||||
)
|
)
|
||||||
|
|
||||||
var durations = NewDurationFixer("interval", "timeout", "deregistercriticalserviceafter")
|
var durations = NewDurationFixer("interval", "timeout", "deregistercriticalserviceafter")
|
||||||
|
|
||||||
func (s *HTTPServer) CatalogRegister(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) CatalogRegister(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "catalog_register"}, 1)
|
||||||
if req.Method != "PUT" {
|
if req.Method != "PUT" {
|
||||||
return nil, MethodNotAllowedError{req.Method, []string{"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
|
// Forward to the servers
|
||||||
var out struct{}
|
var out struct{}
|
||||||
if err := s.agent.RPC("Catalog.Register", &args, &out); err != nil {
|
if err := s.agent.RPC("Catalog.Register", &args, &out); err != nil {
|
||||||
|
metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_register"}, 1)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "success", "catalog_register"}, 1)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HTTPServer) CatalogDeregister(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) CatalogDeregister(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "catalog_deregister"}, 1)
|
||||||
if req.Method != "PUT" {
|
if req.Method != "PUT" {
|
||||||
return nil, MethodNotAllowedError{req.Method, []string{"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
|
// Forward to the servers
|
||||||
var out struct{}
|
var out struct{}
|
||||||
if err := s.agent.RPC("Catalog.Deregister", &args, &out); err != nil {
|
if err := s.agent.RPC("Catalog.Deregister", &args, &out); err != nil {
|
||||||
|
metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_deregister"}, 1)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "success", "catalog_deregister"}, 1)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HTTPServer) CatalogDatacenters(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) CatalogDatacenters(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "catalog_datacenters"}, 1)
|
||||||
if req.Method != "GET" {
|
if req.Method != "GET" {
|
||||||
return nil, MethodNotAllowedError{req.Method, []string{"GET"}}
|
return nil, MethodNotAllowedError{req.Method, []string{"GET"}}
|
||||||
}
|
}
|
||||||
|
|
||||||
var out []string
|
var out []string
|
||||||
if err := s.agent.RPC("Catalog.ListDatacenters", struct{}{}, &out); err != nil {
|
if err := s.agent.RPC("Catalog.ListDatacenters", struct{}{}, &out); err != nil {
|
||||||
|
metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_datacenters"}, 1)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "success", "catalog_datacenters"}, 1)
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HTTPServer) CatalogNodes(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) CatalogNodes(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "catalog_nodes"}, 1)
|
||||||
if req.Method != "GET" {
|
if req.Method != "GET" {
|
||||||
return nil, MethodNotAllowedError{req.Method, []string{"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)
|
s.parseSource(req, &args.Source)
|
||||||
args.NodeMetaFilters = s.parseMetaFilter(req)
|
args.NodeMetaFilters = s.parseMetaFilter(req)
|
||||||
if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
|
if done := s.parse(resp, req, &args.Datacenter, &args.QueryOptions); done {
|
||||||
|
metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_nodes"}, 1)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +110,12 @@ func (s *HTTPServer) CatalogNodes(resp http.ResponseWriter, req *http.Request) (
|
||||||
if out.Nodes == nil {
|
if out.Nodes == nil {
|
||||||
out.Nodes = make(structs.Nodes, 0)
|
out.Nodes = make(structs.Nodes, 0)
|
||||||
}
|
}
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "success", "catalog_nodes"}, 1)
|
||||||
return out.Nodes, nil
|
return out.Nodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HTTPServer) CatalogServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
func (s *HTTPServer) CatalogServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "catalog_services"}, 1)
|
||||||
if req.Method != "GET" {
|
if req.Method != "GET" {
|
||||||
return nil, MethodNotAllowedError{req.Method, []string{"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
|
var out structs.IndexedServices
|
||||||
defer setMeta(resp, &out.QueryMeta)
|
defer setMeta(resp, &out.QueryMeta)
|
||||||
if err := s.agent.RPC("Catalog.ListServices", &args, &out); err != nil {
|
if err := s.agent.RPC("Catalog.ListServices", &args, &out); err != nil {
|
||||||
|
metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_services"}, 1)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,10 +138,12 @@ func (s *HTTPServer) CatalogServices(resp http.ResponseWriter, req *http.Request
|
||||||
if out.Services == nil {
|
if out.Services == nil {
|
||||||
out.Services = make(structs.Services, 0)
|
out.Services = make(structs.Services, 0)
|
||||||
}
|
}
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "success", "catalog_services"}, 1)
|
||||||
return out.Services, nil
|
return out.Services, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HTTPServer) CatalogServiceNodes(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
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" {
|
if req.Method != "GET" {
|
||||||
return nil, MethodNotAllowedError{req.Method, []string{"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
|
var out structs.IndexedServiceNodes
|
||||||
defer setMeta(resp, &out.QueryMeta)
|
defer setMeta(resp, &out.QueryMeta)
|
||||||
if err := s.agent.RPC("Catalog.ServiceNodes", &args, &out); err != nil {
|
if err := s.agent.RPC("Catalog.ServiceNodes", &args, &out); err != nil {
|
||||||
|
metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_service_nodes"}, 1)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.agent.TranslateAddresses(args.Datacenter, out.ServiceNodes)
|
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)
|
s.ServiceTags = make([]string, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
metrics.IncrCounter([]string{"client", "api", "success", "catalog_service_nodes"}, 1)
|
||||||
return out.ServiceNodes, nil
|
return out.ServiceNodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *HTTPServer) CatalogNodeServices(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
|
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" {
|
if req.Method != "GET" {
|
||||||
return nil, MethodNotAllowedError{req.Method, []string{"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
|
var out structs.IndexedNodeServices
|
||||||
defer setMeta(resp, &out.QueryMeta)
|
defer setMeta(resp, &out.QueryMeta)
|
||||||
if err := s.agent.RPC("Catalog.NodeServices", &args, &out); err != nil {
|
if err := s.agent.RPC("Catalog.NodeServices", &args, &out); err != nil {
|
||||||
|
metrics.IncrCounter([]string{"client", "rpc", "error", "catalog_node_services"}, 1)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if out.NodeServices != nil && out.NodeServices.Node != nil {
|
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
|
return out.NodeServices, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue