diff --git a/cmd/contour/serve.go b/cmd/contour/serve.go index fefeaeabf97..177c614c4ef 100644 --- a/cmd/contour/serve.go +++ b/cmd/contour/serve.go @@ -216,6 +216,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { registry := prometheus.NewRegistry() registry.MustRegister(prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{})) registry.MustRegister(prometheus.NewGoCollector()) + registry.MustRegister(cgrpc.ServerMetrics) // step 9. create metrics service and register with workgroup. metricsvc := metrics.Service{ diff --git a/go.mod b/go.mod index 155784fa8dd..531f737522f 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/google/uuid v1.0.0 github.com/googleapis/gnostic v0.2.0 // indirect github.com/gordonklaus/ineffassign v0.0.0-20190601041439-ed7b1b5ee0f8 + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/hashicorp/golang-lru v0.5.1 // indirect github.com/imdario/mergo v0.3.7 // indirect github.com/kisielk/errcheck v1.2.0 diff --git a/go.sum b/go.sum index 3d5acde9dd8..15b31ca0c33 100644 --- a/go.sum +++ b/go.sum @@ -86,6 +86,8 @@ github.com/gordonklaus/ineffassign v0.0.0-20190601041439-ed7b1b5ee0f8/go.mod h1: github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -245,8 +247,6 @@ golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3 golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= -golang.org/x/tools v0.0.0-20190918220241-b8f1ca6a929d h1:509WdJuGomQvj505oUgekhS5hb41+tboOY87t2t1Vko= -golang.org/x/tools v0.0.0-20190918220241-b8f1ca6a929d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190929041059-e7abfedfabcf h1:NvypsVlesF+lEDKVK5RNkww4fzArJXChZxNin79j05M= golang.org/x/tools v0.0.0-20190929041059-e7abfedfabcf/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/grpc/server.go b/internal/grpc/server.go index 21f7f0c5af8..36cfa39beb0 100644 --- a/internal/grpc/server.go +++ b/internal/grpc/server.go @@ -19,14 +19,20 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/grpc-ecosystem/go-grpc-prometheus" + v2 "github.com/envoyproxy/go-control-plane/envoy/api/v2" discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2" loadstats "github.com/envoyproxy/go-control-plane/envoy/service/load_stats/v2" "github.com/sirupsen/logrus" ) +var ServerMetrics = grpc_prometheus.NewServerMetrics() + // NewAPI returns a *grpc.Server which responds to the Envoy v2 xDS gRPC API. func NewAPI(log logrus.FieldLogger, resources map[string]Resource, opts ...grpc.ServerOption) *grpc.Server { + opts = append(opts, grpc.StreamInterceptor(ServerMetrics.StreamServerInterceptor()), + grpc.UnaryInterceptor(ServerMetrics.UnaryServerInterceptor())) g := grpc.NewServer(opts...) s := &grpcServer{ xdsHandler{ @@ -40,6 +46,7 @@ func NewAPI(log logrus.FieldLogger, resources map[string]Resource, opts ...grpc. v2.RegisterListenerDiscoveryServiceServer(g, s) v2.RegisterRouteDiscoveryServiceServer(g, s) discovery.RegisterSecretDiscoveryServiceServer(g, s) + ServerMetrics.InitializeMetrics(g) return g }