/
grpc.go
41 lines (34 loc) · 1.12 KB
/
grpc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package service
import (
"github.com/costinm/istio-discovery/pkg/features/pilot"
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpcprometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
"strconv"
)
func (s *AdsService) initGrpcServer() {
grpcOptions := s.grpcServerOptions()
s.grpcServer = grpc.NewServer(grpcOptions...)
}
func (s *AdsService) grpcServerOptions() []grpc.ServerOption {
interceptors := []grpc.UnaryServerInterceptor{
// setup server prometheus monitoring (as final interceptor in chain)
grpcprometheus.UnaryServerInterceptor,
}
grpcprometheus.EnableHandlingTimeHistogram()
// Temp setting, default should be enough for most supported environments. Can be used for testing
// envoy with lower values.
var maxStreams int
maxStreamsEnv := pilot.MaxConcurrentStreams
if len(maxStreamsEnv) > 0 {
maxStreams, _ = strconv.Atoi(maxStreamsEnv)
}
if maxStreams == 0 {
maxStreams = 100000
}
grpcOptions := []grpc.ServerOption{
grpc.UnaryInterceptor(middleware.ChainUnaryServer(interceptors...)),
grpc.MaxConcurrentStreams(uint32(maxStreams)),
}
return grpcOptions
}