Skip to content

Commit

Permalink
chore: optimize grpc interceptor code (#536)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Ma <majinjing3@gmail.com>
  • Loading branch information
jim3ma authored Aug 12, 2021
1 parent 28999b2 commit 339bf39
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.7.3
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0
github.com/jarcoal/httpmock v1.0.8
github.com/klauspost/compress v1.13.1 // indirect
github.com/kr/text v0.2.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+
github.com/gorilla/sessions v1.2.0 h1:S7P+1Hm5V/AT9cjEcUD5uDaQSX0OE577aCXgoaKpYbQ=
github.com/gorilla/sessions v1.2.0/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 h1:Iju5GlWwrvL6UBg4zJJt3btmonfrMlCDdsejg4CZE7c=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
Expand Down
11 changes: 4 additions & 7 deletions pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"sync"
"time"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"github.com/pkg/errors"
"github.com/serialx/hashring"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
Expand Down Expand Up @@ -96,12 +95,10 @@ var defaultClientOpts = []grpc.DialOption{
Timeout: 10 * time.Second,
}),
// TODO make grpc interceptor optional
grpc.WithStreamInterceptor(grpc_middleware.ChainStreamClient(
otelgrpc.StreamClientInterceptor(),
streamClientInterceptor)),
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(
otelgrpc.UnaryClientInterceptor(),
unaryClientInterceptor)),
grpc.WithChainStreamInterceptor(otelgrpc.StreamClientInterceptor(),
streamClientInterceptor),
grpc.WithChainUnaryInterceptor(otelgrpc.UnaryClientInterceptor(),
unaryClientInterceptor),
}

type ConnOption interface {
Expand Down
11 changes: 4 additions & 7 deletions pkg/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"syscall"
"time"

grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
Expand Down Expand Up @@ -78,12 +77,10 @@ var serverOpts = []grpc.ServerOption{
}),
grpc.MaxConcurrentStreams(100),
// TODO make grpc interceptor optional
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
otelgrpc.StreamServerInterceptor(),
streamServerInterceptor)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
otelgrpc.UnaryServerInterceptor(),
unaryServerInterceptor)),
grpc.ChainStreamInterceptor(otelgrpc.StreamServerInterceptor(),
streamServerInterceptor),
grpc.ChainUnaryInterceptor(otelgrpc.UnaryServerInterceptor(),
unaryServerInterceptor),
}

var sp = struct {
Expand Down

0 comments on commit 339bf39

Please sign in to comment.