connect: add gRPC keep-alive (#4961)

This commit is contained in:
Denis Mishin 2024-02-13 18:26:14 -05:00 committed by GitHub
parent c6d1f17100
commit 2db2bd09a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 4 deletions

View file

@ -6,6 +6,9 @@ import (
"fmt"
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"github.com/pomerium/pomerium/internal/zero/apierror"
connect_mux "github.com/pomerium/pomerium/internal/zero/connect-mux"
"github.com/pomerium/pomerium/internal/zero/grpcconn"
@ -34,6 +37,13 @@ const (
minTelemetryTokenTTL = time.Minute * 5
)
// see https://github.com/pomerium/pomerium-zero/issues/1711
var connectClientKeepaliveParams = keepalive.ClientParameters{
Time: time.Minute, // send pings every minute
Timeout: time.Minute, // wait 1 minute for ping ack
PermitWithoutStream: false,
}
// WatchOption defines which events to watch for
type WatchOption = connect_mux.WatchOption
@ -60,7 +70,7 @@ func NewAPI(ctx context.Context, opts ...Option) (*API, error) {
connectGRPCConn, err := grpcconn.New(ctx, cfg.connectAPIEndpoint, func(ctx context.Context) (string, error) {
return tokenCache.GetToken(ctx, minConnectTokenTTL)
})
}, grpc.WithKeepaliveParams(connectClientKeepaliveParams))
if err != nil {
return nil, fmt.Errorf("error creating connect grpc client: %w", err)
}