diff --git a/go.mod b/go.mod index 1d1213b..6251049 100644 --- a/go.mod +++ b/go.mod @@ -11,13 +11,13 @@ require ( github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.18.0 github.com/sirupsen/logrus v1.9.0 - google.golang.org/grpc v1.64.0 ) require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect @@ -28,7 +28,6 @@ require ( golang.org/x/net v0.22.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index facfc55..ef3409f 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,7 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -108,10 +109,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/prometheus.go b/prometheus.go index 0e0fca8..4c97af2 100644 --- a/prometheus.go +++ b/prometheus.go @@ -1,11 +1,7 @@ package hotload import ( - "context" - "strings" - "github.com/prometheus/client_golang/prometheus" - "google.golang.org/grpc" ) const ( @@ -26,28 +22,3 @@ var sqlStmtsSummary = prometheus.NewSummaryVec(prometheus.SummaryOpts{ func init() { prometheus.MustRegister(sqlStmtsSummary) } - -// PromUnaryServerInterceptor returns a unary server interceptor that sets the -// prometheus labels for the grpc service and method. This is useful for -// population the prometheus metrics. -func PromUnaryServerInterceptor() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - service, method := splitMethod(info.FullMethod) - labels := map[string]string{ - GRPCMethodKey: method, - GRPCServiceKey: service, - } - ctx = ContextWithExecLabels(ctx, labels) - return handler(ctx, req) - } -} - -func splitMethod(fullMethod string) (service, method string) { - // fullMethod is in the form "/service/method" - // We need to split it into service and method - split := strings.Split(fullMethod, "/") - if len(split) != 3 { - return "unknown", "unknown" - } - return split[1], split[2] -} diff --git a/prometheus_test.go b/prometheus_test.go index 9fff8ef..64ec7c9 100644 --- a/prometheus_test.go +++ b/prometheus_test.go @@ -1,13 +1,11 @@ package hotload import ( - "context" "errors" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/prometheus/client_golang/prometheus" - "google.golang.org/grpc" ) var _ = Describe("PrometheusMetric", func() { @@ -18,22 +16,3 @@ var _ = Describe("PrometheusMetric", func() { Expect(errors.As(err, &prometheus.AlreadyRegisteredError{})).Should(BeTrue()) }) }) - -var _ = Describe("PromUnaryServerInterceptor", func() { - It("Should return a unary server interceptor", func() { - validationHandler := func(ctx context.Context, req interface{}) (interface{}, error) { - labels := GetExecLabelsFromContext(ctx) - - Expect(labels).ShouldNot(BeNil()) - Expect(labels[GRPCMethodKey]).Should(Equal("List")) - Expect(labels[GRPCServiceKey]).Should(Equal("infoblox.service.SampleService")) - - return nil, nil - } - - promUnaryServerInterceptor := PromUnaryServerInterceptor() - promUnaryServerInterceptor(context.Background(), struct{}{}, &grpc.UnaryServerInfo{ - FullMethod: "/infoblox.service.SampleService/List", - }, validationHandler) - }) -})