Skip to content

Commit b76d37e

Browse files
committed
agents: implement gRPC retry policies
Implement client-side retry policies for gRPC connections to improve resilience against transient network failures. The retry policy automatically retries failed requests on UNAVAILABLE status with exponential backoff. Retry policy configuration: - Max attempts: 5 retries - Initial backoff: 500ms - Max backoff: 5 seconds - Backoff multiplier: 2.0x - Retryable status: UNAVAILABLE The retry policy is configured via gRPC service config JSON and applies to all RPC methods. This ensures robust connectivity to the N|Solid Console even during temporary network issues or server restarts.
1 parent c4442b3 commit b76d37e

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

agents/grpc/src/grpc_agent.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ const int CONSOLE_ID_SIZE = 36;
8080

8181
const seconds DEFAULT_GRPC_TIMEOUT = seconds{ 60 };
8282

83+
// Retry policy configuration
84+
constexpr size_t retry_max_attempts = 5;
85+
constexpr auto retry_initial_backoff = std::chrono::milliseconds(500);
86+
constexpr auto retry_max_backoff = std::chrono::seconds(5);
87+
constexpr float retry_backoff_multiplier = 2.0f;
88+
8389
JSThreadMetrics::JSThreadMetrics(SharedEnvInst envinst):
8490
metrics_(ThreadMetrics::Create(envinst)) {
8591
}
@@ -1068,6 +1074,11 @@ int GrpcAgent::config(const json& config) {
10681074
}
10691075
}
10701076

1077+
opts.retry_policy_max_attempts = retry_max_attempts;
1078+
opts.retry_policy_initial_backoff = retry_initial_backoff;
1079+
opts.retry_policy_max_backoff = retry_max_backoff;
1080+
opts.retry_policy_backoff_multiplier = retry_backoff_multiplier;
1081+
10711082
nsolid_service_stub_ =
10721083
GrpcClient::MakeNSolidServiceStub(opts, tls_keylog_file_);
10731084

agents/grpc/src/grpc_client.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,40 @@ std::shared_ptr<Channel>
7373
grpc_arguments.SetInt(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1);
7474
grpc_arguments.SetInt(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0);
7575

76+
static const auto kServiceConfigJson = std::string_view{R"(
77+
{
78+
"methodConfig": [
79+
{
80+
"name": [{}],
81+
"retryPolicy": {
82+
"maxAttempts": %0000000000u,
83+
"initialBackoff": "%0000000000.1fs",
84+
"maxBackoff": "%0000000000.1fs",
85+
"backoffMultiplier": %0000000000.1f,
86+
"retryableStatusCodes": [
87+
"UNAVAILABLE"
88+
]
89+
}
90+
}
91+
]
92+
})"};
93+
94+
// Allocate string with buffer large enough to hold the formatted json config
95+
auto service_config = std::string(kServiceConfigJson.size(), '\0');
96+
float initial_backoff = options.retry_policy_initial_backoff.count();
97+
float max_backoff = options.retry_policy_max_backoff.count();
98+
float backoff_multiplier = options.retry_policy_backoff_multiplier;
99+
std::snprintf(
100+
service_config.data(),
101+
service_config.size(),
102+
kServiceConfigJson.data(),
103+
options.retry_policy_max_attempts,
104+
std::min(std::max(initial_backoff, 0.f), 999999999.f),
105+
std::min(std::max(max_backoff, 0.f), 999999999.f),
106+
std::min(std::max(backoff_multiplier, 0.f), 999999999.f));
107+
108+
grpc_arguments.SetServiceConfigJSON(service_config);
109+
76110
return CreateCustomChannel(options.endpoint,
77111
MakeCredentials(options, tls_keylog_file),
78112
grpc_arguments);

deps/opentelemetry-cpp/otlp-http-exporter.gyp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,21 @@
6464
'ENABLE_ASYNC_EXPORT',
6565
'ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW',
6666
'OPENTELEMETRY_STL_VERSION=2020',
67+
'ENABLE_OTLP_RETRY_PREVIEW',
6768
],
6869
'dependencies': [
6970
'../protobuf/protobuf.gyp:protobuf',
7071
'../curl/curl.gyp:curl',
7172
'../grpc/grpc.gyp:grpc++',
72-
'../protobuf/abseil.gyp:abseil_proto',
73+
'../protobuf/abseil.gyp:abseil_proto',
7374
'../zlib/zlib.gyp:zlib',
7475
],
7576
'direct_dependent_settings': {
7677
'defines': [
7778
'ENABLE_ASYNC_EXPORT',
7879
'ENABLE_OTLP_GRPC_CREDENTIAL_PREVIEW',
7980
'OPENTELEMETRY_STL_VERSION=2020',
81+
'ENABLE_OTLP_RETRY_PREVIEW',
8082
],
8183
'include_dirs': [
8284
'api/include',

0 commit comments

Comments
 (0)