Skip to content

Conversation

@mirelap-amazon
Copy link
Contributor

@mirelap-amazon mirelap-amazon commented Jan 5, 2021

Issue #, if available:

Description of changes:
Initial implementation of the agent duplicated and adapted from the internal repository.

Testing:

  1. Run all tests locally with pytest (including integration with local AWS credentials).
  2. When pushed on my personal fork, the commit triggered a GitHub Workflow action that run the unit and acceptance tests, see here the results.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@mirelap-amazon mirelap-amazon self-assigned this Jan 5, 2021
@mirelap-amazon mirelap-amazon marked this pull request as ready for review January 5, 2021 12:48
@mirelap-amazon mirelap-amazon requested review from a team and gimki and removed request for gimki January 5, 2021 12:54
Copy link
Contributor

@gimki gimki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left some comments. I would not be bothered to have those changes in this PR. I am happy for you to push this as initial commits but I would suggest to do a clean up before we making it open source. We may possibly open source this when we release v1.0.3 onto PyPI with new features + cleanup. My comments are minor really but also something that I think we should clean up before making it visible to the community. Feel free to merge it; the comments I left are for future use really. Thanks


def _maybe_append_time_sleep(result, frame, line_no):
line = linecache.getline(frame.f_code.co_filename, line_no).strip()
if "sleep(" in line:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we mind exposing this hardcoded hack here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behaviour is already clear for a customer with this use-case, so I don't see any reason to not include this.

customer_handler_function = bootstrap_module._get_handler(original_handler_name)
else:
# Support for python 3.6 bootstrap which is different. It is starting to be quite hacky at this point.
# We will need to discuss if it is worth handling this case and if we can do it in a better way.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rephrase comments like these(?)

Make it like a TODO or FIXME instead (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a TODO FIXME.

Comment on lines +7 to +10
push:
branches: [ main ]
pull_request:
branches: [ main ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I can link this back to any part of the doc on https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first link from https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-python#starting-with-the-python-workflow-template for "Python workflow template" redirects to a sample that shows this configuration. I generated the initial file by using the default wizard from GitHub.

@@ -0,0 +1,12 @@
class Sample:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not this PR) TODO: Make use of slot for this class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do, interesting.

# [B108:hardcoded_tmp_directory] Probable insecure usage of temp file/directory.
# https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html
# This file can be used by the customer as kill switch for the Profiler.
KILLSWITCH_FILEPATH = "/var/tmp/killProfiler" #nosec
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This would not work for Windows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a TODO FIXME.

import pytest

# Enable pytestutils @focus decoration
pytest_plugins = "test.pytestutils_focus"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question: Do we need to keep this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file is needed to allow other decorations (like @before) from pytestutils, but I will remove @Focus we can use pytest to run a specific folder or file and considering I haven't found a big utility of @Focus yet.



@pytest.mark.skipif(
# TODO FIXME Remove the conditions for skipping this on Amazonian fleets when we move fully to GitHub.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to address that in cleanup commit next

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will update, thanks.

context="expected_context") == "expected result"

class TestLoadModuleFunction:
class TestWhenPython38LambdaBootstrapCalls:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Do we need to control that it is run for python38 only (?) I know it doesnt matter but it is a bit weird to run that for all version of python given that it said python38 explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here is more about the Python38 implementation, not necessary the version we are using. I don't see it worth it to update it considering it passes for all versions.

self.mock_collector.add.assert_not_called()


def wait_until(predicate, max_wait_seconds=1, period_seconds=0.1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we refactored this out to utils.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll update to use the existing wait_for from help_utils, thanks.

assert AgentConfiguration.get().sampling_interval == timedelta(milliseconds=1)
assert AgentConfiguration.get().minimum_time_reporting == timedelta(seconds=1)
assert AgentConfiguration.get().reporting_interval == timedelta(minutes=1)
assert AgentConfiguration.get().max_stack_depth == 998 No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@mirelap-amazon
Copy link
Contributor Author

As discussed, none of this was considered blocking, so I merged like this and handle the comments in the next PR, here. Thanks a lot for your review! @gimki

@mirelap-amazon mirelap-amazon requested a review from a team January 8, 2021 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants