Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
40f6b18
Cleaning up current logic
ldecheverz-split Mar 23, 2021
bfc5301
Interfaces
ldecheverz-split Mar 29, 2021
e92f321
Merge pull request #198 from splitio/telemetry-cleanup-current-logic
ldecheverz-split Mar 31, 2021
ae9da58
Adding interfaces and Implementation
ldecheverz-split Apr 9, 2021
086150c
Changing name
ldecheverz-split Apr 9, 2021
31a8208
Fixing PR comments
ldecheverz-split Apr 9, 2021
b52c519
Adding BucketCalculator, tests and several minor changes
ldecheverz-split Apr 11, 2021
a963764
Changing name of init
ldecheverz-split Apr 12, 2021
d5ef9ef
Merge pull request #202 from splitio/telemetry-storage-inmemory
ldecheverz-split Apr 12, 2021
bd086ba
Commiting to be able to merge
ldecheverz-split Apr 13, 2021
a6e71d5
Merge branch 'development' of github.com:splitio/java-client into tel…
ldecheverz-split Apr 13, 2021
7f2cc84
no message
ldecheverz-split Apr 13, 2021
f530d9a
Adding new methods to segment cache
ldecheverz-split Apr 14, 2021
26ed1fa
Almost final advances
ldecheverz-split Apr 21, 2021
22cb0f0
Adding delay on streaming retry
ldecheverz-split Apr 22, 2021
66de222
Pr comments
ldecheverz-split Apr 22, 2021
1438f78
PR Fix
ldecheverz-split Apr 22, 2021
27eaa84
Merge pull request #208 from splitio/stream-retry-delay
ldecheverz-split Apr 22, 2021
de70bf2
Release 4.1.7-rc
ldecheverz-split Apr 22, 2021
726366b
PR fix
ldecheverz-split Apr 22, 2021
6541254
Merge pull request #209 from splitio/release-4.1.7-rc
ldecheverz-split Apr 22, 2021
196e789
Adding config Generator
ldecheverz-split Apr 26, 2021
8788b77
support for cdn response headers logging - wip
mredolatti Apr 26, 2021
4df2daf
Update README.md
sanzmauro Apr 26, 2021
6228c6f
Adding tests
ldecheverz-split Apr 27, 2021
02f48e2
Fixing consts
ldecheverz-split Apr 27, 2021
f06c806
Merge commit '4df2dafbf6ae8d46bf6d22bbdcc2f2ef69c5f117' into telemetr…
ldecheverz-split Apr 27, 2021
a71a88d
Merge pull request #212 from splitio/readme-dotnet
ldecheverz-split Apr 27, 2021
86be0c0
FIxing travis
ldecheverz-split Apr 27, 2021
71c0ca8
add logging for cdn headers
mredolatti Apr 27, 2021
ddf4621
Merge branch 'development' into debug/cdn_logging
mredolatti Apr 27, 2021
4b67733
Merge pull request #211 from splitio/telemetry-synchronizer
ldecheverz-split Apr 27, 2021
d7f0531
true by default
mredolatti Apr 27, 2021
f49ba00
sonarqube comment
mredolatti Apr 27, 2021
52950cf
Merge remote-tracking branch 'origin/debug/cdn_logging' into debug/cd…
mredolatti Apr 27, 2021
042b4f2
Merge pull request #213 from splitio/debug/cdn_logging
mredolatti Apr 27, 2021
d3c29f0
Adding TelemtrySyncTask
ldecheverz-split Apr 28, 2021
801a7b1
Merge pull request #214 from splitio/telemetry-stats
ldecheverz-split Apr 28, 2021
35e2f1b
Adding Stop
ldecheverz-split Apr 28, 2021
5eb5a9e
Merge pull request #215 from splitio/telemetry-stats
ldecheverz-split Apr 28, 2021
422c156
sdk internal ready implementation
sanzmauro Apr 29, 2021
624851b
pr feedback
sanzmauro Apr 29, 2021
bed70a3
feedback
sanzmauro Apr 30, 2021
de2b36f
improvements
sanzmauro Apr 30, 2021
ab64d08
pr feedback
sanzmauro Apr 30, 2021
084eee0
feedback
sanzmauro Apr 30, 2021
c21fcd1
feedback
sanzmauro May 3, 2021
eeeb747
Merge pull request #216 from splitio/add-internal-ready
sanzmauro May 3, 2021
4b4bb99
added headers
sanzmauro Apr 30, 2021
66bd0ac
pr feedback
sanzmauro May 3, 2021
b0ffa88
pr feedback
sanzmauro May 3, 2021
c83b12b
Recording telemetry data
ldecheverz-split May 3, 2021
d3a3c7e
Merge branch 'telemetry' of github.com:splitio/java-client into telem…
ldecheverz-split May 3, 2021
6aa82ed
pr feedback
sanzmauro May 4, 2021
7e13192
Merge pull request #218 from splitio/add-sse-headers
sanzmauro May 4, 2021
84fd4ca
Attached every service
ldecheverz-split May 6, 2021
ba038b5
Merge branch 'telemetry' of github.com:splitio/java-client into telem…
ldecheverz-split May 6, 2021
ca11660
Files forgotten
ldecheverz-split May 6, 2021
8559aba
PR comments
ldecheverz-split May 6, 2021
2320147
Fixing PR Comments
ldecheverz-split May 10, 2021
b28fd25
Fixing Travis
ldecheverz-split May 11, 2021
70486f0
Merge pull request #219 from splitio/telemetry-attach-services
ldecheverz-split May 12, 2021
f5b39c5
Cleaning metrics and adding Telemetry config initializer
ldecheverz-split May 12, 2021
a6fd325
allow the user to change amount of attempts and how many attempts to …
mredolatti May 12, 2021
d387762
fix error message
mredolatti May 12, 2021
b869868
Merge branch 'development' into debug/cdn_logging
mredolatti May 12, 2021
0565cfd
Merge pull request #221 from splitio/debug/cdn_logging
mredolatti May 13, 2021
868dc77
force the cdn to hit origin if stale data is server after N retries
mredolatti May 17, 2021
ccc5c40
add uts
mredolatti May 17, 2021
e0bf264
Merge pull request #223 from splitio/feat/cdn_bypass
mredolatti May 18, 2021
2dd455c
Making syncManager start async and telemetry init
ldecheverz-split May 18, 2021
9043ace
improve logs, fix crap in random till generation
mredolatti May 19, 2021
1582d08
Merge branch 'development' into feat/cdn_bypass
mredolatti May 19, 2021
31c7e48
ask for target changeNumber when sending `till`
mredolatti May 19, 2021
b785a5d
Merge remote-tracking branch 'origin/feat/cdn_bypass' into feat/cdn_b…
mredolatti May 19, 2021
bed5bfd
Fix PR comments
ldecheverz-split May 19, 2021
9d8dd47
Travis fix
ldecheverz-split May 19, 2021
1a25c13
add retries and cdn bypass logic to segment fetchers
mredolatti May 20, 2021
d14da5c
add tests
mredolatti May 20, 2021
a0c4fd0
Fixing PR comments
ldecheverz-split May 21, 2021
78540db
Final fixes
ldecheverz-split May 21, 2021
859a697
Merge pull request #224 from splitio/connect-ready-sync-manager
ldecheverz-split May 21, 2021
d575244
Setting up size to events Queue
ldecheverz-split May 21, 2021
56a45c5
Merge branch 'telemetry' of github.com:splitio/java-client into size-…
ldecheverz-split May 21, 2021
285ae1b
Fixing wrong import
ldecheverz-split May 21, 2021
563a46e
Improving Test
ldecheverz-split May 21, 2021
80e720c
cleanup for release;
mredolatti May 21, 2021
70169ec
Fixing travis build
ldecheverz-split May 21, 2021
154a615
Fixing travis
ldecheverz-split May 21, 2021
99cf461
Merge pull request #225 from splitio/feat/cdn_bypass
mredolatti May 21, 2021
df8dcc9
Merge pull request #226 from splitio/size-event-queue
ldecheverz-split May 26, 2021
96c104d
Adding tests
ldecheverz-split May 27, 2021
848787d
Fixing old exceptions
ldecheverz-split May 28, 2021
c637a58
Fixing final stats sync
ldecheverz-split May 28, 2021
ea7c9b7
guava fix
ldecheverz-split May 28, 2021
a62f0ac
Fixing PR comments
ldecheverz-split May 28, 2021
efaac85
Merge pull request #227 from splitio/polishing
ldecheverz-split May 28, 2021
4dcbff8
Merge branch 'development' into telemetry
ldecheverz-split May 28, 2021
0a525ef
Merge with development
ldecheverz-split May 28, 2021
88f7cd3
Fix Travis
ldecheverz-split May 28, 2021
91cce5d
FIxing PR comments
ldecheverz-split May 28, 2021
f4bd0e5
Fixing PR Comments
ldecheverz-split Jun 1, 2021
68e3384
Fixing travis
ldecheverz-split Jun 1, 2021
bc42070
Fixing travis
ldecheverz-split Jun 2, 2021
c43f1f9
PR Comments
ldecheverz-split Jun 3, 2021
d398696
Removing conditions limit
ldecheverz-split Jun 4, 2021
4b7e9fa
Merge pull request #228 from splitio/telemetry
ldecheverz-split Jun 7, 2021
1b213c8
Merge pull request #231 from splitio/conditions
ldecheverz-split Jun 7, 2021
e7c4b3d
Changes log
ldecheverz-split Jun 7, 2021
e264811
Fix PR comments
ldecheverz-split Jun 7, 2021
70f26b5
PR comment
ldecheverz-split Jun 7, 2021
5047220
PR comment
ldecheverz-split Jun 7, 2021
4b8d6a6
Merge pull request #232 from splitio/release-4.2.0
ldecheverz-split Jun 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Split has built and maintains SDKs for:
* Java [Github](https://github.com/splitio/java-client) [Docs](https://help.split.io/hc/en-us/articles/360020405151-Java-SDK)
* Javascript [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK)
* Node [Github](https://github.com/splitio/javascript-client) [Docs](https://help.split.io/hc/en-us/articles/360020564931-Node-js-SDK)
* .NET [Github](https://github.com/splitio/.net-core-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
* .NET [Github](https://github.com/splitio/dotnet-client) [Docs](https://help.split.io/hc/en-us/articles/360020240172--NET-SDK)
* Ruby [Github](https://github.com/splitio/ruby-client) [Docs](https://help.split.io/hc/en-us/articles/360020673251-Ruby-SDK)
* PHP [Github](https://github.com/splitio/php-client) [Docs](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
* Python [Github](https://github.com/splitio/python-client) [Docs](https://help.split.io/hc/en-us/articles/360020359652-Python-SDK)
Expand Down
9 changes: 7 additions & 2 deletions client/CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
CHANGES

4.2.0 (Jun 7, 2021)
- Updated SDK telemetry storage, metrics and updater to be more effective and send less often.
- Improved the synchronization flow to be more reliable in the event of an edge case generating delay in cache purge propagation, keeping the SDK cache properly synced.
- Fixed issue where the SDK was validating no Split had over 50 conditions (legacy code).

4.1.6 (Apr 15, 2021)
-Updated log level and message in some messages.
- Updated log level and message in some messages.

4.1.5 (Apr 6, 2021)
-Updated: Streaming retry fix.
- Updated streaming logic to use limited fetch retry attempts.

4.1.4 (Mar 19, 2021)
- Updated: Internal cache structure refactor.
Expand Down
4 changes: 2 additions & 2 deletions client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.split.client</groupId>
<artifactId>java-client-parent</artifactId>
<version>4.1.6</version>
<version>4.2.0</version>
</parent>
<artifactId>java-client</artifactId>
<packaging>jar</packaging>
Expand Down Expand Up @@ -121,7 +121,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>29.0-jre</version>
<version>30.0-jre</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
15 changes: 15 additions & 0 deletions client/src/main/java/io/split/cache/SegmentCache.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.split.cache;

import io.split.engine.segments.SegmentImp;

import java.util.List;
import java.util.Set;

/**
* Memory for segments
Expand Down Expand Up @@ -42,4 +45,16 @@ public interface SegmentCache {
* clear all segments
*/
void clear();

/**
* return every segment
* @return
*/
List<SegmentImp> getAll();

/**
* return key count
* @return
*/
long getKeyCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;

/**
* InMemoryCache Implementation
Expand Down Expand Up @@ -59,4 +61,14 @@ public long getChangeNumber(String segmentName) {
public void clear() {
_segments.clear();
}

@Override
public List<SegmentImp> getAll() {
return _segments.values().stream().collect(Collectors.toList());
}

@Override
public long getKeyCount() {
return _segments.values().stream().mapToLong(SegmentImp::getKeysSize).sum();
}
}
17 changes: 17 additions & 0 deletions client/src/main/java/io/split/client/ApiKeyCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class ApiKeyCounter {

private static final Logger _log = LoggerFactory.getLogger(ApiKeyCounter.class);
Expand Down Expand Up @@ -63,4 +66,18 @@ boolean isApiKeyPresent(String apiKey) {
int getCount(String apiKey) {
return USED_API_KEYS.count(apiKey);
}

public Map<String, Long> getFactoryInstances() {
Map<String, Long> factoryInstances = new HashMap<>();
for (String factory :USED_API_KEYS) {
factoryInstances.putIfAbsent(factory, new Long(getCount(factory)));
}

return factoryInstances;
}

@VisibleForTesting
void clearApiKeys() {
USED_API_KEYS.clear();
}
}
50 changes: 30 additions & 20 deletions client/src/main/java/io/split/client/EventClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import io.split.client.dtos.Event;
import io.split.client.utils.GenericClientUtil;
import io.split.client.utils.Utils;
import io.split.telemetry.domain.enums.EventsDataRecordsEnum;
import io.split.telemetry.domain.enums.HTTPLatenciesEnum;
import io.split.telemetry.domain.enums.LastSynchronizationRecordsEnum;
import io.split.telemetry.storage.TelemetryEvaluationProducer;
import io.split.telemetry.storage.TelemetryRuntimeProducer;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -23,6 +28,7 @@
import java.util.concurrent.TimeUnit;

import static java.lang.Thread.MIN_PRIORITY;
import static com.google.common.base.Preconditions.checkNotNull;

/**
* Responsible for sending events added via .track() to Split collection services
Expand All @@ -45,34 +51,28 @@ public class EventClientImpl implements EventClient {
private final CloseableHttpClient _httpclient;
private final URI _target;
private final int _waitBeforeShutdown;
private final TelemetryRuntimeProducer _telemetryRuntimeProducer;

ThreadFactory eventClientThreadFactory(final String name) {
return new ThreadFactory() {
@Override
public Thread newThread(final Runnable r) {
return new Thread(new Runnable() {
@Override
public void run() {
Thread.currentThread().setPriority(MIN_PRIORITY);
r.run();
}
}, name);
}
};
return r -> new Thread(() -> {
Thread.currentThread().setPriority(MIN_PRIORITY);
r.run();
}, name);
}


public static EventClientImpl create(CloseableHttpClient httpclient, URI eventsRootTarget, int maxQueueSize, long flushIntervalMillis, int waitBeforeShutdown) throws URISyntaxException {
return new EventClientImpl(new LinkedBlockingQueue<WrappedEvent>(),
public static EventClientImpl create(CloseableHttpClient httpclient, URI eventsRootTarget, int maxQueueSize, long flushIntervalMillis, int waitBeforeShutdown, TelemetryRuntimeProducer telemetryRuntimeProducer) throws URISyntaxException {
return new EventClientImpl(new LinkedBlockingQueue<>(maxQueueSize),
httpclient,
Utils.appendPath(eventsRootTarget, "api/events/bulk"),
maxQueueSize,
flushIntervalMillis,
waitBeforeShutdown);
waitBeforeShutdown,
telemetryRuntimeProducer);
}

EventClientImpl(BlockingQueue<WrappedEvent> eventQueue, CloseableHttpClient httpclient, URI target, int maxQueueSize,
long flushIntervalMillis, int waitBeforeShutdown) throws URISyntaxException {
long flushIntervalMillis, int waitBeforeShutdown, TelemetryRuntimeProducer telemetryRuntimeProducer) throws URISyntaxException {

_httpclient = httpclient;

Expand All @@ -83,6 +83,7 @@ public static EventClientImpl create(CloseableHttpClient httpclient, URI eventsR

_maxQueueSize = maxQueueSize;
_flushIntervalMillis = flushIntervalMillis;
_telemetryRuntimeProducer = checkNotNull(telemetryRuntimeProducer);

_senderExecutor = new ThreadPoolExecutor(
1,
Expand Down Expand Up @@ -122,9 +123,16 @@ public boolean track(Event event, int eventSize) {
if (event == null) {
return false;
}
_eventQueue.put(new WrappedEvent(event, eventSize));
if(_eventQueue.offer(new WrappedEvent(event, eventSize))) {
_telemetryRuntimeProducer.recordEventStats(EventsDataRecordsEnum.EVENTS_QUEUED, 1);
}
else {
_log.warn("Event dropped.");
_telemetryRuntimeProducer.recordEventStats(EventsDataRecordsEnum.EVENTS_DROPPED, 1);
}

} catch (InterruptedException e) {
} catch (ClassCastException | NullPointerException | IllegalArgumentException e) {
_telemetryRuntimeProducer.recordEventStats(EventsDataRecordsEnum.EVENTS_DROPPED, 1);
_log.warn("Interruption when adding event withed while adding message %s.", event);
return false;
}
Expand Down Expand Up @@ -153,7 +161,7 @@ public void run() {
List<Event> events = new ArrayList<>();
long accumulated = 0;
try {
while (true) {
while (!Thread.currentThread().isInterrupted()) {
WrappedEvent data = _eventQueue.take();
Event event = data.event();
Long size = data.size();
Expand All @@ -169,7 +177,7 @@ public void run() {

continue;
}

long initTime = System.currentTimeMillis();
if (events.size() >= _maxQueueSize || accumulated >= MAX_SIZE_BYTES || event == CENTINEL) {

// Send over the network
Expand All @@ -183,6 +191,8 @@ public void run() {
// Clear the queue of events for the next batch.
events = new ArrayList<>();
accumulated = 0;
_telemetryRuntimeProducer.recordSyncLatency(HTTPLatenciesEnum.EVENTS, System.currentTimeMillis()-initTime);
_telemetryRuntimeProducer.recordSuccessfulSync(LastSynchronizationRecordsEnum.EVENTS, System.currentTimeMillis());
}
}
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
import io.split.client.dtos.SegmentChange;
import io.split.client.utils.Json;
import io.split.client.utils.Utils;
import io.split.engine.common.FetchOptions;
import io.split.engine.metrics.Metrics;
import io.split.engine.segments.SegmentChangeFetcher;
import io.split.telemetry.domain.enums.HTTPLatenciesEnum;
import io.split.telemetry.domain.enums.LastSynchronizationRecordsEnum;
import io.split.telemetry.domain.enums.ResourceEnum;
import io.split.telemetry.storage.TelemetryRuntimeProducer;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.net.URIBuilder;
import org.slf4j.Logger;
Expand All @@ -17,6 +24,8 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.stream.Collectors;

import static com.google.common.base.Preconditions.checkNotNull;

Expand All @@ -27,57 +36,72 @@ public final class HttpSegmentChangeFetcher implements SegmentChangeFetcher {
private static final Logger _log = LoggerFactory.getLogger(HttpSegmentChangeFetcher.class);

private static final String SINCE = "since";
private static final String TILL = "till";
private static final String PREFIX = "segmentChangeFetcher";
private static final String NAME_CACHE = "Cache-Control";
private static final String VALUE_CACHE = "no-cache";
private static final String CACHE_CONTROL_HEADER_NAME = "Cache-Control";
private static final String CACHE_CONTROL_HEADER_VALUE = "no-cache";

private static final String HEADER_FASTLY_DEBUG_NAME = "Fastly-Debug";
private static final String HEADER_FASTLY_DEBUG_VALUE = "1";

private final CloseableHttpClient _client;
private final URI _target;
private final Metrics _metrics;

public static HttpSegmentChangeFetcher create(CloseableHttpClient client, URI root) throws URISyntaxException {
return create(client, root, new Metrics.NoopMetrics());
}
private final TelemetryRuntimeProducer _telemetryRuntimeProducer;

public static HttpSegmentChangeFetcher create(CloseableHttpClient client, URI root, Metrics metrics) throws URISyntaxException {
return new HttpSegmentChangeFetcher(client, Utils.appendPath(root, "api/segmentChanges"), metrics);
public static HttpSegmentChangeFetcher create(CloseableHttpClient client, URI root, TelemetryRuntimeProducer telemetryRuntimeProducer) throws URISyntaxException {
return new HttpSegmentChangeFetcher(client, Utils.appendPath(root, "api/segmentChanges"), telemetryRuntimeProducer);
}

private HttpSegmentChangeFetcher(CloseableHttpClient client, URI uri, Metrics metrics) {
private HttpSegmentChangeFetcher(CloseableHttpClient client, URI uri, TelemetryRuntimeProducer telemetryRuntimeProducer) {
_client = client;
_target = uri;
_metrics = metrics;
checkNotNull(_target);
_telemetryRuntimeProducer = checkNotNull(telemetryRuntimeProducer);
}

@Override
public SegmentChange fetch(String segmentName, long since, boolean addCacheHeader) {
public SegmentChange fetch(String segmentName, long since, FetchOptions options) {
long start = System.currentTimeMillis();

CloseableHttpResponse response = null;

try {
String path = _target.getPath() + "/" + segmentName;
URI uri = new URIBuilder(_target).setPath(path).addParameter(SINCE, "" + since).build();
URIBuilder uriBuilder = new URIBuilder(_target)
.setPath(path)
.addParameter(SINCE, "" + since);
if (options.hasCustomCN()) {
uriBuilder.addParameter(TILL, "" + options.targetCN());
}

URI uri = uriBuilder.build();
HttpGet request = new HttpGet(uri);
if(addCacheHeader) {
request.setHeader(NAME_CACHE, VALUE_CACHE);

if(options.cacheControlHeadersEnabled()) {
request.setHeader(CACHE_CONTROL_HEADER_NAME, CACHE_CONTROL_HEADER_VALUE);
}

if (options.fastlyDebugHeaderEnabled()) {
request.addHeader(HEADER_FASTLY_DEBUG_NAME, HEADER_FASTLY_DEBUG_VALUE);
}

response = _client.execute(request);
options.handleResponseHeaders(Arrays.stream(response.getHeaders())
.collect(Collectors.toMap(Header::getName, Header::getValue)));

int statusCode = response.getCode();

if (statusCode < 200 || statusCode >= 300) {
if (statusCode < HttpStatus.SC_OK || statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
_telemetryRuntimeProducer.recordSyncError(ResourceEnum.SEGMENT_SYNC, statusCode);
_log.error("Response status was: " + statusCode);
if (statusCode == 403) {
if (statusCode == HttpStatus.SC_FORBIDDEN) {
_log.error("factory instantiation: you passed a browser type api_key, " +
"please grab an api key from the Split console that is of type sdk");
}
_metrics.count(PREFIX + ".status." + statusCode, 1);
throw new IllegalStateException("Could not retrieve segment changes for " + segmentName + "; http return code " + statusCode);
}


_telemetryRuntimeProducer.recordSuccessfulSync(LastSynchronizationRecordsEnum.SEGMENTS, System.currentTimeMillis());

String json = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (_log.isDebugEnabled()) {
Expand All @@ -86,11 +110,10 @@ public SegmentChange fetch(String segmentName, long since, boolean addCacheHeade

return Json.fromJson(json, SegmentChange.class);
} catch (Throwable t) {
_metrics.count(PREFIX + ".exception", 1);
throw new IllegalStateException("Problem fetching segmentChanges: " + t.getMessage(), t);
} finally {
_telemetryRuntimeProducer.recordSyncLatency(HTTPLatenciesEnum.SEGMENTS, System.currentTimeMillis()-start);
Utils.forceClose(response);
_metrics.time(PREFIX + ".time", System.currentTimeMillis() - start);
}


Expand Down
Loading