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,56 @@ 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+ }
74+
5175 {
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- );
76+ put ("name" , Arrays .asList (
77+ new HashMap () {
78+ {
79+ put ("service" , "flagd.sync.v1.FlagSyncService" );
80+ put ("method" , "SyncFlags" );
81+ }
82+ }
83+ ));
84+ put ("retryPolicy" , new HashMap (DEFAULT_RETRY_POLICY ) {
85+ {
86+ // 1 + 2 + 4 + 5 + 5 + 5 + 5 + 5 + 5 + 5
87+ put ("maxAttempts" , 12.0 );
88+ // for streaming Retry on more status codes
89+ put ("retryableStatusCodes" ,
90+ Arrays .asList (
91+ /*
92+ * All codes are retryable except OK and DEADLINE_EXCEEDED since
93+ * any others not listed here cause a very tight loop of retries.
94+ * DEADLINE_EXCEEDED is typically a result of a client specified
95+ * deadline,and definitionally should not result in a tight loop
96+ * (it's a timeout).
97+ */
98+ Code .CANCELLED .toString (),
99+ Code .UNKNOWN .toString (),
100+ Code .INVALID_ARGUMENT .toString (),
101+ Code .NOT_FOUND .toString (),
102+ Code .ALREADY_EXISTS .toString (),
103+ Code .PERMISSION_DENIED .toString (),
104+ Code .RESOURCE_EXHAUSTED .toString (),
105+ Code .FAILED_PRECONDITION .toString (),
106+ Code .ABORTED .toString (),
107+ Code .OUT_OF_RANGE .toString (),
108+ Code .UNIMPLEMENTED .toString (),
109+ Code .INTERNAL .toString (),
110+ Code .UNAVAILABLE .toString (),
111+ Code .DATA_LOSS .toString (),
112+ Code .UNAUTHENTICATED .toString ()
113+ )
114+ );
115+ }
116+ });
68117 }
69- });
70- }
71- }));
118+ }
119+ ));
72120 }
73121 };
74122
0 commit comments