-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
samconfig debug level logging fixed; documentation updated #2891
Changes from 8 commits
bce682d
5e534fc
8486ab9
2e72dcc
b00c06f
bae2879
2251c7d
e888c84
701cc97
6ce5e61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,14 +57,12 @@ def __call__(self, config_path, config_env, cmd_names): | |
|
||
samconfig = SamConfig(config_file_dir, config_file_name) | ||
|
||
# Enable debug level logging by environment variable "SAM_DEBUG" | ||
if os.environ.get("SAM_DEBUG", "").lower() == "true": | ||
LOG.setLevel(logging.DEBUG) | ||
|
||
LOG.debug("Config file location: %s", samconfig.path()) | ||
|
||
if not samconfig.exists(): | ||
LOG.debug("Config file '%s' does not exist", samconfig.path()) | ||
# bringing samconfig file location up to info level, | ||
# to improve UX and make it clear where we're looking for samconfig file | ||
if samconfig.exists(): | ||
click.echo(f"Config file location: {samconfig.path()}") | ||
else: | ||
click.secho(f"Config file '{samconfig.path()}' does not exist", fg="yellow") | ||
return resolved_config | ||
|
||
try: | ||
|
@@ -236,8 +234,10 @@ def decorator_customize_config_file(f): | |
config_file_param_decls = ("--config-file",) | ||
config_file_attrs["help"] = ( | ||
"The path and file name of the configuration file containing default parameter values to use. " | ||
"Its default value is 'samconfig.toml' in project directory. For more information about configuration files, " | ||
"see: " | ||
"Its default value is 'samconfig.toml' in project root directory. Project root directory is defined by the " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Final tweak, I think the help text being in 3rd person makes it sound more uniform, apologies, I didnt note this on my first pass. But I'm approving the PR, feel free to change the help text to be in 3rd person format. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing it. Thanks |
||
"template file location. When you use config file and specify --template-file SAM CLI expects samconfig.toml " | ||
"and the template file to be in the same directory. Alternatively, if --config-file is explicitly specified, " | ||
"it can point to a custom samconfig.toml location. For more information about configuration files, see " | ||
"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html." | ||
) | ||
config_file_attrs["default"] = "samconfig.toml" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,10 +74,6 @@ def print_cmdline_args(func): | |
""" | ||
|
||
def wrapper(*args, **kwargs): | ||
if kwargs.get("config_file") and kwargs.get("config_env"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was inaccurate. When the template file was used outside of the project source directory, instead of giving a warning that the config was not found, it output There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with your point that it gives an impression that the file is found. Here it gives the debugging information about the config file and config env. If the file is not found, the debug will show up later. I suggest changing the log to better describe this. Or combine it into the expanded cli parameters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I deleted this code because I added file directory echo when config file is parsed and because the config env name was already in debug. It didn't get to output without |
||
config_file = kwargs["config_file"] | ||
config_env = kwargs["config_env"] | ||
LOG.debug("Using config file: %s, config environment: %s", config_file, config_env) | ||
LOG.debug("Expand command line arguments to:") | ||
cmdline_args_log = "" | ||
for key, value in kwargs.items(): | ||
|
@@ -115,8 +111,17 @@ def cli(ctx): | |
|
||
The AWS Serverless Application Model extends AWS CloudFormation to provide a simplified way of defining the | ||
Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application. | ||
|
||
SAM CLI commands run in the project root directory which is the directory with SAM template file | ||
(template.{yml|yaml|json}). If no template file is specified explicitly, SAM CLI looks it up in the current | ||
working directory (where SAM CLI is running). | ||
|
||
SAM CLI options can be either passed directly to the commands and/or stored in the config file (samconfig.toml), | ||
which is expected to be in the project root directory by default. It is also possible to specify a custom directory | ||
for the config file if necessary. | ||
|
||
You can find more in-depth guide about the SAM specification here: | ||
https://github.com/awslabs/serverless-application-model. | ||
https://github.com/aws/serverless-application-model. | ||
""" | ||
if global_cfg.telemetry_enabled is None: | ||
enabled = True | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,14 @@ def callback(ctx, param, value): | |
state.debug = value | ||
return value | ||
|
||
# NOTE: --debug option should be eager to be evaluated before other parameters and to set log level to DEBUG | ||
# before any other option/parameter processing will require to output debug info. | ||
# Otherwise parameters are evaluated according to their order and if --debug is specified at the end of the command | ||
# some debug output can be lost | ||
# https://click.palletsprojects.com/en/7.x/advanced/#callback-evaluation-order | ||
return click.option( | ||
"--debug", | ||
is_eager=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using is_eager in some other options. Can you please check the callback order is correct if more than one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The order is okay. There is no problem in this case because
|
||
expose_value=False, | ||
is_flag=True, | ||
envvar="SAM_DEBUG", | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -217,7 +217,12 @@ def template_click_option(include_build=True): | |||||
callback=partial(get_or_default_template_file_name, include_build=include_build), | ||||||
show_default=True, | ||||||
is_eager=True, | ||||||
help="AWS SAM template which references built artifacts for resources in the template. (if applicable)" | ||||||
help="AWS SAM template which references built artifacts for resources in the template (if applicable). " | ||||||
"Template file defines the root directory of the project and allows to point SAM CLI to the directory " | ||||||
"for build, local invocation etc. If template file is not specified explicitly SAM CLI expects it to be " | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"in the current working directory (where it is running). When you use config file and specify --template-file " | ||||||
"SAM CLI expects samconfig.toml and the template file to be in the same directory." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "When you use the default config file and specify --template-file SAM CLI expects samconfig.toml and the template file to be in the same directory. Alternatively, if --config-file is explicitly specified, it can point to a custom samconfig.toml location" How does that sound? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, that's better 😃 |
||||||
"Alternatively, if --config-file is explicitly specified, it can point to a custom samconfig.toml location." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "explicitly" seems unnecessary because
Suggested change
|
||||||
if include_build | ||||||
else "AWS SAM template file.", | ||||||
) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,8 @@ def _verify_invoke_built_function(self, template_path, function_logical_id, over | |
process_execute.process.wait() | ||
|
||
process_stdout = process_execute.stdout.decode("utf-8") | ||
if process_stdout.startswith("Config file"): | ||
*_, process_stdout = process_stdout.partition("\n") | ||
Comment on lines
+175
to
+176
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need "if" here since "Config file" is always printed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well it's not exactly every time. There are commands which don't use it so it's better be on the safe side |
||
self.assertEqual(json.loads(process_stdout), expected_result) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It never worked unless SAM_DEBUG was set manually apart from --debug flag because click doesn't create/set environment variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--debug
also loads from this envvar. In case this callback is executed before callback of--debug
, the log level will not be properly set and here the debug log will not be shown.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to be the case but now it is not. Now
--debug
callback is executed before. I kept SAM_DEBUG as a back door though. Hopefully, we won't ever need it because it makes UX confusing