10000 add code to debug monkey patches applied through localstack.utils.patch by thrau · Pull Request #10957 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

add code to debug monkey patches applied through localstack.utils.patch #10957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

thrau
Copy link
Member
@thrau thrau commented Jun 4, 2024

Motivation

While debugging test failures in #10942, I had a hunch that it had something to do with missing patches, but didn't have the tools to verify. This PR adds these tools.

With the added utilities, I was able to add this simple python snippet after the runtime was ready:

from localstack.utils.patch import Patch

for p in Patch.applied_patches:
    print("- {p}"

And compare the outputs when running with the old/new runtime:

applied patches:
 - Patch(function(botocore.waiter:Waiter.wait) -> function(localstack.aws.connect:my_patch), applied=True)
 - Patch(function(botocore.parsers:BaseJSONParser._parse_body_as_json) -> function(localstack.aws.client:_patch_botocore_json_parser.<locals>._parse_body_as_json), applied=True)
 - Patch(function(moto.core.utils:convert_to_flask_response.__call__) -> function(localstack.utils.aws.request_context:patch_moto_request_handling.<locals>.convert_to_flask_response_call), applied=True)
 - Patch(function(localstack.utils.threads:FuncThread.__init__) -> function(localstack.utils.aws.request_context:patch_moto_request_handling.<locals>.thread_init), applied=True)
 - Patch(function(localstack.utils.threads:FuncThread.run) -> function(localstack.utils.aws.request_context:patch_moto_request_handling.<locals>.thread_run), applied=True)
 - Patch(method(twisted.python.threadpool:ThreadPool.stop) -> method(localstack.aws.serving.twisted:stop_thread_pool), applied=True)
applied patches:
 - Patch(function(botocore.waiter:Waiter.wait) -> function(localstack.aws.connect:my_patch), applied=True)
 - Patch(function(botocore.parsers:BaseJSONParser._parse_body_as_json) -> function(localstack.aws.client:_patch_botocore_json_parser.<locals>._parse_body_as_json), applied=True)
 - Patch(method(twisted.python.threadpool:ThreadPool.stop) -> method(localstack.aws.serving.twisted:stop_thread_pool), applied=True)

This helped me find where the patches came from

Changes

  • Patches that use @patch or Patch are now being tracked in a class-level list Patch.applied_patches
  • Patch can now be printed in a human readable way

Testing

See code snippet above

@thrau thrau requested a review from dominikschubert June 4, 2024 17:35
@thrau thrau added the semver: patch Non-breaking changes which can be included in patch releases label Jun 4, 2024
Copy link
github-actions bot commented Jun 4, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 38m 55s ⏱️ -54s
3 007 tests ±0  2 684 ✅ ±0  323 💤 ±0  0 ❌ ±0 
3 009 runs  ±0  2 684 ✅ ±0  325 💤 ±0  0 ❌ ±0 

Results for commit 0eea2bd. ± Comparison against base commit fc00ea8.

Copy link
Member
@dominikschubert dominikschubert left a comment

Choose a reason for hiding this comment

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

Pretty neat util! 🤩

A pity it won't detect some of the older non-@patch based patches that are sometimes still floating around, but we can't do anything about those I guess 🤷‍♂️

@thrau thrau merged commit 389949f into master Jun 5, 2024
32 of 33 checks passed
@thrau thrau deleted the patch-debug branch June 5, 2024 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0