Skip to content
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

chore: update to use v2 config #161

Merged
merged 2 commits into from
Aug 22, 2024
Merged
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 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(),"{}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need to track this client uuid attaching it to the localbucketing instance - as it's used later for sdkConfig events

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather get that done in the same pr as the sdkConfig if it hasn't been done already

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it has - just an fyi


// 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
Loading