Skip to content

Commit

Permalink
Use a faster JSON library
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Mar 25, 2020
1 parent 39cdcf0 commit d08605c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion twistlock/datadog_checks/twistlock/twistlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
from .config import Config
from .utils import normalize_api_data_inplace

try:
import orjson as json
except ImportError:
import json

DOCKERIO_PREFIX = "docker.io/"

# min_severity tag allows to query number of vulns for a severity target easily
Expand Down Expand Up @@ -322,7 +327,7 @@ def _retrieve_json(self, path):
try:
# it's possible to get a null response from the server
# {} is a bit easier to deal with
j = response.json() or {}
j = json.loads(response.content) or {}
if 'err' in j:
err_msg = "Error in response: {}".format(j.get("err"))
self.log.error(err_msg)
Expand Down
3 changes: 2 additions & 1 deletion twistlock/requirements.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
python-dateutil==2.8.0
python-dateutil==2.8.0
orjson==2.6.1; python_version > '3.0'
5 changes: 5 additions & 0 deletions twistlock/tests/test_twistlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mock
import pytest

from datadog_checks.base import ensure_bytes
from datadog_checks.dev import get_here
from datadog_checks.twistlock import TwistlockCheck

Expand Down Expand Up @@ -47,6 +48,10 @@ def __init__(self, j):
self._json = j
self.status_code = 200

@property
def content(self):
return ensure_bytes(self._json)

def json(self):
return json.loads(self._json)

Expand Down

0 comments on commit d08605c

Please sign in to comment.