From 0698dcf103e4650a37878dab8029b212c0129cea Mon Sep 17 00:00:00 2001 From: Maksim Paskal Date: Wed, 23 Jun 2021 15:13:19 +0300 Subject: [PATCH] add keepalive settings to grpc server (#23) --- Makefile | 2 ++ cmd/main/main.go | 16 +++++++++++++++- docker-compose.yml | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index aee39fd..5f8261f 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ testChart: helm template ./chart/envoy-control-plane | kubectl apply --dry-run=client --validate -f - build: docker build . -t paskalmaksim/envoy-control-plane:dev +build-envoy: + docker-compose build envoy-test1 buildEnvoy: docker build ./envoy -t paskalmaksim/envoy-docker-image:dev build-cli: diff --git a/cmd/main/main.go b/cmd/main/main.go index 077fbcc..a371b34 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -24,6 +24,7 @@ import ( logrushooksentry "github.com/maksim-paskal/logrus-hook-sentry" log "github.com/sirupsen/logrus" "google.golang.org/grpc" + "google.golang.org/grpc/keepalive" "gopkg.in/yaml.v3" v1 "k8s.io/api/core/v1" ) @@ -31,6 +32,9 @@ import ( var gitVersion = "dev" const ( + grpcKeepaliveTime = 30 * time.Second + grpcKeepaliveTimeout = 5 * time.Second + grpcKeepaliveMinTime = 30 * time.Second grpcMaxConcurrentStreams = 1000000 ) @@ -176,7 +180,17 @@ func main() { ctx := context.Background() grpcOptions := []grpc.ServerOption{} - grpcOptions = append(grpcOptions, grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams)) + grpcOptions = append(grpcOptions, + grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams), + grpc.KeepaliveParams(keepalive.ServerParameters{ + Time: grpcKeepaliveTime, + Timeout: grpcKeepaliveTimeout, + }), + grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{ + MinTime: grpcKeepaliveMinTime, + PermitWithoutStream: true, + }), + ) grpcServer := grpc.NewServer(grpcOptions...) defer grpcServer.GracefulStop() diff --git a/docker-compose.yml b/docker-compose.yml index 2a96b2e..84a4b90 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: volumes: - .:/app environment: + #- GODEBUG=http2debug=2 - MY_POD_NAMESPACE=default ports: - 18081:18081