Skip to content

Commit c5408f0

Browse files
committed
feat: Enable gzip option for events in server SDK
1 parent ea88101 commit c5408f0

File tree

6 files changed

+33
-11
lines changed

6 files changed

+33
-11
lines changed

lib/sdk/server/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ext.versions = [
7171
"guava": "32.0.1-jre",
7272
"jackson": "2.11.2",
7373
"launchdarklyJavaSdkCommon": "2.1.1",
74-
"launchdarklyJavaSdkInternal": "1.4.0",
74+
"launchdarklyJavaSdkInternal": "1.5.0",
7575
"launchdarklyLogging": "1.1.0",
7676
"okhttp": "4.9.3", // specify this for the SDK build instead of relying on the transitive dependency from okhttp-eventsource
7777
"okhttpEventsource": "4.1.0",

lib/sdk/server/contract-tests/service/src/main/java/sdktest/Representations.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static class SdkConfigEventParams {
4545
boolean allAttributesPrivate;
4646
int capacity;
4747
boolean enableDiagnostics;
48+
boolean enableGzip;
4849
String[] globalPrivateAttributes;
4950
Long flushIntervalMs;
5051
}

lib/sdk/server/contract-tests/service/src/main/java/sdktest/SdkClientEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ private LDConfig buildSdkConfig(SdkConfigParams params, String tag) {
390390
} else {
391391
endpoints.events(params.events.baseUri);
392392
EventProcessorBuilder eb = Components.sendEvents()
393-
.allAttributesPrivate(params.events.allAttributesPrivate);
393+
.allAttributesPrivate(params.events.allAttributesPrivate)
394+
.enableGzipCompression(params.events.enableGzip);
394395
if (params.events.capacity > 0) {
395396
eb.capacity(params.events.capacity);
396397
}

lib/sdk/server/contract-tests/service/src/main/java/sdktest/TestService.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@
2323
public class TestService {
2424
private static final int PORT = 8000;
2525
private static final String[] CAPABILITIES = new String[]{
26-
"server-side",
27-
"strongly-typed",
2826
"all-flags-client-side-only",
2927
"all-flags-details-only-for-tracked-flags",
3028
"all-flags-with-reasons",
29+
"anonymous-redaction",
3130
"big-segments",
31+
"client-prereq-events",
3232
"context-type",
33-
"service-endpoints",
34-
"tags",
35-
"filtering",
36-
"migrations",
33+
"evaluation-hooks",
34+
"event-gzip",
3735
"event-sampling",
36+
"filtering",
3837
"inline-context-all",
39-
"anonymous-redaction",
40-
"evaluation-hooks",
41-
"client-prereq-events"
38+
"migrations",
39+
"optional-event-gzip",
40+
"server-side",
41+
"service-endpoints",
42+
"strongly-typed",
43+
"tags",
4244
};
4345

4446
static final Gson gson = new GsonBuilder().serializeNulls().create();

lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/ComponentsImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public EventProcessor build(ClientContext context) {
222222
null, // use default request path for server-side events
223223
null, // use default request path for client-side events
224224
0, // 0 means default retry delay
225+
enableGzipCompression,
225226
context.getBaseLogger().subLogger(Loggers.EVENTS_LOGGER_NAME));
226227
} else {
227228
eventSender = new EventSenderWrapper(eventSenderConfigurer.build(context));

lib/sdk/server/src/main/java/com/launchdarkly/sdk/server/integrations/EventProcessorBuilder.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public abstract class EventProcessorBuilder implements ComponentConfigurer<Event
6666
protected int userKeysCapacity = DEFAULT_USER_KEYS_CAPACITY;
6767
protected Duration userKeysFlushInterval = DEFAULT_USER_KEYS_FLUSH_INTERVAL;
6868
protected ComponentConfigurer<EventSender> eventSenderConfigurer = null;
69+
protected boolean enableGzipCompression = false;
6970

7071
/**
7172
* Sets whether or not all optional user attributes should be hidden from LaunchDarkly.
@@ -211,4 +212,20 @@ public EventProcessorBuilder userKeysFlushInterval(Duration userKeysFlushInterva
211212
this.userKeysFlushInterval = userKeysFlushInterval == null ? DEFAULT_USER_KEYS_FLUSH_INTERVAL : userKeysFlushInterval;
212213
return this;
213214
}
215+
216+
/**
217+
* Enables gzip compression for event payloads.
218+
* <p>
219+
* When enabled, event payloads will be compressed using gzip before being sent to LaunchDarkly.
220+
* This can significantly reduce bandwidth usage when sending large event payloads.
221+
* <p>
222+
* The default value is false.
223+
*
224+
* @param enableGzipCompression whether to enable gzip compression
225+
* @return the builder
226+
*/
227+
public EventProcessorBuilder enableGzipCompression(boolean enableGzipCompression) {
228+
this.enableGzipCompression = enableGzipCompression;
229+
return this;
230+
}
214231
}

0 commit comments

Comments
 (0)