Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public LocalhostSplitFactory(String directory, String file) throws IOException {
SplitCache splitCache = new InMemoryCacheImp();
SDKReadinessGates sdkReadinessGates = new SDKReadinessGates();

sdkReadinessGates.splitsAreReady();
_cacheUpdaterService = new CacheUpdaterService(splitCache);
_cacheUpdaterService.updateCache(splitAndKeyToTreatment);
sdkReadinessGates.sdkInternalReady();
_client = new SplitClientImpl(this, splitCache,
new ImpressionsManager.NoOpImpressionsManager(), new NoopEventClient(),
SplitClientConfig.builder().setBlockUntilReadyTimeout(1).build(), sdkReadinessGates, new EvaluatorImp(splitCache), new NoopTelemetryStorage(), new NoopTelemetryStorage());
Expand Down
7 changes: 3 additions & 4 deletions client/src/main/java/io/split/client/SplitClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.split.inputValidation.KeyValidator;
import io.split.inputValidation.SplitNameValidator;
import io.split.inputValidation.TrafficTypeValidator;
import io.split.telemetry.domain.enums.LastSynchronizationRecordsEnum;
import io.split.telemetry.domain.enums.MethodEnum;
import io.split.telemetry.storage.TelemetryConfigProducer;
import io.split.telemetry.storage.TelemetryEvaluationProducer;
Expand Down Expand Up @@ -138,7 +137,7 @@ public void blockUntilReady() throws TimeoutException, InterruptedException {
if (_config.blockUntilReady() <= 0) {
throw new IllegalArgumentException("setBlockUntilReadyTimeout must be positive but in config was: " + _config.blockUntilReady());
}
if (!_gates.isSDKReady(_config.blockUntilReady())) {
if (!_gates.waitUntilInternalReady(_config.blockUntilReady())) {
throw new TimeoutException("SDK was not ready in " + _config.blockUntilReady()+ " milliseconds");
}
_log.debug(String.format("Split SDK ready in %d ms", (System.currentTimeMillis() - startTime)));
Expand Down Expand Up @@ -188,7 +187,7 @@ private boolean track(Event event) {
private SplitResult getTreatmentWithConfigInternal(String method, String matchingKey, String bucketingKey, String split, Map<String, Object> attributes, MethodEnum methodEnum) {
long initTime = System.currentTimeMillis();
try {
if(!_gates.isSDKReadyNow()){
if(!_gates.isSDKReady()){
_log.warn(method + ": the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
_telemetryConfigProducer.recordNonReadyUsage();
}
Expand All @@ -215,7 +214,7 @@ private SplitResult getTreatmentWithConfigInternal(String method, String matchin

EvaluatorImp.TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(matchingKey, bucketingKey, split, attributes);

if (result.treatment.equals(Treatments.CONTROL) && result.label.equals(Labels.DEFINITION_NOT_FOUND) && _gates.isSDKReadyNow()) {
if (result.treatment.equals(Treatments.CONTROL) && result.label.equals(Labels.DEFINITION_NOT_FOUND) && _gates.isSDKReady()) {
_log.warn(
"getTreatment: you passed \"" + split + "\" that does not exist in this environment, " +
"please double check what Splits exist in the web console.");
Expand Down
17 changes: 10 additions & 7 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import io.split.client.interceptors.GzipDecoderResponseInterceptor;
import io.split.client.interceptors.GzipEncoderRequestInterceptor;
import io.split.client.interceptors.SdkMetadataInterceptorFilter;
import io.split.client.metrics.HttpMetrics;
import io.split.cache.InMemoryCacheImp;
import io.split.cache.SplitCache;
import io.split.engine.evaluator.Evaluator;
Expand Down Expand Up @@ -124,8 +123,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
// Cache Initialisations
_segmentCache = new SegmentCacheInMemoryImpl();
_splitCache = new InMemoryCacheImp();
_telemetrySynchronizer = new SynchronizerMemory(_httpclient, URI.create(config.get_telemetryURL()), _telemetryStorage, _splitCache, _segmentCache, _telemetryStorage);
_telemetrySyncTask = new TelemetrySyncTask(config.get_telemetryRefreshRate(), _telemetrySynchronizer);
_telemetrySynchronizer = new SynchronizerMemory(_httpclient, URI.create(config.get_telemetryURL()), _telemetryStorage, _splitCache, _segmentCache, _telemetryStorage, _startTime);


// Segments
_segmentSynchronizationTaskImp = buildSegments(config);
Expand All @@ -142,9 +141,7 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
// EventClient
_eventClient = EventClientImpl.create(_httpclient, _eventsRootTarget, config.eventsQueueSize(), config.eventFlushIntervalInMillis(), config.waitBeforeShutdown(), _telemetryStorage);

// SyncManager
_syncManager = SyncManagerImp.build(config.streamingEnabled(), _splitSynchronizationTask, _splitFetcher, _segmentSynchronizationTaskImp, _splitCache, config.authServiceURL(), _httpclient, config.streamingServiceURL(), config.authRetryBackoffBase(), buildSSEdHttpClient(apiToken, config), _segmentCache, config.streamingRetryDelay(), _gates, _telemetryStorage);
_syncManager.start();
_telemetrySyncTask = new TelemetrySyncTask(config.get_telemetryRefreshRate(), _telemetrySynchronizer);

// Evaluator
_evaluator = new EvaluatorImp(_splitCache);
Expand All @@ -155,6 +152,12 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
// SplitManager
_manager = new SplitManagerImpl(_splitCache, config, _gates, _telemetryStorage);

// SyncManager
_syncManager = SyncManagerImp.build(config.streamingEnabled(), _splitSynchronizationTask, _splitFetcher, _segmentSynchronizationTaskImp, _splitCache,
config.authServiceURL(), _httpclient, config.streamingServiceURL(), config.authRetryBackoffBase(), buildSSEdHttpClient(apiToken, config),
_segmentCache, config.streamingRetryDelay(), _gates, _telemetryStorage, _telemetrySynchronizer,config);
_syncManager.start();

// DestroyOnShutDown
if (config.destroyOnShutDown()) {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Expand Down Expand Up @@ -313,7 +316,7 @@ private SplitFetcher buildSplitFetcher() throws URISyntaxException {
SplitChangeFetcher splitChangeFetcher = HttpSplitChangeFetcher.create(_httpclient, _rootTarget, _telemetryStorage);
SplitParser splitParser = new SplitParser(_segmentSynchronizationTaskImp, _segmentCache);

return new SplitFetcherImp(splitChangeFetcher, splitParser, _gates, _splitCache, _telemetryStorage);
return new SplitFetcherImp(splitChangeFetcher, splitParser, _splitCache, _telemetryStorage);
}

private ImpressionsManagerImpl buildImpressionsManager(SplitClientConfig config) throws URISyntaxException {
Expand Down
11 changes: 5 additions & 6 deletions client/src/main/java/io/split/client/SplitManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.split.cache.SplitCache;
import io.split.engine.experiments.ParsedSplit;
import io.split.inputValidation.SplitNameValidator;
import io.split.telemetry.domain.enums.MethodEnum;
import io.split.telemetry.storage.TelemetryConfigProducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -43,7 +42,7 @@ public SplitManagerImpl(SplitCache splitCache,

@Override
public List<SplitView> splits() {
if (!_gates.isSDKReadyNow()) { {
if (!_gates.isSDKReady()) { {
_log.warn("splits: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
_telemetryConfigProducer.recordNonReadyUsage();
}}
Expand All @@ -58,7 +57,7 @@ public List<SplitView> splits() {

@Override
public SplitView split(String featureName) {
if (!_gates.isSDKReadyNow()) { {
if (!_gates.isSDKReady()) { {
_log.warn("split: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
_telemetryConfigProducer.recordNonReadyUsage();
}}
Expand All @@ -70,7 +69,7 @@ public SplitView split(String featureName) {

ParsedSplit parsedSplit = _splitCache.get(featureName);
if (parsedSplit == null) {
if (_gates.isSDKReadyNow()) {
if (_gates.isSDKReady()) {
_log.warn("split: you passed \"" + featureName + "\" that does not exist in this environment, " +
"please double check what Splits exist in the web console.");
}
Expand All @@ -82,7 +81,7 @@ public SplitView split(String featureName) {

@Override
public List<String> splitNames() {
if (!_gates.isSDKReadyNow()) { {
if (!_gates.isSDKReady()) { {
_log.warn("splitNames: the SDK is not ready, results may be incorrect. Make sure to wait for SDK readiness before using this method");
_telemetryConfigProducer.recordNonReadyUsage();
}}
Expand All @@ -100,7 +99,7 @@ public void blockUntilReady() throws TimeoutException, InterruptedException {
if (_config.blockUntilReady() <= 0) {
throw new IllegalArgumentException("setBlockUntilReadyTimeout must be positive but in config was: " + _config.blockUntilReady());
}
if (!_gates.isSDKReady(_config.blockUntilReady())) {
if (!_gates.waitUntilInternalReady(_config.blockUntilReady())) {
_telemetryConfigProducer.recordBURTimeout();
throw new TimeoutException("SDK was not ready in " + _config.blockUntilReady()+ " milliseconds");
}
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions client/src/main/java/io/split/client/metrics/DTOMetrics.java

This file was deleted.

Loading