Skip to content

Commit 86248a5

Browse files
authored
Merge pull request #306 from NathanielRN/remove-slow-filepath-resolve
2 parents b5b99b7 + aa4b2f5 commit 86248a5

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

Diff for: aws_xray_sdk/core/sampling/local/sampler.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import json
2+
import pkgutil
23
from random import Random
34

4-
from pkg_resources import resource_filename
55
from .sampling_rule import SamplingRule
66
from ...exceptions.exceptions import InvalidSamplingManifestError
77

8-
9-
with open(resource_filename(__name__, 'sampling_rule.json')) as f:
10-
local_sampling_rule = json.load(f)
8+
local_sampling_rule = json.loads(pkgutil.get_data(__name__, 'sampling_rule.json'))
119

1210
SUPPORTED_RULE_VERSION = (1, 2)
1311

Diff for: aws_xray_sdk/ext/boto_utils.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import absolute_import
22
# Need absolute import as botocore is also in the current folder for py27
33
import json
4+
import pkgutil
45

5-
from pkg_resources import resource_filename
66
from botocore.exceptions import ClientError
77

88
from aws_xray_sdk.core import xray_recorder
@@ -12,8 +12,7 @@
1212
from aws_xray_sdk.ext.util import inject_trace_header, to_snake_case
1313

1414

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

1817

1918
def inject_header(wrapped, instance, args, kwargs):

Diff for: tests/mock_sampling_rule.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": 2,
3+
"default": {
4+
"fixed_target": 1,
5+
"rate": 0.05
6+
},
7+
"rules": [
8+
]
9+
}

Diff for: tests/test_local_sampling_benchmark.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import json
2+
import pkgutil
3+
from pkg_resources import resource_filename
4+
5+
# Faster
6+
def test_pkgutil_static_read(benchmark):
7+
def get_sampling_rule():
8+
return json.loads(pkgutil.get_data(__name__, 'mock_sampling_rule.json'))
9+
benchmark(get_sampling_rule)
10+
11+
# Slower
12+
def test_pkg_resources_static_read(benchmark):
13+
def get_sampling_rule():
14+
with open(resource_filename(__name__, 'mock_sampling_rule.json')) as f:
15+
return json.load(f)
16+
benchmark(get_sampling_rule)

Diff for: tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ skip_missing_interpreters = True
1616
passenv = TOXENV CI TRAVIS TRAVIS_* CODECOV_*
1717
deps =
1818
pytest > 3.0.0
19+
pytest-benchmark
1920
coverage==4.5.4
2021
codecov
2122
requests

0 commit comments

Comments
 (0)