Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configure default grpc server keepalive enforcement policy #589

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions common/client_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package common
import (
"context"
"crypto/tls"
"google.golang.org/grpc/keepalive"
"io"
"log/slog"
"strings"
Expand All @@ -39,6 +40,11 @@ import (

const DefaultRpcTimeout = 30 * time.Second
const AddressSchemaTLS = "tls://"
const (
defaultGrpcClientKeepAliveTime = time.Second * 10
defaultGrpcClientKeepAliveTimeout = time.Second * 5
defaultGrpcClientPermitWithoutStream = true
)

type ClientPool interface {
io.Closer
Expand Down Expand Up @@ -178,6 +184,11 @@ func (cp *clientPool) newConnection(target string) (*grpc.ClientConn, error) {
grpc.WithTransportCredentials(tcs),
grpc.WithStreamInterceptor(grpcprometheus.StreamClientInterceptor),
grpc.WithUnaryInterceptor(grpcprometheus.UnaryClientInterceptor),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
PermitWithoutStream: defaultGrpcClientPermitWithoutStream,
Time: defaultGrpcClientKeepAliveTime,
Timeout: defaultGrpcClientKeepAliveTimeout,
}),
}
if cp.authentication != nil {
options = append(options, grpc.WithPerRPCCredentials(cp.authentication))
Expand Down
13 changes: 10 additions & 3 deletions common/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package container
import (
"context"
"crypto/tls"
"google.golang.org/grpc/keepalive"
"io"
"log/slog"
"net"
"os"
"time"

"github.com/streamnative/oxia/server/auth"

Expand All @@ -34,9 +36,10 @@ import (
)

const (
maxGrpcFrameSize = 256 * 1024 * 1024

ReadinessProbeService = "oxia-readiness"
maxGrpcFrameSize = 256 * 1024 * 1024
defaultGrpcServerKeepAliveMinTime = 5 * time.Second
defaultGrpcServerKeepPermitWithoutStream = true
ReadinessProbeService = "oxia-readiness"
)

type GrpcServer interface {
Expand Down Expand Up @@ -102,6 +105,10 @@ func newDefaultGrpcProvider(name, bindAddress string, registerFunc func(grpc.Ser
grpc.ChainStreamInterceptor(streamInterceptors...),
grpc.ChainUnaryInterceptor(unaryInterceptors...),
grpc.MaxRecvMsgSize(maxGrpcFrameSize),
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: defaultGrpcServerKeepAliveMinTime,
PermitWithoutStream: defaultGrpcServerKeepPermitWithoutStream,
}),
),
}
registerFunc(c.server)
Expand Down
Loading