Skip to content

Commit

Permalink
removed interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
yvardhineni committed Jun 19, 2024
1 parent 5fd9914 commit 700112e
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 56 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
29 changes: 0 additions & 29 deletions prometheus.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package hotload

import (
"context"
"strings"

"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc"
)

const (
Expand All @@ -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]
}
21 changes: 0 additions & 21 deletions prometheus_test.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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)
})
})

0 comments on commit 700112e

Please sign in to comment.