Skip to content

Commit

Permalink
chore(kuma-cp) set GRPC keepalives (#1580)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Nikolaev <nikolay.nikolaev@konghq.com>

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
Nikolay Nikolaev and mergify[bot] committed Feb 19, 2021
1 parent 4f87870 commit 10936f8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
16 changes: 15 additions & 1 deletion pkg/dp-server/server/server.go
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"net/http"
"strings"
"time"

"google.golang.org/grpc/keepalive"

http_prometheus "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
Expand All @@ -19,7 +22,10 @@ import (

var log = core.Log.WithName("dp-server")

const grpcMaxConcurrentStreams = 1000000
const (
grpcMaxConcurrentStreams = 1000000
grpcKeepAliveTime = 15 * time.Second
)

type DpServer struct {
config dp_server.DpServerConfig
Expand All @@ -33,6 +39,14 @@ var _ component.Component = &DpServer{}
func NewDpServer(config dp_server.DpServerConfig, metrics metrics.Metrics) *DpServer {
grpcOptions := []grpc.ServerOption{
grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams),
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: grpcKeepAliveTime,
Timeout: grpcKeepAliveTime,
}),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: grpcKeepAliveTime,
PermitWithoutStream: true,
}),
}
grpcOptions = append(grpcOptions, metrics.GRPCServerInterceptors()...)
grpcServer := grpc.NewServer(grpcOptions...)
Expand Down
16 changes: 15 additions & 1 deletion pkg/kds/mux/server.go
Expand Up @@ -3,6 +3,9 @@ package mux
import (
"fmt"
"net"
"time"

"google.golang.org/grpc/keepalive"

"github.com/pkg/errors"
"google.golang.org/grpc"
Expand All @@ -16,7 +19,10 @@ import (
core_metrics "github.com/kumahq/kuma/pkg/metrics"
)

const grpcMaxConcurrentStreams = 1000000
const (
grpcMaxConcurrentStreams = 1000000
grpcKeepAliveTime = 15 * time.Second
)

var (
muxServerLog = core.Log.WithName("mux-server")
Expand Down Expand Up @@ -52,6 +58,14 @@ func NewServer(callbacks []Callbacks, config multizone.KdsServerConfig, metrics
func (s *server) Start(stop <-chan struct{}) error {
grpcOptions := []grpc.ServerOption{
grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams),
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: grpcKeepAliveTime,
Timeout: grpcKeepAliveTime,
}),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: grpcKeepAliveTime,
PermitWithoutStream: true,
}),
}
grpcOptions = append(grpcOptions, s.metrics.GRPCServerInterceptors()...)
useTLS := s.config.TlsCertFile != ""
Expand Down
16 changes: 15 additions & 1 deletion pkg/mads/server/grpc.go
Expand Up @@ -3,6 +3,9 @@ package server
import (
"fmt"
"net"
"time"

"google.golang.org/grpc/keepalive"

observability_proto "github.com/kumahq/kuma/api/observability/v1alpha1"

Expand All @@ -14,7 +17,10 @@ import (
core_metrics "github.com/kumahq/kuma/pkg/metrics"
)

const grpcMaxConcurrentStreams = 1000000
const (
grpcMaxConcurrentStreams = 1000000
grpcKeepAliveTime = 15 * time.Second
)

var (
grpcServerLog = core.Log.WithName("mads-server").WithName("grpc")
Expand All @@ -33,6 +39,14 @@ var (
func (s *grpcServer) Start(stop <-chan struct{}) error {
grpcOptions := []grpc.ServerOption{
grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams),
grpc.KeepaliveParams(keepalive.ServerParameters{
Time: grpcKeepAliveTime,
Timeout: grpcKeepAliveTime,
}),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: grpcKeepAliveTime,
PermitWithoutStream: true,
}),
}
grpcOptions = append(grpcOptions, s.metrics.GRPCServerInterceptors()...)
grpcOptions = append(grpcOptions, grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams))
Expand Down

0 comments on commit 10936f8

Please sign in to comment.