Skip to content

Commit 0565cfd

Browse files
authored
Merge pull request #221 from splitio/debug/cdn_logging
Debug/cdn logging
2 parents 042b4f2 + b869868 commit 0565cfd

File tree

8 files changed

+74
-14
lines changed

8 files changed

+74
-14
lines changed

client/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>4.1.7-rc2</version>
8+
<version>4.1.7-rc3</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/client/SplitClientConfig.java

+31
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class SplitClientConfig {
4747
private final String _authServiceURL;
4848
private final String _streamingServiceURL;
4949
private final int _onDemandFetchRetryDelayMs;
50+
private final int _onDemandFetchMaxRetries;
51+
private final int _failedAttemptsBeforeLogging;
5052
private final boolean _cdnDebugLogging;
5153

5254
// Proxy configs
@@ -93,6 +95,8 @@ private SplitClientConfig(String endpoint,
9395
String authServiceURL,
9496
String streamingServiceURL,
9597
int onDemandFetchRetryDelayMs,
98+
int onDemandFetchMaxRetries,
99+
int failedAttemptsBeforeLogging,
96100
boolean cdnDebugLogging) {
97101
_endpoint = endpoint;
98102
_eventsEndpoint = eventsEndpoint;
@@ -125,6 +129,8 @@ private SplitClientConfig(String endpoint,
125129
_authServiceURL = authServiceURL;
126130
_streamingServiceURL = streamingServiceURL;
127131
_onDemandFetchRetryDelayMs = onDemandFetchRetryDelayMs;
132+
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
133+
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
128134
_cdnDebugLogging = cdnDebugLogging;
129135

130136
Properties props = new Properties();
@@ -256,6 +262,10 @@ public String streamingServiceURL() {
256262

257263
public int streamingRetryDelay() {return _onDemandFetchRetryDelayMs;}
258264

265+
public int streamingFetchMaxRetries() {return _onDemandFetchMaxRetries;}
266+
267+
public int failedAttemptsBeforeLogging() {return _failedAttemptsBeforeLogging;}
268+
259269
public boolean cdnDebugLogging() { return _cdnDebugLogging; }
260270

261271

@@ -295,6 +305,8 @@ public static final class Builder {
295305
private String _authServiceURL = "https://auth.split.io/api/auth";
296306
private String _streamingServiceURL = "https://streaming.split.io/sse";
297307
private int _onDemandFetchRetryDelayMs = 50;
308+
private int _onDemandFetchMaxRetries = 10;
309+
private int _failedAttemptsBeforeLogging = -1;
298310
private boolean _cdnDebugLogging = true;
299311

300312
public Builder() {
@@ -697,6 +709,16 @@ public Builder streamingRetryDelay(int onDemandFetchRetryDelayMs) {
697709
return this;
698710
}
699711

712+
public Builder streamingFetchMaxRetries(int maxRetries) {
713+
_onDemandFetchMaxRetries = maxRetries;
714+
return this;
715+
}
716+
717+
public Builder failedAttemptsBeforeLoggingCDNInfo(int failedAttemptsBeforeLogging) {
718+
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
719+
return this;
720+
}
721+
700722
/**
701723
* Enable logging response headers for requests made to our CDN.
702724
* @param cdnDebugLogging
@@ -780,6 +802,13 @@ public SplitClientConfig build() {
780802
if(_onDemandFetchRetryDelayMs <= 0) {
781803
throw new IllegalStateException("streamingRetryDelay must be > 0");
782804
}
805+
if(_onDemandFetchMaxRetries <= 0) {
806+
throw new IllegalStateException("_onDemandFetchMaxRetries must be > 0");
807+
}
808+
809+
if (_failedAttemptsBeforeLogging < 0) {
810+
_failedAttemptsBeforeLogging = _onDemandFetchMaxRetries / 2;
811+
}
783812

784813
return new SplitClientConfig(
785814
_endpoint,
@@ -813,6 +842,8 @@ public SplitClientConfig build() {
813842
_authServiceURL,
814843
_streamingServiceURL,
815844
_onDemandFetchRetryDelayMs,
845+
_onDemandFetchMaxRetries,
846+
_failedAttemptsBeforeLogging,
816847
_cdnDebugLogging);
817848
}
818849
}

client/src/main/java/io/split/client/SplitFactoryImpl.java

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
159159
buildSSEdHttpClient(config),
160160
_segmentCache,
161161
config.streamingRetryDelay(),
162+
config.streamingFetchMaxRetries(),
163+
config.failedAttemptsBeforeLogging(),
162164
config.cdnDebugLogging());
163165
_syncManager.start();
164166

client/src/main/java/io/split/engine/common/SyncManagerImp.java

+24-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,32 @@ public static SyncManagerImp build(boolean streamingEnabledConfig,
6161
CloseableHttpClient sseHttpClient,
6262
SegmentCache segmentCache,
6363
int streamingRetryDelay,
64+
int maxOnDemandFetchRetries,
65+
int failedAttemptsBeforeLogging,
6466
boolean cdnDebugLogging) {
6567
LinkedBlockingQueue<PushManager.Status> pushMessages = new LinkedBlockingQueue<>();
66-
Synchronizer synchronizer = new SynchronizerImp(splitSynchronizationTask, splitFetcher, segmentSynchronizationTaskImp, splitCache, segmentCache, streamingRetryDelay, cdnDebugLogging);
67-
PushManager pushManager = PushManagerImp.build(synchronizer, streamingServiceUrl, authUrl, httpClient, pushMessages, sseHttpClient);
68-
return new SyncManagerImp(streamingEnabledConfig, synchronizer, pushManager, pushMessages, authRetryBackOffBase);
68+
Synchronizer synchronizer = new SynchronizerImp(splitSynchronizationTask,
69+
splitFetcher,
70+
segmentSynchronizationTaskImp,
71+
splitCache,
72+
segmentCache,
73+
streamingRetryDelay,
74+
maxOnDemandFetchRetries,
75+
failedAttemptsBeforeLogging,
76+
cdnDebugLogging);
77+
78+
PushManager pushManager = PushManagerImp.build(synchronizer,
79+
streamingServiceUrl,
80+
authUrl,
81+
httpClient,
82+
pushMessages,
83+
sseHttpClient);
84+
85+
return new SyncManagerImp(streamingEnabledConfig,
86+
synchronizer,
87+
pushManager,
88+
pushMessages,
89+
authRetryBackOffBase);
6990
}
7091

7192
@Override

client/src/main/java/io/split/engine/common/SynchronizerImp.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
public class SynchronizerImp implements Synchronizer {
2323

24-
private static final int MAX_ATTEMPTS = 10;
25-
2624
private static final Logger _log = LoggerFactory.getLogger(Synchronizer.class);
2725
private final SplitSynchronizationTask _splitSynchronizationTask;
2826
private final SplitFetcher _splitFetcher;
@@ -31,7 +29,10 @@ public class SynchronizerImp implements Synchronizer {
3129
private final SplitCache _splitCache;
3230
private final SegmentCache _segmentCache;
3331
private final int _onDemandFetchRetryDelayMs;
32+
private final int _onDemandFetchMaxRetries;
33+
private final int _failedAttemptsBeforeLogging;
3434
private final boolean _cdnResponseHeadersLogging;
35+
3536
private final Gson gson = new GsonBuilder().create();
3637

3738
public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
@@ -40,6 +41,8 @@ public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
4041
SplitCache splitCache,
4142
SegmentCache segmentCache,
4243
int onDemandFetchRetryDelayMs,
44+
int onDemandFetchMaxRetries,
45+
int failedAttemptsBeforeLogging,
4346
boolean cdnResponseHeadersLogging) {
4447
_splitSynchronizationTask = checkNotNull(splitSynchronizationTask);
4548
_splitFetcher = checkNotNull(splitFetcher);
@@ -48,6 +51,8 @@ public SynchronizerImp(SplitSynchronizationTask splitSynchronizationTask,
4851
_segmentCache = checkNotNull(segmentCache);
4952
_onDemandFetchRetryDelayMs = checkNotNull(onDemandFetchRetryDelayMs);
5053
_cdnResponseHeadersLogging = cdnResponseHeadersLogging;
54+
_onDemandFetchMaxRetries = onDemandFetchMaxRetries;
55+
_failedAttemptsBeforeLogging = failedAttemptsBeforeLogging;
5156

5257
ThreadFactory splitsThreadFactory = new ThreadFactoryBuilder()
5358
.setDaemon(true)
@@ -92,15 +97,15 @@ public void refreshSplits(long targetChangeNumber) {
9297
.responseHeadersCallback(_cdnResponseHeadersLogging ? captor::handle : null)
9398
.build();
9499

95-
int remainingAttempts = MAX_ATTEMPTS;
100+
int remainingAttempts = _onDemandFetchMaxRetries;
96101
while(true) {
97102
remainingAttempts--;
98103
_splitFetcher.forceRefresh(opts);
99104
if (targetChangeNumber <= _splitCache.getChangeNumber()) {
100-
_log.debug(String.format("Refresh completed in %s attempts.", MAX_ATTEMPTS - remainingAttempts));
105+
_log.debug(String.format("Refresh completed in %s attempts.", _onDemandFetchMaxRetries - remainingAttempts));
101106
break;
102107
} else if (remainingAttempts <= 0) {
103-
_log.info(String.format("No changes fetched after %s attempts.", MAX_ATTEMPTS));
108+
_log.info(String.format("No changes fetched after %s attempts.", _onDemandFetchMaxRetries));
104109
break;
105110
}
106111
try {
@@ -111,7 +116,8 @@ public void refreshSplits(long targetChangeNumber) {
111116
}
112117
}
113118

114-
if (_cdnResponseHeadersLogging && remainingAttempts <= (MAX_ATTEMPTS / 2)) {
119+
if (_cdnResponseHeadersLogging &&
120+
(_onDemandFetchMaxRetries - remainingAttempts) > _failedAttemptsBeforeLogging) {
115121
_log.info(String.format("CDN Debug headers: %s", gson.toJson(captor.get())));
116122
}
117123
}
@@ -127,7 +133,7 @@ public void localKillSplit(String splitName, String defaultTreatment, long newCh
127133
@Override
128134
public void refreshSegment(String segmentName, long changeNumber) {
129135
int retries = 1;
130-
while(changeNumber > _segmentCache.getChangeNumber(segmentName) && retries <= MAX_ATTEMPTS) {
136+
while(changeNumber > _segmentCache.getChangeNumber(segmentName) && retries <= _onDemandFetchMaxRetries) {
131137
SegmentFetcher fetcher = _segmentSynchronizationTaskImp.getFetcher(segmentName);
132138
try{
133139
fetcher.fetch(true);

client/src/test/java/io/split/engine/common/SynchronizerTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void beforeMethod() {
2626
_splitCache = Mockito.mock(SplitCache.class);
2727
_segmentCache = Mockito.mock(SegmentCache.class);
2828

29-
_synchronizer = new SynchronizerImp(_refreshableSplitFetcherTask, _splitFetcher, _segmentFetcher, _splitCache, _segmentCache, 50, false);
29+
_synchronizer = new SynchronizerImp(_refreshableSplitFetcherTask, _splitFetcher, _segmentFetcher, _splitCache, _segmentCache, 50, 10, 5, false);
3030
}
3131

3232
@Test

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.split.client</groupId>
66
<artifactId>java-client-parent</artifactId>
7-
<version>4.1.7-rc2</version>
7+
<version>4.1.7-rc3</version>
88
<dependencyManagement>
99
<dependencies>
1010
<dependency>

testing/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.split.client</groupId>
88
<artifactId>java-client-parent</artifactId>
9-
<version>4.1.7-rc2</version>
9+
<version>4.1.7-rc3</version>
1010
</parent>
1111

1212
<artifactId>java-client-testing</artifactId>

0 commit comments

Comments
 (0)