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

Convert print statements to logging statements #1893

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

invisiblethreat
Copy link

Please answer these questions before submitting your pull requests. Thanks!

  1. What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1178890: When using externalbrowser printing to STDOUT breaks pipelining #1892

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am modifying authorization mechanisms
    • I am adding new credentials
    • I am modifying OCSP code
    • I am adding a new dependency
  3. Please describe how your code solves the related issue.

    The use of print breaks piping outputs, as the output is contaminated with the message when using exteranlbrowswer authentication. Moving these messages into logging allows for pipelining, and also elevating the the failure mode to a more suitable level of urgency.

Copy link

github-actions bot commented Feb 29, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@invisiblethreat
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@invisiblethreat
Copy link
Author

recheck

@sfc-gh-aalam sfc-gh-aalam added the NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md label Mar 1, 2024
@sfc-gh-aalam sfc-gh-aalam enabled auto-merge (squash) March 1, 2024 00:53
@sfc-gh-aalam
Copy link
Collaborator

@invisiblethreat could you fix the unit tests too and use logging.caplog to match what the old test was testing

auto-merge was automatically disabled March 1, 2024 21:22

Head branch was pushed to by a user without write access

@invisiblethreat
Copy link
Author

@sfc-gh-aalam Had some issues getting tests to run as expected locally, but built out some toy scripts to assess the functionality of caplog and the resulting changes should restore tests. 🤞

Comment on lines +285 to +292
assert (
"Initiating login request with your identity provider. A browser window "
"should have opened for you to complete the login. If you can't see it, "
"check existing browser windows, or your OS settings. Press CTRL+C to "
f"abort and try again...\nGoing to open: {REF_SSO_URL if disable_console_login else REF_CONSOLE_LOGIN_SSO_URL} to authenticate...\nWe were unable to open a browser window for "
"you, please open the url above manually then paste the URL you "
"are redirected to into the terminal.\n"
)
) in caplog.text
Copy link
Collaborator

Choose a reason for hiding this comment

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

you would have to break this into two assert statements because logger is adding extra text in between. same for the other test

assert "Initiating login request with your identity provider. A browser window should have opened for you to
complete the login. If you can't see it, check existing browser windows, or your OS settings. Press CTRL+C to abort 
and try again...\nGoing to open: https://testsso.snowflake.net/sso to authenticate...\n" in "INFO     
snowflake.connector.auth.webbrowser:webbrowser.py:169 Initiating login request with your identity provider. A 
browser window should have opened for you to complete the login. If you can't see it, check existing browser 
windows, or your OS settings. Press CTRL+C to abort and try again...\nINFO     
snowflake.connector.auth.webbrowser:webbrowser.py:177 Going to open: https://testsso.snowflake.net/sso to 
authenticate...\n"

"Initiating login request with your identity provider. A "
"browser window should have opened for you to complete the "
"login. If you can't see it, check existing browser windows, "
"or your OS settings. Press CTRL+C to abort and try again..."
)

logger.debug("step 2: open a browser")
print(f"Going to open: {sso_url} to authenticate...")
Copy link
Contributor

Choose a reason for hiding this comment

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

We print it to stdout so when the program failed to open a browser, CLI users could manually open the link in browser, not sure if logging would work in this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is at least a breaking change and should go through announcement. But I'm not too sure whether we'd want to change this in the first place. I think the opening message we wouldn't want to get rid off in the default case.
How about introducing a setting that switches to logging instead of printing, but we'd leave the default setting on printing? @invisiblethreat would that work for you?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that would work. I'd actually propose that log is the default and a more verbose mode is available for troubleshooting, or this particular use case. Defaulting a library to STDOUT feels like the wrong thing to do, but I'm not privy to all the use cases 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SNOW-1178890: When using externalbrowser printing to STDOUT breaks pipelining
4 participants