diff --git a/dotnet-statsig-tests/Common/StatsigTest.cs b/dotnet-statsig-tests/Common/StatsigTest.cs index 24ea8f1..7b94e76 100644 --- a/dotnet-statsig-tests/Common/StatsigTest.cs +++ b/dotnet-statsig-tests/Common/StatsigTest.cs @@ -202,7 +202,7 @@ public async void TestServerInitialize() { _server.ResetLogEntries(); _server.Given( - Request.Create().WithPath("/v1/download_config_specs").UsingPost() + Request.Create().WithPath("/v1/download_config_specs/secret-fake-key.json").UsingGet() ).RespondWith( Response.Create().WithStatusCode(200).WithBodyAsJson( new Dictionary @@ -307,19 +307,11 @@ await StatsigServer.Initialize var requestBody = _server.LogEntries.ElementAt(0).RequestMessage.Body; var requestHeaders = _server.LogEntries.ElementAt(0).RequestMessage.Headers; - var requestDict = JObject.Parse(requestBody); - - JToken m; - requestDict.TryGetValue("statsigMetadata", out m); - var metadata = m.ToObject>(); Assert.True(requestHeaders["STATSIG-API-KEY"].ToString().Equals("secret-fake-key")); Assert.True(requestHeaders["STATSIG-SDK-VERSION"].ToString().Equals(ExpectedSdkVersion)); Assert.True(requestHeaders["STATSIG-SDK-TYPE"].ToString().Equals("dotnet-server")); - Assert.True(metadata["sdkType"].Equals("dotnet-server")); - Assert.True(metadata["sdkVersion"].Equals(ExpectedSdkVersion)); - var gate = await StatsigServer.CheckGate(user, "test_gate"); Assert.True(gate); var exp = await StatsigServer.GetExperiment(user, "test_config"); @@ -340,7 +332,7 @@ await StatsigServer.Initialize // Verify log event requets for exposures and custom logs requestBody = _server.LogEntries.ElementAt(2).RequestMessage.Body; requestHeaders = _server.LogEntries.ElementAt(2).RequestMessage.Headers; - requestDict = JObject.Parse(requestBody); + var requestDict = JObject.Parse(requestBody); Assert.True(requestHeaders["STATSIG-API-KEY"].ToString().Equals("secret-fake-key")); diff --git a/dotnet-statsig-tests/Server/ConcurrencyTest.cs b/dotnet-statsig-tests/Server/ConcurrencyTest.cs index d6d6923..4f084f7 100644 --- a/dotnet-statsig-tests/Server/ConcurrencyTest.cs +++ b/dotnet-statsig-tests/Server/ConcurrencyTest.cs @@ -28,7 +28,7 @@ Task IAsyncLifetime.InitializeAsync() _baseURL = _server.Urls[0]; _server.ResetLogEntries(); _server.Given( - Request.Create().WithPath("/v1/download_config_specs").UsingPost() + Request.Create().WithPath("/v1/download_config_specs/secret-server-key.json").UsingGet() ).RespondWith(this); _server.Given( Request.Create().WithPath("/v1/log_event").UsingPost() @@ -142,7 +142,7 @@ private async Task RunChecks(int taskId, int delay, int times) Assert.True(await StatsigServer.CheckGate(user, "always_on_gate")); // check id list gate for a user that should be in the id list - Assert.True(await StatsigServer.CheckGate(new StatsigUser { UserID = "regular_user_id", customIDs = {{"unique_id", $"{i}_{taskId}"}}}, "on_for_id_list")); + Assert.True(await StatsigServer.CheckGate(new StatsigUser { UserID = "regular_user_id", customIDs = { { "unique_id", $"{i}_{taskId}" } } }, "on_for_id_list")); StatsigServer.LogEvent(user, "test_event_2", 1, new Dictionary() { { "Key", "Value" } }); diff --git a/dotnet-statsig-tests/Server/DedupeTest.cs b/dotnet-statsig-tests/Server/DedupeTest.cs index 9bafb6e..7286a36 100644 --- a/dotnet-statsig-tests/Server/DedupeTest.cs +++ b/dotnet-statsig-tests/Server/DedupeTest.cs @@ -18,7 +18,7 @@ public class DedupeTest : IAsyncLifetime, IResponseProvider private const int NUM_EVENTS = 8; private const int NUM_LOOOPS = 20; private const int NUM_THREADS = 10; - + private WireMockServer _server; private string _baseUrl; private int _flushedEventCount; @@ -32,7 +32,7 @@ Task IAsyncLifetime.InitializeAsync() _baseUrl = _server.Urls[0]; _server.ResetLogEntries(); _server.Given( - Request.Create().WithPath("/v1/download_config_specs").UsingPost() + Request.Create().WithPath("/v1/download_config_specs/secret-server-key.json").UsingGet() ).RespondWith(this); _server.Given( Request.Create().WithPath("/v1/log_event").UsingPost() diff --git a/dotnet-statsig-tests/Server/GetFeatureGateTest.cs b/dotnet-statsig-tests/Server/GetFeatureGateTest.cs index 63e5deb..ccb8aef 100644 --- a/dotnet-statsig-tests/Server/GetFeatureGateTest.cs +++ b/dotnet-statsig-tests/Server/GetFeatureGateTest.cs @@ -30,7 +30,7 @@ Task IAsyncLifetime.InitializeAsync() baseURL = _server.Urls[0]; _server.ResetLogEntries(); _server.Given( - Request.Create().WithPath("/v1/download_config_specs").UsingPost() + Request.Create().WithPath("/v1/download_config_specs/secret-server-key.json").UsingGet() ).RespondWith(this); _server.Given( Request.Create().WithPath("/v1/log_event").UsingPost() diff --git a/dotnet-statsig-tests/Server/GetListsTest.cs b/dotnet-statsig-tests/Server/GetListsTest.cs index ecb8b8e..2cf13ff 100644 --- a/dotnet-statsig-tests/Server/GetListsTest.cs +++ b/dotnet-statsig-tests/Server/GetListsTest.cs @@ -26,7 +26,7 @@ public async Task InitializeAsync() _server = WireMockServer.Start(); _server.ResetLogEntries(); _server.Given(Request.Create() - .WithPath("/v1/download_config_specs").UsingPost() + .WithPath("/v1/download_config_specs/secret-key.json").UsingGet() ).RespondWith(Response.Create() .WithStatusCode(200) .WithBody(SpecStoreResponseData.downloadConfigSpecResponse) diff --git a/dotnet-statsig-tests/Server/LayerExposureTest.cs b/dotnet-statsig-tests/Server/LayerExposureTest.cs index 0239f73..74a920b 100644 --- a/dotnet-statsig-tests/Server/LayerExposureTest.cs +++ b/dotnet-statsig-tests/Server/LayerExposureTest.cs @@ -31,7 +31,7 @@ Task IAsyncLifetime.InitializeAsync() _server = WireMockServer.Start(); _server.ResetLogEntries(); _server.Given( - Request.Create().WithPath("/v1/download_config_specs").UsingPost() + Request.Create().WithPath("/v1/download_config_specs/secret-server-key.json").UsingGet() ).RespondWith(this); _server.Given( Request.Create().WithPath("/v1/log_event").UsingPost() diff --git a/dotnet-statsig/src/Statsig/Network/RequestDispatcher.cs b/dotnet-statsig/src/Statsig/Network/RequestDispatcher.cs index 746fd45..a7b014e 100644 --- a/dotnet-statsig/src/Statsig/Network/RequestDispatcher.cs +++ b/dotnet-statsig/src/Statsig/Network/RequestDispatcher.cs @@ -61,7 +61,7 @@ string sessionID int timeoutInMs = 0, IReadOnlyDictionary? additionalHeaders = null) { - var (result, status) = await FetchAsString(endpoint, body, retries, backoff, timeoutInMs, additionalHeaders).ConfigureAwait(false); + var (result, status) = await FetchAsString(endpoint, body, 0, retries, backoff, timeoutInMs, additionalHeaders).ConfigureAwait(false); return JsonConvert.DeserializeObject>(result ?? ""); } @@ -74,7 +74,7 @@ public async Task FetchStatus( IReadOnlyDictionary? additionalHeaders = null, bool zipped = false) { - var (result, status) = await FetchAsString(endpoint, body, retries, backoff, timeoutInMs, additionalHeaders, zipped).ConfigureAwait(false); + var (result, status) = await FetchAsString(endpoint, body, 0, retries, backoff, timeoutInMs, additionalHeaders, zipped).ConfigureAwait(false); return status; } @@ -109,6 +109,7 @@ public static void CopyTo(Stream src, Stream dest) public async Task<(string?, InitializeResult)> FetchAsString( string endpoint, string body, + long sinceTime = 0, int retries = 0, int backoff = 1, int timeoutInMs = 0, @@ -125,13 +126,13 @@ public static void CopyTo(Stream src, Stream dest) var url = ApiBaseUrl.EndsWith("/") ? ApiBaseUrl + endpoint : ApiBaseUrl + "/" + endpoint; if (endpoint.Equals("download_config_specs")) { - url = CDNBaseUrl.EndsWith("/") ? CDNBaseUrl + endpoint : CDNBaseUrl + "/" + endpoint; + url = (CDNBaseUrl.EndsWith("/") ? CDNBaseUrl + endpoint : CDNBaseUrl + "/" + endpoint) + "/" + Key + ".json?sinceTime=" + sinceTime; } var client = new HttpClient(new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip }); - using var request = new HttpRequestMessage(HttpMethod.Post, url); + using var request = new HttpRequestMessage(endpoint.Equals("download_config_specs") ? HttpMethod.Get : HttpMethod.Post, url); if (zipped) { var zippedBody = Zip(body); @@ -139,7 +140,7 @@ public static void CopyTo(Stream src, Stream dest) request.Content.Headers.Add("Content-Encoding", "gzip"); request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); } - else + else if (!string.IsNullOrWhiteSpace(body)) { request.Content = new StringContent(body, Encoding.UTF8, "application/json"); } @@ -234,7 +235,7 @@ public static void CopyTo(Stream src, Stream dest) bool zipped = false) { await Task.Delay(backoff * 1000).ConfigureAwait(false); - return await FetchAsString(endpoint, body, retries - 1, backoff * BackoffMultiplier, timeoutInMs, additionalHeaders, zipped).ConfigureAwait(false); + return await FetchAsString(endpoint, body, 0, retries - 1, backoff * BackoffMultiplier, timeoutInMs, additionalHeaders, zipped).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/dotnet-statsig/src/Statsig/Server/Evaluation/SpecStore.cs b/dotnet-statsig/src/Statsig/Server/Evaluation/SpecStore.cs index e849751..caad9fa 100644 --- a/dotnet-statsig/src/Statsig/Server/Evaluation/SpecStore.cs +++ b/dotnet-statsig/src/Statsig/Server/Evaluation/SpecStore.cs @@ -365,11 +365,8 @@ private async Task SyncValuesFromNetwork() { var (response, status) = await _requestDispatcher.FetchAsString( "download_config_specs", - JsonConvert.SerializeObject(new Dictionary - { - ["sinceTime"] = LastSyncTime, - ["statsigMetadata"] = SDKDetails.GetServerSDKDetails().StatsigMetadata - }) + "", + LastSyncTime ).ConfigureAwait(false); var hasUpdates = ParseResponse(response);