Skip to content

Commit

Permalink
Replace jsonutils by ujson
Browse files Browse the repository at this point in the history
ujson is faster than jsonutils, and we do not need any fancy feature jsonutils
might offer.

This also has the benefit of removing a big dependency on Ceilometer.

Change-Id: I24bf08d0fa6ccc34beef0a0c34a47bf2fa266e3e
  • Loading branch information
jd committed Oct 26, 2017
1 parent 9323f07 commit 7b959b3
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ceilometer/publisher/gnocchi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
from gnocchiclient import exceptions as gnocchi_exc
from keystoneauth1 import exceptions as ka_exceptions
from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import fnmatch
from oslo_utils import timeutils
import six
import six.moves.urllib.parse as urlparse
from stevedore import extension
import ujson

from ceilometer import declarative
from ceilometer import gnocchi_client
Expand Down Expand Up @@ -502,7 +502,7 @@ def _delete_event(self, rd, event):
def _search_resource(self, resource_type, query):
try:
return self._gnocchi.resource.search(
resource_type, jsonutils.loads(query))
resource_type, ujson.loads(query))
except Exception:
LOG.error("Fail to search resource type %{resource_type}s "
"with '%{query}s'",
Expand Down
4 changes: 2 additions & 2 deletions ceilometer/publisher/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
# under the License.

from oslo_log import log
from oslo_serialization import jsonutils
from oslo_utils import strutils
import requests
from requests import adapters
from six.moves.urllib import parse as urlparse
import ujson

from ceilometer import publisher

Expand Down Expand Up @@ -154,7 +154,7 @@ def _do_post(self, data):
if not data:
LOG.debug('Data set is empty!')
return
data = jsonutils.dumps(data)
data = ujson.dumps(data)
LOG.trace('Message: %s', data)
try:
res = self.session.post(self.target, data=data,
Expand Down
2 changes: 1 addition & 1 deletion ceilometer/tests/unit/publisher/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,5 @@ def test_post_raw_only(self):
with mock.patch.object(requests.Session, 'post') as post:
publisher.publish_events(self.event_data)
self.assertEqual(
'[{"some": "aa"}, {"some": "aa"}, {"some": "aa"}]',
'[{"some":"aa"},{"some":"aa"},{"some":"aa"}]',
post.call_args[1]['data'])
6 changes: 3 additions & 3 deletions ceilometer/tests/unit/publisher/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# under the License.
"""Tests for ceilometer/publisher/utils.py
"""
from oslo_serialization import jsonutils
from oslotest import base
import ujson

from ceilometer.publisher import utils

Expand Down Expand Up @@ -104,7 +104,7 @@ def test_verify_signature_nested_json(self):
data['message_signature'] = utils.compute_signature(
data,
'not-so-secret')
jsondata = jsonutils.loads(jsonutils.dumps(data))
jsondata = ujson.loads(ujson.dumps(data))
self.assertTrue(utils.verify_signature(jsondata, 'not-so-secret'))

def test_verify_unicode_symbols(self):
Expand All @@ -114,7 +114,7 @@ def test_verify_unicode_symbols(self):
data['message_signature'] = utils.compute_signature(
data,
'not-so-secret')
jsondata = jsonutils.loads(jsonutils.dumps(data))
jsondata = ujson.loads(ujson.dumps(data))
self.assertTrue(utils.verify_signature(jsondata, 'not-so-secret'))

def test_verify_no_secret(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ oslo.reports>=0.6.0 # Apache-2.0
oslo.rootwrap>=2.0.0 # Apache-2.0
pbr>=1.6 # Apache-2.0
oslo.messaging>=5.12.0 # Apache-2.0
oslo.serialization>=1.10.0 # Apache-2.0
ujson
oslo.utils>=3.5.0 # Apache-2.0
pysnmp<5.0.0,>=4.2.3 # BSD
python-glanceclient>=2.0.0 # Apache-2.0
Expand Down

0 comments on commit 7b959b3

Please sign in to comment.