Skip to content

Commit

Permalink
chore: update to use v2 config (#161)
Browse files Browse the repository at this point in the history
* chore: update to use v2 config

* chore: updated local bucketing
  • Loading branch information
jsalaber authored Aug 22, 2024
1 parent 6922acb commit e7e3e7c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 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 @@ -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<ProjectConfig> getConfig(@Path("sdkToken") String sdkToken, @Header("If-None-Match") String etag, @Header("If-Modified-Since") String lastModified);

/**
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 e7e3e7c

Please sign in to comment.