Skip to content

feat: Enable gzip support for event payloads #286

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

Merged
merged 1 commit into from
May 2, 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
1 change: 1 addition & 0 deletions contract-tests/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def status():
'secure-mode-hash',
'tags',
'migrations',
'event-gzip',
'event-sampling',
'polling-gzip',
'inline-context',
Expand Down
5 changes: 4 additions & 1 deletion ldclient/impl/events/event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import uuid
import queue
import urllib3
import gzip
from ldclient.config import Config
from datetime import timedelta
from random import Random
Expand Down Expand Up @@ -559,19 +560,21 @@ def _post_events_with_retry(
):
hdrs = _headers(config)
hdrs['Content-Type'] = 'application/json'
hdrs['Content-Encoding'] = 'gzip'
if payload_id:
hdrs['X-LaunchDarkly-Event-Schema'] = str(__CURRENT_EVENT_SCHEMA__)
hdrs['X-LaunchDarkly-Payload-ID'] = payload_id
can_retry = True
context = "posting %s" % events_description
data = gzip.compress(bytes(body, 'utf-8'))
while True:
next_action_message = "will retry" if can_retry else "some events were dropped"
try:
r = http_client.request(
'POST',
uri,
headers=hdrs,
body=body,
body=data,
timeout=urllib3.Timeout(connect=config.http.connect_timeout, read=config.http.read_timeout),
retries=0
)
Expand Down