From ab6b840c4739a7f4f9b6a551baa61fb9dd5065eb Mon Sep 17 00:00:00 2001 From: Jason Salaber Date: Wed, 21 Aug 2024 09:34:34 -0400 Subject: [PATCH 1/2] chore: update to use v2 config --- .../java/com/devcycle/sdk/server/common/api/IDevCycleApi.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/devcycle/sdk/server/common/api/IDevCycleApi.java b/src/main/java/com/devcycle/sdk/server/common/api/IDevCycleApi.java index 9e6eb49..bdc2e91 100755 --- a/src/main/java/com/devcycle/sdk/server/common/api/IDevCycleApi.java +++ b/src/main/java/com/devcycle/sdk/server/common/api/IDevCycleApi.java @@ -61,7 +61,7 @@ public interface IDevCycleApi { * @return Call<ProjectConfig> */ @Headers({"Content-Type:application/json"}) - @GET("config/v1/server/{sdkToken}.json") + @GET("config/v2/server/{sdkToken}.json") Call getConfig(@Path("sdkToken") String sdkToken, @Header("If-None-Match") String etag, @Header("If-Modified-Since") String lastModified); /** From d98621978b2fec8bd3b7861b89489d8ac78c14ff Mon Sep 17 00:00:00 2001 From: Jason Salaber Date: Wed, 21 Aug 2024 10:40:13 -0400 Subject: [PATCH 2/2] chore: updated local bucketing --- build.gradle | 2 +- .../devcycle/sdk/server/local/api/DevCycleLocalClient.java | 5 ++++- .../sdk/server/local/bucketing/LocalBucketing.java | 7 ++++--- .../sdk/server/local/managers/EventQueueManager.java | 4 ++-- .../com/devcycle/sdk/server/local/LocalBucketingTest.java | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index dec48d3..4ae5fe7 100644 --- a/build.gradle +++ b/build.gradle @@ -112,7 +112,7 @@ sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 def wasmResourcePath = "$projectDir/src/main/resources" -def wasmVersion = "1.21.0" +def wasmVersion = "1.25.3" def wasmUrl = "https://unpkg.com/@devcycle/bucketing-assembly-script@$wasmVersion/build/bucketing-lib.release.wasm" task downloadDVCBucketingWASM(type: Download) { src wasmUrl diff --git a/src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java b/src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java index c69afbc..7900025 100755 --- a/src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java +++ b/src/main/java/com/devcycle/sdk/server/local/api/DevCycleLocalClient.java @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.Map; +import java.util.UUID; public final class DevCycleLocalClient implements IDevCycleClient { @@ -28,12 +29,14 @@ public final class DevCycleLocalClient implements IDevCycleClient { private final LocalBucketing localBucketing = new LocalBucketing(); private final EnvironmentConfigManager configManager; private EventQueueManager eventQueueManager; + private final String clientUUID; public DevCycleLocalClient(String sdkKey) { this(sdkKey, DevCycleLocalOptions.builder().build()); } public DevCycleLocalClient(String sdkKey, DevCycleLocalOptions dvcOptions) { + clientUUID = UUID.randomUUID().toString(); if (sdkKey == null || sdkKey.equals("")) { throw new IllegalArgumentException("Missing SDK key! Call initialize with a valid SDK key"); } @@ -54,7 +57,7 @@ public DevCycleLocalClient(String sdkKey, DevCycleLocalOptions dvcOptions) { configManager = new EnvironmentConfigManager(sdkKey, localBucketing, dvcOptions); this.sdkKey = sdkKey; try { - eventQueueManager = new EventQueueManager(sdkKey, localBucketing, dvcOptions); + eventQueueManager = new EventQueueManager(sdkKey, localBucketing, clientUUID, dvcOptions); } catch (Exception e) { DevCycleLogger.error("Error creating event queue due to error: " + e.getMessage()); } diff --git a/src/main/java/com/devcycle/sdk/server/local/bucketing/LocalBucketing.java b/src/main/java/com/devcycle/sdk/server/local/bucketing/LocalBucketing.java index 69b133d..ff97a7b 100644 --- a/src/main/java/com/devcycle/sdk/server/local/bucketing/LocalBucketing.java +++ b/src/main/java/com/devcycle/sdk/server/local/bucketing/LocalBucketing.java @@ -260,14 +260,15 @@ public synchronized byte[] getVariableForUserProtobuf(byte[] serializedParams) { return varBytes; } - public synchronized void initEventQueue(String sdkKey, String options) { + public synchronized void initEventQueue(String sdkKey, String clientUUID, String options) { unpinAll(); int sdkKeyAddress = getSDKKeyAddress(sdkKey); + int clientUUIDAddress = newWasmString(clientUUID); int optionsAddress = newWasmString(options); Func initEventQueuePtr = linker.get(store, "", "initEventQueue").get().func(); - WasmFunctions.Consumer2 fn = WasmFunctions.consumer(store, initEventQueuePtr, I32, I32); - fn.accept(sdkKeyAddress, optionsAddress); + WasmFunctions.Consumer3 fn = WasmFunctions.consumer(store, initEventQueuePtr, I32, I32, I32); + fn.accept(sdkKeyAddress, clientUUIDAddress, optionsAddress); } public synchronized void queueEvent(String sdkKey, String user, String event) { diff --git a/src/main/java/com/devcycle/sdk/server/local/managers/EventQueueManager.java b/src/main/java/com/devcycle/sdk/server/local/managers/EventQueueManager.java index cc895a2..a26440b 100644 --- a/src/main/java/com/devcycle/sdk/server/local/managers/EventQueueManager.java +++ b/src/main/java/com/devcycle/sdk/server/local/managers/EventQueueManager.java @@ -34,7 +34,7 @@ public class EventQueueManager { private final int flushEventQueueSize; private final int maxEventQueueSize; - public EventQueueManager(String sdkKey, LocalBucketing localBucketing, DevCycleLocalOptions options) throws Exception { + public EventQueueManager(String sdkKey, LocalBucketing localBucketing, String clientUUID, DevCycleLocalOptions options) throws Exception { this.localBucketing = localBucketing; this.sdkKey = sdkKey; eventFlushIntervalMS = options.getEventFlushIntervalMS(); @@ -45,7 +45,7 @@ public EventQueueManager(String sdkKey, LocalBucketing localBucketing, DevCycleL OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); - this.localBucketing.initEventQueue(sdkKey, OBJECT_MAPPER.writeValueAsString(options)); + this.localBucketing.initEventQueue(sdkKey, clientUUID, OBJECT_MAPPER.writeValueAsString(options)); setupScheduler(); } diff --git a/src/test/java/com/devcycle/sdk/server/local/LocalBucketingTest.java b/src/test/java/com/devcycle/sdk/server/local/LocalBucketingTest.java index 6ce5f70..25ad3f4 100644 --- a/src/test/java/com/devcycle/sdk/server/local/LocalBucketingTest.java +++ b/src/test/java/com/devcycle/sdk/server/local/LocalBucketingTest.java @@ -75,7 +75,7 @@ public void testStoreConfig() { public void testEventQueue() throws JsonProcessingException { DevCycleEvent event = DevCycleEvent.builder().type("test").target("target").build(); - localBucketing.initEventQueue(apiKey, "{}"); + localBucketing.initEventQueue(apiKey, UUID.randomUUID().toString(),"{}"); // Add 2 events, aggregated by same target (should create 1 event with eventCount 2) localBucketing.queueEvent(apiKey, mapper.writeValueAsString(getUser()), mapper.writeValueAsString(event));