Skip to content

Commit ddb03c7

Browse files
committed
[FAB-11646] Add interceptors to comm.GRPCServer
Adds the ability to set unary and stream interceptors when configuring comm.GRPCServer instances. Adds the grpc-middleware library in order to allow chaining of interceptors. NOTE: had to remove unused package folders manually and add grpc-middleware to the noverify list due to hashes not matching for symlinks across OS versions. Change-Id: I0c9baa570ea84aa4be8377dedd0ada30c7e7a291 Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent bbbd098 commit ddb03c7

File tree

12 files changed

+1031
-240
lines changed

12 files changed

+1031
-240
lines changed

Gopkg.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ required = [
1212
ignored = [
1313
]
1414

15+
noverify = [
16+
"github.com/grpc-ecosystem/go-grpc-middleware"
17+
]
18+
1519
[[constraint]]
1620
name = "github.com/Knetic/govaluate"
1721
version = "3.0.0"
@@ -158,7 +162,10 @@ ignored = [
158162
name = "github.com/coreos/etcd"
159163
non-go = false
160164

161-
162165
[[constraint]]
163166
name = "go.uber.org/zap"
164167
version = "1.9.0"
168+
169+
[[constraint]]
170+
name = "github.com/grpc-ecosystem/go-grpc-middleware"
171+
version = "1.0.0"

core/comm/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ type ServerConfig struct {
5050
SecOpts *SecureOptions
5151
// KaOpts defines the keepalive parameters
5252
KaOpts *KeepaliveOptions
53+
// StreamInterceptors specifies a list of interceptors to apply to
54+
// streaming RPCs. They are executed in order.
55+
StreamInterceptors []grpc.StreamServerInterceptor
56+
// UnaryInterceptors specifies a list of interceptors to apply to unary
57+
// RPCs. They are executed in order.
58+
UnaryInterceptors []grpc.UnaryServerInterceptor
5359
}
5460

5561
// ClientConfig defines the parameters for configuring a GRPCClient instance

core/comm/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"sync"
1616
"sync/atomic"
1717

18+
"github.com/grpc-ecosystem/go-grpc-middleware"
1819
"google.golang.org/grpc"
1920
)
2021

@@ -130,6 +131,21 @@ func NewGRPCServerFromListener(listener net.Listener, serverConfig ServerConfig)
130131
serverOpts = append(
131132
serverOpts,
132133
grpc.ConnectionTimeout(serverConfig.ConnectionTimeout))
134+
// set the interceptors
135+
if len(serverConfig.StreamInterceptors) > 0 {
136+
serverOpts = append(
137+
serverOpts,
138+
grpc.StreamInterceptor(
139+
grpc_middleware.ChainStreamServer(
140+
serverConfig.StreamInterceptors...)))
141+
}
142+
if len(serverConfig.UnaryInterceptors) > 0 {
143+
serverOpts = append(
144+
serverOpts,
145+
grpc.UnaryInterceptor(
146+
grpc_middleware.ChainUnaryServer(
147+
serverConfig.UnaryInterceptors...)))
148+
}
133149

134150
grpcServer.server = grpc.NewServer(serverOpts...)
135151

0 commit comments

Comments
 (0)