Skip to content

General polishing #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Splitio.Redis/Splitio.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>7.11.0</Version>
<Version>7.11.1</Version>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>SplitioRedis.snk</AssemblyOriginatorKeyFile>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ image:
nuget:
account_feed: true

version: 7.11.0
version: 7.11.1-rc.{build}
dotnet_csproj:
patch: true
file: '**\*.csproj'
Expand Down
1 change: 1 addition & 0 deletions src/Splitio/Constants/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static class Gral
public static int DestroyTimeount => 30000;
public static int IntervalToClearLongTermCache => 3600000;
public static string Control => "control";
public static string SdkVersion => "7.11.1";
}

public static class Urls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Splitio.Services.Cache.Classes
{
public class InMemoryRuleBasedSegmentCache : IRuleBasedSegmentCache
{
{
private readonly ConcurrentDictionary<string, RuleBasedSegment> _cache;
private long _changeNumber;

Expand Down
12 changes: 5 additions & 7 deletions src/Splitio/Services/Cache/Classes/InMemorySplitCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ public void Update(List<ParsedSplit> toAdd, List<string> toRemove, long till)

foreach (var featureFlagName in toRemove)
{
if (!_featureFlags.TryGetValue(featureFlagName, out ParsedSplit cached))
continue;

_featureFlags.TryRemove(featureFlagName, out ParsedSplit removedSplit);

DecreaseTrafficTypeCount(removedSplit);
RemoveFromFlagSets(removedSplit.name, removedSplit.Sets);
if (_featureFlags.TryRemove(featureFlagName, out ParsedSplit removedSplit))
{
DecreaseTrafficTypeCount(removedSplit);
RemoveFromFlagSets(removedSplit.name, removedSplit.Sets);
}
}

SetChangeNumber(till);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ public async Task<string> FetchSegmentChangesAsync(string name, long since, Fetc

private string GetRequestUri(string name, long since, long? till = null)
{
var uri = $"{_baseUrl}/api/segmentChanges/{name}?since={Uri.EscapeDataString(since.ToString())}";
var uri = $"{_baseUrl}/api/segmentChanges/{name}?since={since}";

if (till.HasValue)
return $"{uri}&till={Uri.EscapeDataString(till.Value.ToString())}";
uri = $"{uri}&till={till.Value}";

return uri;
}
Expand Down
19 changes: 14 additions & 5 deletions src/Splitio/Services/Shared/Classes/WrapperAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public SdkMetadata BuildSdkMetadata(ConfigurationOptions config, ISplitLogger lo
var ipAddressesEnabled = config.IPAddressesEnabled ?? true;

#if NET_LATEST
metadata.Version = ".NET_CORE-" + SplitSdkVersion();
metadata.Version = ".NET_CORE-" + SplitSdkVersion(log);
#else
metadata.Version = ".NET-" + SplitSdkVersion();
metadata.Version = ".NET-" + SplitSdkVersion(log);
#endif
metadata.MachineName = GetSdkMachineName(config, ipAddressesEnabled, log);
metadata.MachineIP = GetSdkMachineIP(config, ipAddressesEnabled, log);
Expand All @@ -59,13 +59,22 @@ public Task<Task> WhenAnyAsync(params Task[] tasks)
return Task.WhenAny(tasks);
}

private static string SplitSdkVersion()
private static string SplitSdkVersion(ISplitLogger log)
{
try
{
#if NET_LATEST
return typeof(Split).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
return typeof(Split).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
#else
return FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
return FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
#endif
}
catch (Exception ex)
{
log.Warn("Exception retrieving sdk version", ex);
}

return Constants.Gral.SdkVersion;
}

public void SetCustomerLogger(ISplitLogger splitLogger)
Expand Down
16 changes: 9 additions & 7 deletions src/Splitio/Services/SplitFetcher/Classes/SplitSdkApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ public async Task<ApiFetchResult> FetchSplitChangesAsync(FetchOptions fetchOptio
var result = new ApiFetchResult
{
Success = true,
ClearCache = _lastProxyCheckTimestamp != null,
Spec = _flagSpec,
Content = response.Content
};

_lastProxyCheckTimestamp = null;
if (_flagSpec != ApiVersions.Spec1_1)
{
result.ClearCache = _lastProxyCheckTimestamp != null;
_lastProxyCheckTimestamp = null;
}

return result;
}
Expand All @@ -84,6 +87,7 @@ public async Task<ApiFetchResult> FetchSplitChangesAsync(FetchOptions fetchOptio
{
_flagSpec = ApiVersions.Spec1_1;
_lastProxyCheckTimestamp = CurrentTimeHelper.CurrentTimeMillis();
_log.Debug($"FetchSplitChange BadRequest: {requestUri}");
_log.Warn($"Detected proxy without support for Feature flags spec {ApiVersions.LatestFlagsSpec} version, will switch to spec version {_flagSpec}");

return await FetchSplitChangesAsync(fetchOptions);
Expand All @@ -109,20 +113,18 @@ public async Task<ApiFetchResult> FetchSplitChangesAsync(FetchOptions fetchOptio

private string GetRequestUri(long since, long rbSinceTarget, long? till)
{
var ffSince = Uri.EscapeDataString(since.ToString());
var uri = $"{_baseUrl}/api/splitChanges?s={_flagSpec}&since={ffSince}";
var uri = $"{_baseUrl}/api/splitChanges?s={_flagSpec}&since={since}";

if (_flagSpec.Equals(ApiVersions.LatestFlagsSpec))
{
var rbSince = Uri.EscapeDataString(rbSinceTarget.ToString());
uri = $"{uri}&rbSince={rbSince}";
uri = $"{uri}&rbSince={rbSinceTarget}";
}

if (!string.IsNullOrEmpty(_flagSets))
uri = $"{uri}&sets={_flagSets}";

if (till.HasValue)
uri = $"{uri}&till={Uri.EscapeDataString(till.Value.ToString())}";
uri = $"{uri}&till={till.Value}";

return uri;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Splitio/Splitio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>7.11.0</Version>
<Version>7.11.1</Version>
<RootNamespace>Splitio</RootNamespace>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>Splitio.snk</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Splitio.Services.SplitFetcher.Classes;
using Splitio.Telemetry.Storages;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace Splitio_Tests.Unit_Tests.SplitFetcher
Expand Down Expand Up @@ -238,11 +240,12 @@ public async Task FetchSplitChangesAsync_SwitchFlagSpecAndBack_Ok()
// Arrange.
var baseUrl = "https://app.split-testing.io";
var flagSetsFilter = new FlagSetsFilter(new HashSet<string>());
var splitSdkApiClient = new SplitSdkApiClient(_httpClient.Object, _telemetryRuntimeProducer.Object, baseUrl, flagSetsFilter, true, 0);
var expectedUrl = $"{baseUrl}/api/splitChanges?s=1.3&since=-1&rbSince=-1";
var splitSdkApiClient = new SplitSdkApiClient(_httpClient.Object, _telemetryRuntimeProducer.Object, baseUrl, flagSetsFilter, true, 100);
var expectedUrl1_3 = $"{baseUrl}/api/splitChanges?s=1.3&since=-1&rbSince=-1";
var expectedUrl1_1 = $"{baseUrl}/api/splitChanges?s=1.1&since=-1";

_httpClient
.SetupSequence(mock => mock.GetAsync(expectedUrl, false))
.SetupSequence(mock => mock.GetAsync(expectedUrl1_3, false))
.ReturnsAsync(new HTTPResult
{
StatusCode = System.Net.HttpStatusCode.BadRequest,
Expand All @@ -256,17 +259,39 @@ public async Task FetchSplitChangesAsync_SwitchFlagSpecAndBack_Ok()
IsSuccessStatusCode = true
});

// Act.
_httpClient
.Setup(mock => mock.GetAsync(expectedUrl1_1, false))
.ReturnsAsync(new HTTPResult
{
StatusCode = System.Net.HttpStatusCode.OK,
Content = "ok",
IsSuccessStatusCode = true
});

// Act and Assert.
var result = await splitSdkApiClient.FetchSplitChangesAsync(new FetchOptions
{
FeatureFlagsSince = -1,
RuleBasedSegmentsSince = -1
});

// Assert.
Assert.AreEqual("ok", result.Content);
Assert.IsTrue(result.Success);
_httpClient.Verify(mock => mock.GetAsync(expectedUrl, false), Times.Exactly(2));
_httpClient.Verify(mock => mock.GetAsync(expectedUrl1_1, false), Times.Once);
_httpClient.Verify(mock => mock.GetAsync(expectedUrl1_3, false), Times.Once);


Thread.Sleep(150);
result = await splitSdkApiClient.FetchSplitChangesAsync(new FetchOptions
{
FeatureFlagsSince = -1,
RuleBasedSegmentsSince = -1
});

Assert.AreEqual("ok", result.Content);
Assert.IsTrue(result.Success);
_httpClient.Verify(mock => mock.GetAsync(expectedUrl1_1, false), Times.Once);
_httpClient.Verify(mock => mock.GetAsync(expectedUrl1_3, false), Times.Exactly(2));
}
}
}