Skip to content

Commit 86b1f30

Browse files
authored
Add keepalive params to Envoy alts transport socket (#40195)
Commit Message: Add keepalive params to Envoy alts transport socket Additional Description: Add environment variable-protected gRPC keepalive params for the ALTS handshake client. Risk Level: low Testing: N/A Docs Changes: N/A Release Notes: N/A Platform Specific Features: N/A --------- Signed-off-by: Luwei Ge <[email protected]>
1 parent 88641a1 commit 86b1f30

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

changelogs/current.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,5 +370,8 @@ new_features:
370370
flag to HTTP Dynamic Forward Proxy filter. When enabled, the filter will check for ``envoy.upstream.dynamic_host`` and
371371
``envoy.upstream.dynamic_port`` filter state values before using the HTTP Host header, providing consistency with SNI
372372
and UDP DFP filters. When disabled (default), maintains backward compatibility by using the HTTP Host header directly.
373+
- area: alts
374+
change: |
375+
Added environment variable-protected gRPC keepalive params to the ALTS handshaker client.
373376
374377
deprecated:

source/extensions/transport_sockets/alts/alts_channel_pool.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "source/extensions/transport_sockets/alts/alts_channel_pool.h"
22

33
#include <algorithm>
4+
#include <cstring>
45
#include <memory>
56
#include <string>
67
#include <utility>
@@ -20,13 +21,25 @@ namespace Alts {
2021

2122
// TODO(matthewstevenson88): Extend this to be configurable through API.
2223
constexpr std::size_t ChannelPoolSize = 10;
24+
constexpr char UseGrpcExperimentalAltsHandshakerKeepaliveParams[] =
25+
"GRPC_EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS";
26+
27+
// 10 seconds
28+
constexpr int ExperimentalKeepAliveTimeoutMs = 10 * 1000;
29+
// 10 minutes
30+
constexpr int ExperimentalKeepAliveTimeMs = 10 * 60 * 1000;
2331

2432
std::unique_ptr<AltsChannelPool>
2533
AltsChannelPool::create(absl::string_view handshaker_service_address) {
2634
std::vector<std::shared_ptr<grpc::Channel>> channel_pool;
2735
channel_pool.reserve(ChannelPoolSize);
2836
grpc::ChannelArguments channel_args;
2937
channel_args.SetInt(GRPC_ARG_USE_LOCAL_SUBCHANNEL_POOL, 1);
38+
const char* keep_alive = std::getenv(UseGrpcExperimentalAltsHandshakerKeepaliveParams);
39+
if (keep_alive != nullptr && std::strcmp(keep_alive, "true") == 0) {
40+
channel_args.SetInt(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, ExperimentalKeepAliveTimeoutMs);
41+
channel_args.SetInt(GRPC_ARG_KEEPALIVE_TIME_MS, ExperimentalKeepAliveTimeMs);
42+
}
3043
for (std::size_t i = 0; i < ChannelPoolSize; ++i) {
3144
channel_pool.push_back(grpc::CreateCustomChannel(
3245
std::string(handshaker_service_address), grpc::InsecureChannelCredentials(), channel_args));

test/extensions/transport_sockets/alts/alts_channel_pool_test.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include <stdlib.h>
2+
13
#include <memory>
24
#include <string>
35
#include <thread>
@@ -115,6 +117,32 @@ TEST_P(AltsChannelPoolTest, SuccessWithDefaultChannels) {
115117
}
116118
}
117119

120+
TEST_P(AltsChannelPoolTest, SuccessWithDefaultChannelsWithKeepAliveParams) {
121+
startFakeHandshakerService();
122+
123+
setenv("GRPC_EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS", "true", 1);
124+
// Create a channel pool and check that it has the correct dimensions.
125+
auto channel_pool = AltsChannelPool::create(serverAddress());
126+
EXPECT_THAT(channel_pool, NotNull());
127+
EXPECT_THAT(channel_pool->getChannel(), NotNull());
128+
EXPECT_EQ(channel_pool->getChannelPoolSize(), 10);
129+
130+
// Check that we can write to and read from the channel multiple times.
131+
for (int i = 0; i < 10; ++i) {
132+
auto channel = channel_pool->getChannel();
133+
EXPECT_THAT(channel, NotNull());
134+
grpc::ClientContext client_context;
135+
auto stub = HandshakerService::NewStub(channel);
136+
auto stream = stub->DoHandshake(&client_context);
137+
HandshakerReq request;
138+
EXPECT_TRUE(stream->Write(request));
139+
HandshakerResp response;
140+
EXPECT_TRUE(stream->Read(&response));
141+
}
142+
143+
unsetenv("GRPC_EXPERIMENTAL_ALTS_HANDSHAKER_KEEPALIVE_PARAMS");
144+
}
145+
118146
} // namespace
119147
} // namespace Alts
120148
} // namespace TransportSockets

0 commit comments

Comments
 (0)