Skip to content

Commit 3afb9dc

Browse files
authored
Merge pull request #3 from mirelap-amazon/main
Multiple minor clean-ups from previous PR.
2 parents 5acbd7d + a0739c8 commit 3afb9dc

File tree

11 files changed

+19
-88
lines changed

11 files changed

+19
-88
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
For more details, check the documentation: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/what-is-codeguru-profiler.html
44

5+
## How to use it
6+
7+
This package is released to PyPI, so use it as any Python package from PyPI: https://pypi.org/project/codeguru-profiler-agent
8+
9+
For a demo application that uses this agent, check our [demo application](https://github.com/aws-samples/aws-codeguru-profiler-python-demo-application).
10+
511
## Release to PyPI
612

713
Use the `setup.py` script to create the archive.

codeguru_profiler_agent/aws_lambda/lambda_handler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def load_handler(bootstrap_module, env=os.environ, original_handler_env_key=HAND
2222
if hasattr(bootstrap_module, '_get_handler'):
2323
customer_handler_function = bootstrap_module._get_handler(original_handler_name)
2424
else:
25-
# Support for python 3.6 bootstrap which is different. It is starting to be quite hacky at this point.
26-
# We will need to discuss if it is worth handling this case and if we can do it in a better way.
25+
# TODO FIXME Review if the support for python 3.6 bootstrap can be improved.
2726
# This returns both a init_handler and the function, we apply the init right away as we are in init process
2827
init_handler, customer_handler_function = bootstrap_module._get_handlers(
2928
handler=original_handler_name,

codeguru_profiler_agent/model/sample.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
class Sample:
2+
__slots__ = ["stacks", "attempted_sample_threads_count", "seen_threads_count"]
3+
24
def __init__(self, stacks, attempted_sample_threads_count=0, seen_threads_count=0):
35
"""
46
:param stacks: list of lists; each list is a list of Frame object representing a thread stack in bottom (of thread stack) to top (of thread stack) order

codeguru_profiler_agent/profiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# [B108:hardcoded_tmp_directory] Probable insecure usage of temp file/directory.
3232
# https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html
3333
# This file can be used by the customer as kill switch for the Profiler.
34+
# TODO FIXME Consider making this work for Windows.
3435
KILLSWITCH_FILEPATH = "/var/tmp/killProfiler" #nosec
3536

3637
logger = logging.getLogger(__name__)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def find_version(*file_paths):
3030
description="The Python agent to be used for Amazon CodeGuru Profiler",
3131
long_description="https://docs.aws.amazon.com/codeguru/latest/profiler-ug/what-is-codeguru-profiler.html",
3232
author="Amazon Web Services",
33-
url="https://github.com/aws",
34-
download_url="https://github.com/aws",
33+
url="https://github.com/aws/amazon-codeguru-profiler-python-agent",
34+
download_url="https://github.com/aws/amazon-codeguru-profiler-python-agent",
3535
classifiers=[
3636
"Programming Language :: Python :: 3",
3737
"Development Status :: 5 - Production/Stable",

test/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import pytest
2-
3-
# Enable pytestutils @focus decoration
4-
pytest_plugins = "test.pytestutils_focus"
1+
# Enable pytestutils decoration
2+
pytest_plugins = "test.pytestutils"

test/integration/test_live_backend_reporting.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919

2020
@pytest.mark.skipif(
21-
# TODO FIXME Remove the conditions for skipping this on Amazonian fleets when we move fully to GitHub.
22-
socket.gethostname().startswith("pb-worker-prod") or
23-
socket.gethostname().startswith("coverlay-") or
2421
socket.getfqdn().endswith("internal.cloudapp.net"), # hosts running ubuntu and windows in GitHub
2522
socket.getfqdn().endswith("ip6.arpa"), # hosts running macs in GitHub
2623
reason="This integration test is skipped on any shared fleet from Amazon or GitHub "

test/pytestutils.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
_pytestutils_before_global_counter = 0
66
_pytestutils_before_global_lock = threading.Lock()
77

8-
_pytestutils_is_there_any_test_marked_with_focus = False
9-
108

119
def before(before_function):
1210
"""
@@ -56,55 +54,3 @@ def test_it_does_stuff(self):
5654

5755
return pytest.fixture(
5856
autouse=True, name=unique_fixture_name)(before_function)
59-
60-
61-
def focus(decorated_test):
62-
"""
63-
Decorator for tagging a function or class as being in focus, and to switch the test suite execution to "focused
64-
execution mode". When the test suite is in "focused execution mode", only functions and classes marked with @focus
65-
are run, all others are skipped.
66-
67-
When there are no functions/classes marked with @focus, the test suite goes back to the usual mode, and all tests
68-
are run.
69-
70-
The focused execution mode is useful for quickly and without needing to edit any more configuration/files selecting
71-
only a subset of the tests for execution, to speed up testing cycles.
72-
73-
This decorator is inspired by similar IDE features (e.g. https://blogs.oracle.com/geertjan/run-focused-test-method )
74-
and other test libraries (e.g. https://medium.com/table-xi/focus-your-rspec-workflow-4cd5798d2a3e ).
75-
76-
Limitation when used with Pytest < 3.6: @focus does not extend to nested classes, see
77-
https://github.com/pytest-dev/pytest/issues/199 and https://github.com/pytest-dev/pytest/pull/3317 for details.
78-
79-
This feature is broken into several pieces:
80-
* The @focus decorator sets a global variable to trigger the focused execution mode, and additionally marks any
81-
test method or class with the "pytestutils_focus" marker
82-
* In pytestutils_focus.py a pytest plugin is provided that when in focused execution mode, skips any tests not
83-
marked with the "pytestutils_focus" marker
84-
* In conftest.py we enable the pytest plugin
85-
"""
86-
_validate_focus_enabled()
87-
88-
global _pytestutils_is_there_any_test_marked_with_focus
89-
90-
_pytestutils_is_there_any_test_marked_with_focus = True
91-
92-
return pytest.mark.pytestutils_focus(decorated_test)
93-
94-
95-
def _validate_focus_enabled():
96-
if os.environ.get("PYTESTUTILS_ALLOW_FOCUS") in ("1", "true", "yes"):
97-
return
98-
raise RuntimeError("""
99-
Found tests annotated with @focus decorator, but the PYTESTUTILS_ALLOW_FOCUS environment variable is not set in the
100-
current environment.
101-
102-
If you found this error in a CI environment, it means someone committed test code with a @focus annotation -- please
103-
check for and remove it from the codebase.
104-
105-
If you found this error and you wanted to use @focus for your own development work, please add a PYTESTUTILS_ALLOW_FOCUS
106-
enviroment variable set to 1 (e.g. `export PYTESTUTILS_ALLOW_FOCUS=1`) to your execution environment to make this error
107-
go away.
108-
109-
Thanks for using @focus!
110-
""")

test/pytestutils_focus.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

test/unit/reporter/test_agent_configuration_merger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ def test_it_leaves_other_values_untouched(self):
8787
assert AgentConfiguration.get().sampling_interval == timedelta(milliseconds=1)
8888
assert AgentConfiguration.get().minimum_time_reporting == timedelta(seconds=1)
8989
assert AgentConfiguration.get().reporting_interval == timedelta(minutes=1)
90-
assert AgentConfiguration.get().max_stack_depth == 998
90+
assert AgentConfiguration.get().max_stack_depth == 998

0 commit comments

Comments
 (0)