Skip to content

Commit 9cedeb4

Browse files
committed
Use gzip compression
1 parent ea3533f commit 9cedeb4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pipeline.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from apache_beam.options.pipeline_options import PipelineOptions
66
from apache_beam.transforms.window import FixedWindows
77
import requests
8+
import gzip
89
from typing import Dict, Any, List
910
from datetime import timedelta
1011

@@ -15,7 +16,8 @@ def __init__(self, source_token: str, ingesting_host: str, batch_size: int):
1516
self.batch_size = batch_size
1617
self.headers = {
1718
'Authorization': f'Bearer {source_token}',
18-
'Content-Type': 'application/json'
19+
'Content-Type': 'application/json',
20+
'Content-Encoding': 'gzip'
1921
}
2022
self.batch = []
2123

@@ -45,11 +47,15 @@ def finish_bundle(self):
4547

4648
def _send_batch(self):
4749
try:
48-
# Send batch to Better Stack
50+
# Convert batch to JSON and compress with gzip
51+
json_data = json.dumps(self.batch)
52+
compressed_data = gzip.compress(json_data.encode('utf-8'))
53+
54+
# Send compressed batch to Better Stack
4955
response = requests.post(
5056
self.ingesting_url,
5157
headers=self.headers,
52-
json=self.batch
58+
data=compressed_data
5359
)
5460

5561
if response.status_code != 202:

0 commit comments

Comments
 (0)