Skip to content
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

Use a faster JSON library #6143

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ lxml==4.4.1
lz4==2.2.1
meld3==1.0.2
openstacksdk==0.24.0
orjson==2.6.1; python_version > '3.0'
paramiko==2.6.0
ply==3.10
prometheus-client==0.3.0
Expand Down
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

ofek marked this conversation as resolved.
Show resolved Hide resolved
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