Skip to content
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

Fix #1463. Allow to expose multiple ports when running in debug mode #1479

Merged
merged 6 commits into from
Oct 25, 2019

Conversation

sdubov
Copy link
Contributor

@sdubov sdubov commented Oct 22, 2019

Issue #, if available:
#1463

Description of changes:

  • Add ability to specify multiple ports to be exposed from docker instance when running lambda in debug mode
  • Update and add new tests to verify multiple debug ports

Checklist:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* Add ability to specify multiple ports to be exposed from docker instance when running lambda in debug mode
* Update and add new tests to verify multiple debug ports

Success criteria for the change
-------------------------------
All ports (comma separated) specified in ``--debug-port`` SAM CLI parameter should be exposed by docker container.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why comma separated? This seems like a good use-case for multiple options: --debug-port 5600 --debug-port 5601.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Updated with multiple=true option parameter.

Copy link
Contributor

@jfuss jfuss left a comment

Choose a reason for hiding this comment

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

Overall, this looks pretty good. Just a couple requests, nothing major.

@@ -95,6 +95,8 @@ def invoke_common_options(f):
help="When specified, Lambda function container will start in debug mode and will expose this "
"port on localhost.",
envvar="SAM_DEBUG_PORT",
type=click.INT,
Copy link
Contributor

Choose a reason for hiding this comment

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

If -d is passed as a string, would this cause any issues? I understand why you would add this but not sure if this affects if the integer was pass as a string ("33333" for example). I want to make sure we don't accidentally break the existing contract here.

I didn't find any specific information on click, but will the debug-port always be a list when passed to our cli methods? I am having a hard time understanding how type in impacts what click will end up passing us.

Copy link
Contributor Author

@sdubov sdubov Oct 24, 2019

Choose a reason for hiding this comment

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

No issues with passing integer as a string here. Looked to the click parameters type processing logic - it tries to cast a value to integer. Verified it works well with strings unless you specify an invalid value, e.g. "abc" that sounds like an expected behavior.

Looked through click implementation for handling multiple flag - it wraps values into tuple if flag is set and return them or return an empty tuple if no values. So, I would expect we always have tuple after processing --debug-port option. Verified with single and multiple values.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect. Thanks for digging into that.

@@ -96,16 +96,21 @@ def _get_exposed_ports(debug_options):
bind to same port both inside and outside the container ie. Runtime process is started in debug mode with
at given port inside the container and exposed to the host machine at the same port

:param int debug_port: Optional, integer value of debug port
:param list(int) debug_port: Optional, List of integer values of debug ports
Copy link
Contributor

Choose a reason for hiding this comment

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

This doc is wrong (was wrong previously). The parameter passed in is debug_options not the debug_port. Could you update this to be correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Fixed doc here and in DebugContext to specify that debug port is a collection of ports to be exposed.


# container port : host port
ports_map = {}
for port in debug_options.debug_port:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you update the docs for debug_options.debug_port to reflect changes to the type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

"""
Initialize the Debug Context with Lambda debugger options

:param tuple(int) debug_port: Collection of debugger ports to be exposed from a docker container
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should this be debug_ports instead of debug_port

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I thought about the same naming change. My original thought here was to persist the original CLI option --debug-port down to usages. Updated parameter names from InvokeContext down to DebugContext.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ya we can keep the option the same (--debug-port). This is just an internal object, so no concerns on the updates.

Will do a re-review here shortly.

@jfuss
Copy link
Contributor

jfuss commented Oct 24, 2019

@sdubov I had one last comment. It's purely for readability. Everything else looks good to me.

- Update DebugContext parameter from "debug-port" to "debug_ports" to make it clear about the implementation details
- Update related parameters
- Fix the logic to set port when running Java and other containers
- Update documentation
@sdubov sdubov force-pushed the sdubov-multi-debug-ports branch from 01e1044 to a2b9b05 Compare October 24, 2019 21:01
@sdubov
Copy link
Contributor Author

sdubov commented Oct 24, 2019

Not sure why make-pr configuration is failed. Checked agent details and did not find any issues from logs.

@jfuss
Copy link
Contributor

jfuss commented Oct 24, 2019

@sdubov its failing due to a format check. We run a tool called black to make sure everything is formatted the same way throughout the codebase and avoids us having to do things manually. I can pull a update that part tomorrow if you don’t want to set that up.

@sdubov
Copy link
Contributor Author

sdubov commented Oct 24, 2019

@jfuss, Thank you for clarifying. No worries. Done with code formatting.

:return list: List containing the new entry points. Each element in the list is one portion of the command.
ie. if command is ``node index.js arg1 arg2``, then this list will be ["node", "index.js", "arg1", "arg2"]
"""

if not debug_options:
return None

debug_port = debug_options.debug_port
debug_ports = debug_options.debug_ports
if not debug_ports:
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is fine but I think it is not needed. __bool__ on DebugContext is bool(self.debug_ports). This should never execute given the first if statement (if not debug_options).

@jfuss jfuss merged commit 8d82ec0 into aws:develop Oct 25, 2019
@jfuss
Copy link
Contributor

jfuss commented Oct 25, 2019

@sdubov Thanks for contributing the feature and going through and addressing all the feedback!

@sdubov
Copy link
Contributor Author

sdubov commented Oct 25, 2019

@jfuss, no problem :) thank you for your feedback and a quick review 👍

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