Skip to content
Open
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
4 changes: 3 additions & 1 deletion Splitio.Redis/Services/Client/Classes/RedisClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Splitio.Redis.Telemetry.Storages;
using Splitio.Services.Cache.Interfaces;
using Splitio.Services.Client.Classes;
using Splitio.Services.Common;
using Splitio.Services.EngineEvaluator;
using Splitio.Services.Evaluator;
using Splitio.Services.Impressions.Classes;
Expand All @@ -30,7 +31,8 @@ public class RedisClient : SplitClient
private IFeatureFlagCacheConsumer _featureFlagCacheConsumer;
private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator;

public RedisClient(ConfigurationOptions config, string apiKey, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(apiKey, fallbackTreatmentCalculator)
public RedisClient(ConfigurationOptions config, string apiKey, FallbackTreatmentCalculator fallbackTreatmentCalculator,
EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager)
{
_config = new RedisConfig();
_fallbackTreatmentCalculator = fallbackTreatmentCalculator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Splitio.Services.Cache.Interfaces;
using Splitio.Domain;
using Splitio.Services.Cache.Interfaces;
using Splitio.Services.Common;
using System.Collections.Generic;
using System.Threading;

namespace Splitio.Services.Client.Classes
Expand All @@ -7,6 +10,12 @@ public class InMemoryReadinessGatesCache : IStatusManager
{
private readonly CountdownEvent _sdkReady = new CountdownEvent(1);
private readonly CountdownEvent _sdkDestroyed = new CountdownEvent(1);
private readonly EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> _eventsManager;

public InMemoryReadinessGatesCache(EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager)
{
_eventsManager = eventsManager;
}

public bool IsReady()
{
Expand All @@ -21,6 +30,10 @@ public bool WaitUntilReady(int milliseconds)
public void SetReady()
{
_sdkReady.Signal();
_eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady,
new EventMetadata(new Dictionary<string, object>()),
Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady,
_eventsManager));
}

public void SetDestroy()
Expand Down
4 changes: 2 additions & 2 deletions src/Splitio/Services/Client/Classes/JSONFileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class JSONFileClient : SplitClient
public JSONFileClient(string splitsFilePath,
string segmentsFilePath,
FallbackTreatmentCalculator fallbackTreatmentCalculator,
EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager,
ISegmentCache segmentCacheInstance = null,
IFeatureFlagCache featureFlagCacheInstance = null,
IImpressionsLog impressionsLog = null,
Expand All @@ -33,9 +34,8 @@ public JSONFileClient(string splitsFilePath,
ITrafficTypeValidator trafficTypeValidator = null,
IImpressionsManager impressionsManager = null,
IRuleBasedSegmentCache ruleBasedSegmentCache = null
) : base("localhost", fallbackTreatmentCalculator)
) : base("localhost", fallbackTreatmentCalculator, eventsManager)
{
var eventsManager = new EventsManager<SdkEvent, SdkInternalEvent, EventMetadata>(new EventsManagerConfig());
_segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary<string, Segment>(), eventsManager);
var rbsCache = ruleBasedSegmentCache ?? new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary<string, RuleBasedSegment>(), eventsManager);

Expand Down
4 changes: 2 additions & 2 deletions src/Splitio/Services/Client/Classes/LocalhostClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class LocalhostClient : SplitClient

private readonly object _lock = new object();

public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base("localhost", fallbackTreatmentCalculator)
public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatmentCalculator fallbackTreatmentCalculator,
EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager) : base("localhost", fallbackTreatmentCalculator, eventsManager)
{
var configs = (LocalhostClientConfigurations)_configService.ReadConfig(configurationOptions, ConfigTypes.Localhost, _statusManager);

Expand All @@ -47,7 +48,6 @@ public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatm

BuildFlagSetsFilter(new HashSet<string>());

var eventsManager = new EventsManager<SdkEvent, SdkInternalEvent, EventMetadata>(new EventsManagerConfig());
var splits = _localhostFileService.ParseSplitFile(_fullPath);
_featureFlagCache = new InMemorySplitCache(splits, _flagSetsFilter, eventsManager);

Expand Down
13 changes: 5 additions & 8 deletions src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ public class SelfRefreshingClient : SplitClient
private IRuleBasedSegmentCache _ruleBasedSegmentCache;
private IUpdater<RuleBasedSegmentDto> _ruleBasedSegmentUpdater;
private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator;
private EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> _eventsManager;
private readonly EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> _eventsManager;

public SelfRefreshingClient(string apiKey, ConfigurationOptions config,
FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(apiKey, fallbackTreatmentCalculator)
FallbackTreatmentCalculator fallbackTreatmentCalculator,
EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager)
{
_config = (SelfRefreshingConfig)_configService.ReadConfig(config, ConfigTypes.InMemory);
_fallbackTreatmentCalculator = fallbackTreatmentCalculator;
_eventsManager = eventsManager;

BuildFlagSetsFilter(_config.FlagSetsFilter);
BuildEventsManager();
BuildSplitCache();
BuildSegmentCache();
BuildRuleBasedSegmentCache();
Expand Down Expand Up @@ -90,10 +91,6 @@ public SelfRefreshingClient(string apiKey, ConfigurationOptions config,
}

#region Private Methods
private void BuildEventsManager()
{
_eventsManager = new EventsManager<SdkEvent, SdkInternalEvent, EventMetadata>(new EventsManagerConfig());
}
private void BuildSplitCache()
{
_featureFlagCache = new InMemorySplitCache(new ConcurrentDictionary<string, ParsedSplit>(_config.ConcurrencyLevel, InitialCapacity), _flagSetsFilter, _eventsManager);
Expand Down Expand Up @@ -218,7 +215,7 @@ private void BuildManager()

private void BuildBlockUntilReadyService()
{
_blockUntilReadyService = new SelfRefreshingBlockUntilReadyService(_statusManager, _telemetryInitProducer);
_blockUntilReadyService = new SelfRefreshingBlockUntilReadyService(_statusManager, _telemetryInitProducer, _eventsManager);
}

private void BuildTelemetrySyncTask()
Expand Down
6 changes: 4 additions & 2 deletions src/Splitio/Services/Client/Classes/SplitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ public abstract class SplitClient : ISplitClient
protected IClientExtensionService _clientExtensionService;
protected IFlagSetsFilter _flagSetsFilter;

protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator)
protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator,
EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager)
{
ApiKey = apikey;
Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager);

_fallbackTreatmentCalculator = fallbackTreatmentCalculator;
_wrapperAdapter = WrapperAdapter.Instance();
Expand All @@ -77,7 +79,7 @@ protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatme
_factoryInstantiationsService = FactoryInstantiationsService.Instance();
_flagSetsValidator = new FlagSetsValidator();
_configService = new ConfigService(_wrapperAdapter, _flagSetsValidator, new SdkMetadataValidator());
_statusManager = new InMemoryReadinessGatesCache();
_statusManager = new InMemoryReadinessGatesCache(eventsManager);
_tasksManager = new TasksManager(_statusManager);
}

Expand Down
9 changes: 6 additions & 3 deletions src/Splitio/Services/Client/Classes/SplitFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Splitio.Domain;
using Splitio.Services.Client.Interfaces;
using Splitio.Services.Common;
using Splitio.Services.Impressions.Classes;
using Splitio.Services.InputValidation.Classes;
using Splitio.Services.InputValidation.Interfaces;
Expand Down Expand Up @@ -59,18 +60,20 @@ public ISplitManager Manager()
private void BuildSplitClient()
{
FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(_options.FallbackTreatments);
EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager = new EventsManager<SdkEvent, SdkInternalEvent, EventMetadata>(new EventsManagerConfig());

switch (_options.Mode)
{
case Mode.Standalone:
_apiKeyValidator.Validate(_apiKey);

if (_apiKey == "localhost")
{
_client = new LocalhostClient(_options, fallbackTreatmentCalculator);
_client = new LocalhostClient(_options, fallbackTreatmentCalculator, eventsManager);
}
else
{
_client = new SelfRefreshingClient(_apiKey, _options, fallbackTreatmentCalculator);
_client = new SelfRefreshingClient(_apiKey, _options, fallbackTreatmentCalculator, eventsManager);
}
break;
case Mode.Consumer:
Expand All @@ -81,7 +84,7 @@ private void BuildSplitClient()
var redisAssembly = Assembly.Load(new AssemblyName("Splitio.Redis"));
var redisType = redisAssembly.GetType("Splitio.Redis.Services.Client.Classes.RedisClient");

_client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, fallbackTreatmentCalculator });
_client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, fallbackTreatmentCalculator, eventsManager });
}
catch (ArgumentException ex)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Splitio.Services.Cache.Interfaces;
using Splitio.Domain;
using Splitio.Services.Cache.Interfaces;
using Splitio.Services.Common;
using Splitio.Services.Logger;
using Splitio.Services.Shared.Interfaces;
using Splitio.Telemetry.Storages;
using System;
using System.Collections.Generic;

namespace Splitio.Services.Shared.Classes
{
Expand All @@ -12,11 +15,14 @@ public class SelfRefreshingBlockUntilReadyService : IBlockUntilReadyService

private readonly IStatusManager _statusManager;
private readonly ITelemetryInitProducer _telemetryInitProducer;
private readonly EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> _eventsManager;

public SelfRefreshingBlockUntilReadyService(IStatusManager statusManager, ITelemetryInitProducer telemetryInitProducer)
public SelfRefreshingBlockUntilReadyService(IStatusManager statusManager, ITelemetryInitProducer telemetryInitProducer,
EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> eventsManager)
{
_statusManager = statusManager;
_telemetryInitProducer = telemetryInitProducer;
_eventsManager = eventsManager;
}

public void BlockUntilReady(int blockMilisecondsUntilReady)
Expand All @@ -30,6 +36,10 @@ public void BlockUntilReady(int blockMilisecondsUntilReady)

if (!_statusManager.WaitUntilReady(blockMilisecondsUntilReady))
{
_eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut,
new EventMetadata(new Dictionary<string, object>()),
Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkTimedOut,
_eventsManager));
_telemetryInitProducer.RecordBURTimeout();
throw new TimeoutException($"SDK was not ready in {blockMilisecondsUntilReady} milliseconds");
}
Expand Down
31 changes: 17 additions & 14 deletions tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Splitio.Domain;
using Splitio.Redis.Services.Client.Classes;
using Splitio.Services.Client.Classes;
using Splitio.Services.Common;
using Splitio.Services.Impressions.Classes;
using Splitio.Telemetry.Domain;
using System;
Expand All @@ -24,13 +25,15 @@ public abstract class BaseLocalhostClientTests
private readonly string rootFilePath;
private readonly string _mode;
private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator;
private readonly EventsManager<SdkEvent, SdkInternalEvent, EventMetadata> _eventsManager;

public BaseLocalhostClientTests(string mode)
{
// This line is to clean the warnings.
rootFilePath = string.Empty;
_mode = mode;
_fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration());
_eventsManager = new EventsManager<SdkEvent, SdkInternalEvent, EventMetadata>(new EventsManagerConfig());

#if NET_LATEST
rootFilePath = @"Resources\";
Expand All @@ -42,7 +45,7 @@ public async Task GetTreatmentAsync()
{
// Arrange.
var config = GetConfiguration($"{rootFilePath}test.splits");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -81,7 +84,7 @@ public void GetTreatmentSuccessfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}test.splits");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand All @@ -105,7 +108,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFile()
// Arrange
var filePath = $"{rootFilePath}test2-{_mode}.splits";
var config = GetConfiguration(filePath);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -148,7 +151,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFileSameFile()
Thread.Sleep(1000);

var config = GetConfiguration(filePath);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand All @@ -171,7 +174,7 @@ public void ClientDestroySuccessfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}test.splits");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand All @@ -193,7 +196,7 @@ public void GetTreatment_WhenIsYamlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -225,7 +228,7 @@ public void GetTreatmentWithConfig_WhenIsYamlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -264,7 +267,7 @@ public void GetTreatment_WhenIsYmlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -296,7 +299,7 @@ public void GetTreatmentWithConfig_WhenIsYmlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -335,7 +338,7 @@ public void GetTreatments_WhenIsYamlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -372,7 +375,7 @@ public void GetTreatmentsWithConfig_WhenIsYamlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -423,7 +426,7 @@ public void GetTreatments_WhenIsYmlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -460,7 +463,7 @@ public void GetTreatmentsWithConfig_WhenIsYmlFile_Successfully()
{
//Arrange
var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, _fallbackTreatmentCalculator);
var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down Expand Up @@ -514,7 +517,7 @@ public void FallbackTreatments_WhenFeatureDoesNotExist()
FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration);

var config = GetConfiguration($"{rootFilePath}split.yml");
var client = new LocalhostClient(config, fallbackTreatmentCalculator);
var client = new LocalhostClient(config, fallbackTreatmentCalculator, _eventsManager);

client.BlockUntilReady(1000);

Expand Down
Loading