Skip to content

Conversation

@symwell
Copy link
Contributor

@symwell symwell commented Oct 19, 2022

Don't show noise in the console.

  • Show a warning when the agent does something I'm not necessarily expecting, or when I've made a mistake. So, if set APPMAP=true, or APPMAP=false, or one of the APPMAP_RECORD_ variables is set to true or false, log at info.
  • If any of those variables is set to a value other than true or false, write a message at warning. This is new behavior.
  • Make the comparison with true or false be case-insensitive. Before it was done with == "true" and == "false".
  • If there's an environment variable that starts with the prefix APPMAP_RECORD_ but doesn't match one of the supported recording types, log a message at warning. This is also new behavior.
  • We've gone back and forth about what level to use when recording by default. On balance, we should log this message at info: it's presumably exactly the behavior they were hoping for when they installed the agent, and they'll see all the AppMaps that got generated.

Fixes #182.

Tested with poetry run pytest -s -v appmap/test/test_django.py.

@symwell symwell requested a review from apotterri October 19, 2022 20:18
@apotterri
Copy link
Contributor

Can you add something (Loom, asciinema, copy-and-paste terminal session, whatever) that shows the output for each of the new cases, please?

@symwell
Copy link
Contributor Author

symwell commented Oct 20, 2022

I would like to check this with testcases.

I changed the testcases to assert the logger output. I found that WARNING output gets produced as expected but INFO output isn't. I thought the logger was configured to not show INFO output but after changing that in both testcases and in detect_enabled.py I don't see any INFO output even though code execution gets to the logger.info statement.

@symwell
Copy link
Contributor Author

symwell commented Oct 20, 2022

Not seeing INFO output is a bug in pytest. I reproduced it with the instructions from here.

However, it works with with caplog.at_level(logging.INFO): in the instructions but not in test_detect_enabled.py

@apotterri
Copy link
Contributor

I would like to check this with testcases.

I agree that it's important to verify it with testcases. But, I'd also like to see what the user experience is actually going to look like, as seen in a terminal.

@symwell
Copy link
Contributor Author

symwell commented Oct 20, 2022

Tested through this repo https://github.com/symwell/try_appmap_python

  1. APPMAP=true, master (before)
PYTHONPATH=/home/test/src/appmap-python APPMAP=true python3 -m appmap.unittest program_test.py
[2022-10-20 13:07:44,163] WARNING appmap._implementation.detect_enabled: AppMap recording is enabled because APPMAP=true
WARNING:appmap._implementation.detect_enabled:AppMap recording is enabled because APPMAP=true
.
----------------------------------------------------------------------
Ran 1 test in 0.023s

OK

APPMAP=true, sw/dont_show_warning_when_appmap_is_enabled (after)

PYTHONPATH=/home/test/src/appmap-python APPMAP=true python3 -m appmap.unittest program_test.py
.
----------------------------------------------------------------------
Ran 1 test in 0.023s

OK

APPMAP_true_before_after

  1. APPMAP=false, master (before)
PYTHONPATH=/home/test/src/appmap-python APPMAP=false python3 -m appmap.unittest program_test.py
WARNING:__main__:AppMap disabled. Did you forget to set APPMAP=true?
[2022-10-20 13:10:29,134] WARNING appmap.unittest: AppMap disabled. Did you forget to set APPMAP=true?
WARNING:appmap.unittest:AppMap disabled. Did you forget to set APPMAP=true?
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

APPMAP=false, sw/dont_show_warning_when_appmap_is_enabled (after)

PYTHONPATH=/home/test/src/appmap-python APPMAP=false python3 -m appmap.unittest program_test.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

APPMAP_false_before_after

  1. APPMAP=invalid, master (before)
PYTHONPATH=/home/test/src/appmap-python APPMAP=invalid python3 -m appmap.unittest program_test.py
[2022-10-20 13:46:11,338] WARNING appmap._implementation.detect_enabled: AppMap recording is enabled because will record by default
WARNING:appmap._implementation.detect_enabled:AppMap recording is enabled because will record by default
.
----------------------------------------------------------------------
Ran 1 test in 0.023s

OK

APPMAP=invalid, sw/dont_show_warning_when_appmap_is_enabled (after)

PYTHONPATH=/home/test/src/appmap-python APPMAP=invalid python3 -m appmap.unittest program_test.py
AppMap recording is not enabled because APPMAP=invalid is an invalid option.
AppMap recording is not enabled because APPMAP=invalid is an invalid option.
AppMap recording is not enabled because APPMAP=invalid is an invalid option.
AppMap recording is not enabled because APPMAP=invalid is an invalid option.
[2022-10-20 13:43:02,650] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP=invalid is an invalid option.
[2022-10-20 13:43:02,650] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP=invalid is an invalid option.
[2022-10-20 13:43:02,650] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP=invalid is an invalid option.
[2022-10-20 13:43:02,650] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP=invalid is an invalid option.
[2022-10-20 13:43:02,753] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP=invalid is an invalid option.
WARNING:appmap._implementation.detect_enabled:AppMap recording is not enabled because APPMAP=invalid is an invalid option.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

APPMAP_invalid_before_after

  1. APPMAP_RECORD_INVALID=true, master (before)
PYTHONPATH=/home/test/src/appmap-python APPMAP_RECORD_INVALID=true python3 -m appmap.unittest program_test.py
[2022-10-20 13:48:59,467] WARNING appmap._implementation.detect_enabled: AppMap recording is enabled because will record by default
WARNING:appmap._implementation.detect_enabled:AppMap recording is enabled because will record by default
.
----------------------------------------------------------------------
Ran 1 test in 0.023s

OK

APPMAP_RECORD_INVALID=true, sw/dont_show_warning_when_appmap_is_enabled (after)

PYTHONPATH=/home/test/src/appmap-python APPMAP_RECORD_INVALID=true python3 -m appmap.unittest program_test.py
AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
[2022-10-20 13:49:24,044] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
[2022-10-20 13:49:24,044] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
[2022-10-20 13:49:24,044] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
[2022-10-20 13:49:24,044] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
[2022-10-20 13:49:24,147] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
WARNING:appmap._implementation.detect_enabled:AppMap recording is not enabled because APPMAP_RECORD_INVALID is an invalid recording method.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

APPMAP_RECORD_INVALID_before_after

I think after the latest change stuff gets printed 5 times.

@symwell symwell force-pushed the sw/dont_show_warning_when_appmap_is_enabled branch from 7ff3b12 to ed511f8 Compare October 20, 2022 19:40
@symwell
Copy link
Contributor Author

symwell commented Oct 20, 2022

Added screenshots and changed one more testcase now that a warning isn't printed.

@apotterri
Copy link
Contributor

It doesn't seem ideal to print the same message multiple times. Can we do something about that?

@symwell
Copy link
Contributor Author

symwell commented Oct 21, 2022

It also prints the warning without WARNING in front of it. Looking into this part.

Got it to print the warning only once.

APPMAP_invalid_print_warning_only_once

@symwell
Copy link
Contributor Author

symwell commented Oct 21, 2022

Screenshot diffs.
Top is master
Bottom is sw/dont_show_warning_when_appmap_is_enabled

  1. APPMAP=true

v2_APPMAP_true

  1. APPMAP=false

v2_APPMAP_false

  1. APPMAP=invalid

v2_APPMAP_invalid

  1. APPMAP_RECORD_INVALID=true

v2_APPMAP_RECORD_INVALID

  1. APPMAP_RECORD_REQUESTS=true

v2_APPMAP_RECORD_REQUESTS_true

  1. APPMAP_RECORD_REQUESTS=false

v2_APPMAP_RECORD_REQUESTS_false

@symwell
Copy link
Contributor Author

symwell commented Oct 21, 2022

APPMAP_RECORD_UNITTEST shows a duplicate log on stdout without the formatted datetime.

PYTHONPATH=/home/test/src/appmap-python APPMAP_RECORD_UNITTEST=invalid python3 -m appmap.unittest program_test.py
[2022-10-21 13:04:24,539] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP_RECORD_UNITTEST=invalid is an invalid option.
WARNING:appmap._implementation.detect_enabled:AppMap recording is not enabled because APPMAP_RECORD_UNITTEST=invalid is an invalid option.
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

APPMAP_RECORD_PYTEST doesn't.

test@o[2022-10-21_14:43:02]:~/src/try_appmap_python$ PYTHONPATH=/home/test/src/appmap-python APPMAP_RECORD_PYTEST=invalid python3 -m appmap.unittest program_test.py
[2022-10-21 14:43:17,670] WARNING appmap._implementation.detect_enabled: AppMap recording is not enabled because APPMAP_RECORD_PYTEST=invalid is an invalid option.
.
----------------------------------------------------------------------
Ran 1 test in 0.023s

OK

v2_APPMAP_pytest_unittest

Interesting: if the call to logger.isEnabledFor(log_level) is removed then no warning is shown.

APPMAP_RECORD_UNITTEST enters _configure_logging twice before logging its warning.
APPMAP_RECORD_PYTEST enters _configure_logging once before logging its warning and once after.

In either case why is _configure_logging called twice? I'm looking into this.
update: After turning Env into a singleton, which gets _configure_logging called only once, the warning issue persisted.

@symwell
Copy link
Contributor Author

symwell commented Oct 21, 2022

Created separate issue to address configuring logging for APPMAP_RECORD_UNITTEST.

@symwell symwell force-pushed the sw/dont_show_warning_when_appmap_is_enabled branch 2 times, most recently from a092023 to 7f37bbb Compare October 24, 2022 15:04
@symwell symwell requested a review from apotterri October 25, 2022 13:44
Copy link
Contributor

@apotterri apotterri left a comment

Choose a reason for hiding this comment

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

Please fix the body of the comment on the comment so it describes the change you made.

Show a warning when the agent does something the user is not
necessarily expecting, or when the user made a mistake. So, if
APPMAP=true or APPMAP=false or one of the APPMAP_RECORD_ variables is
set to true or false, log at "info".

If any of those variables is set to a value other than true or false,
log at "warning". This is new behavior.

Make the comparison with true or false be case-insensitive. Before it
was done with '== "true"' and '== "false"'.

If there's an environment variable that starts with the prefix
APPMAP_RECORD_ but doesn't match one of the supported recording types,
log a message at "warning". This is also new behavior.

When recording by default log at "info": it's presumably exactly the
behavior the user was hoping for when they installed the agent, and
they'll see all the AppMaps that got generated.
@symwell symwell force-pushed the sw/dont_show_warning_when_appmap_is_enabled branch from 7f37bbb to f763eb6 Compare October 25, 2022 18:10
Copy link
Contributor

@apotterri apotterri left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for making this update.

@symwell symwell merged commit 40690e6 into master Oct 25, 2022
@symwell symwell deleted the sw/dont_show_warning_when_appmap_is_enabled branch October 25, 2022 19:24
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.

Don't display warning that says "AppMap recording is enabled" -- appmap-python

3 participants