28
28
import java .util .ArrayList ;
29
29
30
30
import static com .google .common .base .Preconditions .checkNotNull ;
31
- import static io .split .Spec .SPEC_VERSION ;
32
31
import static io .split .Spec .SPEC_1_3 ;
33
32
import static io .split .Spec .SPEC_1_1 ;
34
33
@@ -44,6 +43,7 @@ public final class HttpSplitChangeFetcher implements SplitChangeFetcher {
44
43
private static final String TILL = "till" ;
45
44
private static final String SETS = "sets" ;
46
45
private static final String SPEC = "s" ;
46
+ private String specVersion = SPEC_1_3 ;
47
47
private int PROXY_CHECK_INTERVAL_MILLISECONDS_SS = 24 * 60 * 60 * 1000 ;
48
48
private Long _lastProxyCheckTimestamp = 0L ;
49
49
private final SplitHttpClient _client ;
@@ -75,9 +75,9 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
75
75
long start = System .currentTimeMillis ();
76
76
SplitHttpResponse response ;
77
77
try {
78
- if (SPEC_VERSION .equals (SPEC_1_1 ) && (System .currentTimeMillis () - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS )) {
78
+ if (specVersion .equals (SPEC_1_1 ) && (System .currentTimeMillis () - _lastProxyCheckTimestamp >= PROXY_CHECK_INTERVAL_MILLISECONDS_SS )) {
79
79
_log .info ("Switching to new Feature flag spec ({}) and fetching." , SPEC_1_3 );
80
- SPEC_VERSION = SPEC_1_3 ;
80
+ specVersion = SPEC_1_3 ;
81
81
}
82
82
URI uri = buildURL (options , since , sinceRBS );
83
83
response = _client .get (uri , options , null );
@@ -87,12 +87,12 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
87
87
throw new UriTooLongException (String .format ("Status code: %s. Message: %s" , response .statusCode (), response .statusMessage ()));
88
88
}
89
89
90
- if (response .statusCode () == HttpStatus .SC_BAD_REQUEST && SPEC_VERSION .equals (Spec .SPEC_1_3 ) && _rootURIOverriden ) {
91
- SPEC_VERSION = Spec .SPEC_1_1 ;
90
+ if (response .statusCode () == HttpStatus .SC_BAD_REQUEST && specVersion .equals (Spec .SPEC_1_3 ) && _rootURIOverriden ) {
91
+ specVersion = Spec .SPEC_1_1 ;
92
92
_log .warn ("Detected proxy without support for Feature flags spec {} version, will switch to spec version {}" ,
93
93
SPEC_1_3 , SPEC_1_1 );
94
94
_lastProxyCheckTimestamp = System .currentTimeMillis ();
95
- return fetch (since , sinceRBS , options );
95
+ return fetch (since , 0 , options );
96
96
}
97
97
98
98
_telemetryRuntimeProducer .recordSyncError (ResourceEnum .SPLIT_SYNC , response .statusCode ());
@@ -106,11 +106,12 @@ public SplitChange fetch(long since, long sinceRBS, FetchOptions options) {
106
106
_telemetryRuntimeProducer .recordSyncLatency (HTTPLatenciesEnum .SPLITS , System .currentTimeMillis () - start );
107
107
}
108
108
109
- if (SPEC_VERSION .equals (Spec .SPEC_1_1 )) {
109
+ String body = response .body ();
110
+ if (specVersion .equals (Spec .SPEC_1_1 )) {
110
111
return Json .fromJson (body , SplitChangesOldPayloadDto .class ).toSplitChange ();
111
112
}
112
113
113
- return Json .fromJson (response . body () , SplitChange .class );
114
+ return Json .fromJson (body , SplitChange .class );
114
115
}
115
116
116
117
public Long getLastProxyCheckTimestamp () {
@@ -132,7 +133,7 @@ private ChangeDto<RuleBasedSegment> createEmptyDTO() {
132
133
}
133
134
134
135
private URI buildURL (FetchOptions options , long since , long sinceRBS ) throws URISyntaxException {
135
- URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + SPEC_VERSION );
136
+ URIBuilder uriBuilder = new URIBuilder (_target ).addParameter (SPEC , "" + specVersion );
136
137
uriBuilder .addParameter (SINCE , "" + since );
137
138
uriBuilder .addParameter (RB_SINCE , "" + sinceRBS );
138
139
if (!options .flagSetsFilter ().isEmpty ()) {
0 commit comments