Skip to content

Commit

Permalink
chore: updated local bucketing
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalaber committed Aug 21, 2024
1 parent ab6b840 commit d986219
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Collections;
import java.util.Map;
import java.util.UUID;

public final class DevCycleLocalClient implements IDevCycleClient {

Expand All @@ -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");
}
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer, Integer> fn = WasmFunctions.consumer(store, initEventQueuePtr, I32, I32);
fn.accept(sdkKeyAddress, optionsAddress);
WasmFunctions.Consumer3<Integer, Integer, Integer> fn = WasmFunctions.consumer(store, initEventQueuePtr, I32, I32, I32);
fn.accept(sdkKeyAddress, clientUUIDAddress, optionsAddress);
}

public synchronized void queueEvent(String sdkKey, String user, String event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit d986219

Please sign in to comment.