From 721ba40a8f71071a78f77b80f52d651a9a448e8f Mon Sep 17 00:00:00 2001 From: Pete Gautier Date: Fri, 22 Nov 2024 13:51:57 -0800 Subject: [PATCH] chore: add support for grpc kepalive --- src/Cache/Internal/DataGrpcManager.php | 12 +++++++ src/Config/Transport/IGrpcConfiguration.php | 7 +++++ .../Transport/StaticGrpcConfiguration.php | 31 +++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Cache/Internal/DataGrpcManager.php b/src/Cache/Internal/DataGrpcManager.php index f697bb89..9e70921b 100644 --- a/src/Cache/Internal/DataGrpcManager.php +++ b/src/Cache/Internal/DataGrpcManager.php @@ -32,6 +32,18 @@ public function __construct(ICredentialProvider $authProvider, IConfiguration $c if ($forceNewChannel) { $channelArgs["force_new"] = $forceNewChannel; } + if ($configuration->getTransportStrategy()->getGrpcConfig()->getKeepAlivePermitWithoutCalls()) { + $channelArgs["grpc.keepalive_permit_without_calls"] = + $configuration->getTransportStrategy()->getGrpcConfig()->getKeepAlivePermitWithoutCalls(); + } + if ($configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeoutMS()) { + $channelArgs["grpc.keepalive_timeout_ms"] = + $configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeoutMS(); + } + if ($configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeMS()) { + $channelArgs["grpc.keepalive_time_ms"] = + $configuration->getTransportStrategy()->getGrpcConfig()->getKeepAliveTimeMS(); + } $this->channel = new Channel($endpoint, $channelArgs); $interceptors = [ new AuthorizationInterceptor($authProvider->getAuthToken()), diff --git a/src/Config/Transport/IGrpcConfiguration.php b/src/Config/Transport/IGrpcConfiguration.php index ff4362c6..25885a22 100644 --- a/src/Config/Transport/IGrpcConfiguration.php +++ b/src/Config/Transport/IGrpcConfiguration.php @@ -16,4 +16,11 @@ public function withForceNewChannel(bool $forceNewChannel) : IGrpcConfiguration; public function getNumGrpcChannels(): int; public function withNumGrpcChannels(int $numGrpcChannels): IGrpcConfiguration; + + public function getKeepAlivePermitWithoutCalls(): ?int; + + public function getKeepAliveTimeoutMS(): ?int; + + public function getKeepAliveTimeMS(): ?int; + } diff --git a/src/Config/Transport/StaticGrpcConfiguration.php b/src/Config/Transport/StaticGrpcConfiguration.php index a51b775c..b587c459 100644 --- a/src/Config/Transport/StaticGrpcConfiguration.php +++ b/src/Config/Transport/StaticGrpcConfiguration.php @@ -9,12 +9,39 @@ class StaticGrpcConfiguration implements IGrpcConfiguration private ?int $deadlineMilliseconds; private bool $forceNewChannel; private int $numGrpcChannels; + private ?int $keepAlivePermitWithoutCalls; + private ?int $keepAliveTimeoutMS; + private ?int $keepAliveTimeMS; - public function __construct(?int $deadlineMilliseconds = null, bool $forceNewChannel = false, int $numGrpcChannels = 1) - { + public function __construct( + ?int $deadlineMilliseconds = null, + bool $forceNewChannel = false, + int $numGrpcChannels = 1, + ?int $keepAlivePermitWithoutCalls = 0, + ?int $keepAliveTimeoutMS = null, + ?int $keepAliveTimeMS = null + ) { $this->deadlineMilliseconds = $deadlineMilliseconds; $this->forceNewChannel = $forceNewChannel; $this->numGrpcChannels = $numGrpcChannels; + $this->keepAlivePermitWithoutCalls = $keepAlivePermitWithoutCalls; + $this->keepAliveTimeoutMS = $keepAliveTimeoutMS; + $this->keepAliveTimeMS = $keepAliveTimeMS; + } + + public function getKeepAlivePermitWithoutCalls(): ?int + { + return $this->keepAlivePermitWithoutCalls; + } + + public function getKeepAliveTimeoutMS(): ?int + { + return $this->keepAliveTimeoutMS; + } + + public function getKeepAliveTimeMS(): ?int + { + return $this->keepAliveTimeMS; } public function getDeadlineMilliseconds(): ?int