2626/** gRPC channel builder helper. */
2727public class ChannelBuilder {
2828
29+ @ SuppressWarnings ({"unchecked" , "rawtypes" })
30+ private static final Map <String , ?> DEFAULT_RETRY_POLICY = new HashMap () {
31+ {
32+ // 1 + 2 + 4
33+ put ("maxAttempts" , 3.0 ); // types used here are important, need to be doubles
34+ put ("initialBackoff" , "1s" );
35+ put ("maxBackoff" , "5s" );
36+ put ("backoffMultiplier" , 2.0 );
37+ // status codes to retry on:
38+ put ("retryableStatusCodes" ,
39+ Arrays .asList (
40+ /*
41+ * Only states UNAVAILABLE and UNKNOWN should be retried. All
42+ * other failure states will probably not be resolved with a simple retry.
43+ */
44+ Code .UNAVAILABLE .toString (),
45+ Code .UNKNOWN .toString ()
46+ )
47+ );
48+ }
49+ };
50+
2951 /**
3052 * Controls retry (not-reconnection) policy for failed RPCs.
3153 */
3254 @ SuppressWarnings ({"unchecked" , "rawtypes" })
3355 static final Map <String , ?> SERVICE_CONFIG_WITH_RETRY = new HashMap () {
3456 {
35- put ("methodConfig" , Arrays .asList (new HashMap () {
36- {
37- put (
38- "name" ,
39- Arrays .asList (
57+ put ("methodConfig" , Arrays .asList (
58+ new HashMap () {
59+ {
60+ put ("name" , Arrays .asList (
4061 new HashMap () {
4162 {
4263 put ("service" , "flagd.sync.v1.FlagSyncService" );
@@ -46,29 +67,54 @@ public class ChannelBuilder {
4667 {
4768 put ("service" , "flagd.evaluation.v1.Service" );
4869 }
49- }));
50- put ("retryPolicy" , new HashMap () {
70+ }
71+ ));
72+ put ("retryPolicy" , DEFAULT_RETRY_POLICY );
73+ }
5174 {
52- // 1 + 2 + 4
53- put ("maxAttempts" , 3.0 ); // types used here are important, need to be doubles
54- put ("initialBackoff" , "1s" );
55- put ("maxBackoff" , "5s" );
56- put ("backoffMultiplier" , 2.0 );
57- // status codes to retry on:
58- put (
59- "retryableStatusCodes" ,
60- Arrays .asList (
61- /*
62- * Only states UNAVAILABLE and UNKNOWN should be retried. All
63- * other failure states will probably not be resolved with a simple retry.
64- */
65- Code .UNAVAILABLE .toString (),
66- Code .UNKNOWN .toString ())
67- );
75+ put ("name" , Arrays .asList (
76+ new HashMap () {
77+ {
78+ put ("service" , "flagd.sync.v1.FlagSyncService" );
79+ put ("method" , "SyncFlags" );
80+ }
81+ }
82+ ));
83+ put ("retryPolicy" , new HashMap (DEFAULT_RETRY_POLICY ) {
84+ {
85+ // 1 + 2 + 4 + 5 + 5 + 5 + 5 + 5 + 5 + 5
86+ put ("maxAttempts" , 12.0 );
87+ // for streaming Retry on more status codes
88+ put ("retryableStatusCodes" ,
89+ Arrays .asList (
90+ /*
91+ * All codes are retryable except OK and DEADLINE_EXCEEDED since
92+ * any others not listed here cause a very tight loop of retries.
93+ * DEADLINE_EXCEEDED is typically a result of a client specified deadline,
94+ * and definitionally should not result in a tight loop (it's a timeout).
95+ */
96+ Code .CANCELLED .toString (),
97+ Code .UNKNOWN .toString (),
98+ Code .INVALID_ARGUMENT .toString (),
99+ Code .NOT_FOUND .toString (),
100+ Code .ALREADY_EXISTS .toString (),
101+ Code .PERMISSION_DENIED .toString (),
102+ Code .RESOURCE_EXHAUSTED .toString (),
103+ Code .FAILED_PRECONDITION .toString (),
104+ Code .ABORTED .toString (),
105+ Code .OUT_OF_RANGE .toString (),
106+ Code .UNIMPLEMENTED .toString (),
107+ Code .INTERNAL .toString (),
108+ Code .UNAVAILABLE .toString (),
109+ Code .DATA_LOSS .toString (),
110+ Code .UNAUTHENTICATED .toString ()
111+ )
112+ );
113+ }
114+ });
68115 }
69- });
70- }
71- }));
116+ }
117+ ));
72118 }
73119 };
74120
0 commit comments