Skip to content

Commit

Permalink
Merge pull request #306 from NathanielRN/remove-slow-filepath-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanielRN committed Jul 28, 2021
2 parents b5b99b7 + aa4b2f5 commit 86248a5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
6 changes: 2 additions & 4 deletions aws_xray_sdk/core/sampling/local/sampler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json
import pkgutil
from random import Random

from pkg_resources import resource_filename
from .sampling_rule import SamplingRule
from ...exceptions.exceptions import InvalidSamplingManifestError


with open(resource_filename(__name__, 'sampling_rule.json')) as f:
local_sampling_rule = json.load(f)
local_sampling_rule = json.loads(pkgutil.get_data(__name__, 'sampling_rule.json'))

SUPPORTED_RULE_VERSION = (1, 2)

Expand Down
5 changes: 2 additions & 3 deletions aws_xray_sdk/ext/boto_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import absolute_import
# Need absolute import as botocore is also in the current folder for py27
import json
import pkgutil

from pkg_resources import resource_filename
from botocore.exceptions import ClientError

from aws_xray_sdk.core import xray_recorder
Expand All @@ -12,8 +12,7 @@
from aws_xray_sdk.ext.util import inject_trace_header, to_snake_case


with open(resource_filename(__name__, 'resources/aws_para_whitelist.json'), 'r') as data_file:
whitelist = json.load(data_file)
whitelist = json.loads(pkgutil.get_data(__name__, 'resources/aws_para_whitelist.json'))


def inject_header(wrapped, instance, args, kwargs):
Expand Down
9 changes: 9 additions & 0 deletions tests/mock_sampling_rule.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"version": 2,
"default": {
"fixed_target": 1,
"rate": 0.05
},
"rules": [
]
}
16 changes: 16 additions & 0 deletions tests/test_local_sampling_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
import pkgutil
from pkg_resources import resource_filename

# Faster
def test_pkgutil_static_read(benchmark):
def get_sampling_rule():
return json.loads(pkgutil.get_data(__name__, 'mock_sampling_rule.json'))
benchmark(get_sampling_rule)

# Slower
def test_pkg_resources_static_read(benchmark):
def get_sampling_rule():
with open(resource_filename(__name__, 'mock_sampling_rule.json')) as f:
return json.load(f)
benchmark(get_sampling_rule)
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ skip_missing_interpreters = True
passenv = TOXENV CI TRAVIS TRAVIS_* CODECOV_*
deps =
pytest > 3.0.0
pytest-benchmark
coverage==4.5.4
codecov
requests
Expand Down

0 comments on commit 86248a5

Please sign in to comment.