Skip to content

Commit

Permalink
only compress dogstatsd payloads that are larger than 1k
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlo Cabanilla committed Apr 2, 2014
1 parent 522177e commit 15b02fb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions dogstatsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@
FLUSH_LOGGING_INITIAL = 10
FLUSH_LOGGING_COUNT = 5
EVENT_CHUNK_SIZE = 50
COMPRESS_THRESHOLD = 1024

def serialize_metrics(metrics):
return zlib.compress(json.dumps({"series" : metrics}))
serialized = json.dumps({"series" : metrics})
if len(serialized) > COMPRESS_THRESHOLD:
headers = {'Content-Type': 'application/json',
'Content-Encoding': 'deflate'}
serialized = zlib.compress(serialized)
else:
headers = {'Content-Type': 'application/json'}
return serialized, headers

def serialize_event(event):
return json.dumps(event)
Expand Down Expand Up @@ -147,9 +155,7 @@ def flush(self):
def submit(self, metrics):
# Copy and pasted from dogapi, because it's a bit of a pain to distribute python
# dependencies with the agent.
body = serialize_metrics(metrics)
headers = {'Content-Type': 'application/json',
'Content-Encoding': 'deflate'}
body, headers = serialize_metrics(metrics)
method = 'POST'

params = {}
Expand Down

0 comments on commit 15b02fb

Please sign in to comment.