Skip to content

Commit 07ee909

Browse files
authored
fix: add retry policy to grpc calls. (#261)
Some error codes are not on the stream, eg. istio is sending some special ones, and we already used to implement the same logic in java to bypass this issue. Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
1 parent d0ec36f commit 07ee909

File tree

2 files changed

+77
-0
lines changed
  • providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers

2 files changed

+77
-0
lines changed

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/grpc.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
import threading
34
import time
@@ -80,6 +81,44 @@ def _generate_channel(self, config: Config) -> grpc.Channel:
8081
("grpc.initial_reconnect_backoff_ms", config.retry_backoff_ms),
8182
("grpc.max_reconnect_backoff_ms", config.retry_backoff_max_ms),
8283
("grpc.min_reconnect_backoff_ms", config.deadline_ms),
84+
(
85+
"grpc.service_config",
86+
json.dumps(
87+
{
88+
"methodConfig": [
89+
{
90+
"name": [
91+
{"service": "flagd.sync.v1.FlagSyncService"},
92+
{"service": "flagd.evaluation.v1.Service"},
93+
],
94+
"retryPolicy": {
95+
"maxAttempts": 3,
96+
"initialBackoff": "1s",
97+
"maxBackoff": "5s",
98+
"backoffMultiplier": 2.0,
99+
"retryableStatusCodes": [
100+
"CANCELLED",
101+
"UNKNOWN",
102+
"INVALID_ARGUMENT",
103+
"NOT_FOUND",
104+
"ALREADY_EXISTS",
105+
"PERMISSION_DENIED",
106+
"RESOURCE_EXHAUSTED",
107+
"FAILED_PRECONDITION",
108+
"ABORTED",
109+
"OUT_OF_RANGE",
110+
"UNIMPLEMENTED",
111+
"INTERNAL",
112+
"UNAVAILABLE",
113+
"DATA_LOSS",
114+
"UNAUTHENTICATED",
115+
],
116+
},
117+
}
118+
]
119+
}
120+
),
121+
),
83122
]
84123
if config.tls:
85124
channel_args = {

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/process/connector/grpc_watcher.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,44 @@ def _generate_channel(self, config: Config) -> grpc.Channel:
6262
("grpc.initial_reconnect_backoff_ms", config.retry_backoff_ms),
6363
("grpc.max_reconnect_backoff_ms", config.retry_backoff_max_ms),
6464
("grpc.min_reconnect_backoff_ms", config.stream_deadline_ms),
65+
(
66+
"grpc.service_config",
67+
json.dumps(
68+
{
69+
"methodConfig": [
70+
{
71+
"name": [
72+
{"service": "flagd.sync.v1.FlagSyncService"},
73+
{"service": "flagd.evaluation.v1.Service"},
74+
],
75+
"retryPolicy": {
76+
"maxAttempts": 3,
77+
"initialBackoff": "1s",
78+
"maxBackoff": "5s",
79+
"backoffMultiplier": 2.0,
80+
"retryableStatusCodes": [
81+
"CANCELLED",
82+
"UNKNOWN",
83+
"INVALID_ARGUMENT",
84+
"NOT_FOUND",
85+
"ALREADY_EXISTS",
86+
"PERMISSION_DENIED",
87+
"RESOURCE_EXHAUSTED",
88+
"FAILED_PRECONDITION",
89+
"ABORTED",
90+
"OUT_OF_RANGE",
91+
"UNIMPLEMENTED",
92+
"INTERNAL",
93+
"UNAVAILABLE",
94+
"DATA_LOSS",
95+
"UNAUTHENTICATED",
96+
],
97+
},
98+
}
99+
]
100+
}
101+
),
102+
),
65103
]
66104
if config.default_authority is not None:
67105
options.append(("grpc.default_authority", config.default_authority))

0 commit comments

Comments
 (0)