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

feat: add standardized debug logging #1097

Merged
merged 7 commits into from
Jun 3, 2024
Merged

feat: add standardized debug logging #1097

merged 7 commits into from
Jun 3, 2024

Conversation

jackwotherspoon
Copy link
Collaborator

@jackwotherspoon jackwotherspoon commented May 31, 2024

Standardize optional debug logging across Cloud SQL Connector packages.

To print debug logs for the Python Connector package add the following to your application:

import logging

logging.basicConfig(format="%(asctime)s [%(levelname)s]: %(message)s")
logger = logging.getLogger(name="google.cloud.sql.connector")
logger.setLevel(logging.DEBUG)

Example of the debug logs produced:

2024-05-31 18:27:30,472 [DEBUG]: ['my-project:my-region:my-instance']: Refresh strategy is set to backgound refresh
2024-05-31 18:27:30,473 [DEBUG]: ['my-project:my-region:my-instance']: Connection info added to cache
2024-05-31 18:27:30,473 [DEBUG]: ['my-project:my-region:my-instance']: Connection info refresh operation started
2024-05-31 18:27:30,771 [DEBUG]: ['my-project:my-region:my-instance']: Connection info refresh operation complete
2024-05-31 18:27:30,771 [DEBUG]: ['my-project:my-region:my-instance']: Current certificate expiration = 2024-05-31T19:27:30+00:00
2024-05-31 18:27:30,772 [DEBUG]: ['my-project:my-region:my-instance']: Connection info refresh operation scheduled for 2024-05-31T19:23:29+00:00 (now + 0:55:59)
2024-05-31 18:27:30,772 [DEBUG]: ['my-project:my-region:my-instance']: Connecting to X.X.X.X:3307
2024-05-31 18:27:31,508 [DEBUG]: ['my-project:my-region:my-instance']: Canceling connection info refresh operation tasks
2024-05-31 18:27:31,509 [DEBUG]: ['my-project:my-region:my-instance']: Scheduled refresh operation cancelled
2024-05-31 18:27:31,509 [DEBUG]: Waiting for Connector http client to close
2024-05-31 18:27:31,509 [DEBUG]: Closed Connector http client

Currently debug logging the following:

  • When a refresh operation starts
  • When a refresh operation finishes
  • When a refresh operation errors
  • When a refresh operation is canceled
  • The ephemeral certificate’s expiration time
  • The next scheduled refresh
  • Adding connection info to the cache
  • The IP address connection is being made to

Fixes #1035

@jackwotherspoon jackwotherspoon self-assigned this May 31, 2024
@jackwotherspoon jackwotherspoon requested a review from a team as a code owner May 31, 2024 19:12
@jackwotherspoon
Copy link
Collaborator Author

Some additional logs will require feature parity work first and adding those logs have been called out in the corresponding bugs #1098 and #941

Copy link
Contributor

@hessjcg hessjcg left a comment

Choose a reason for hiding this comment

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

LGTM. I made an optional suggestion for a more specific log message on sleep.

google/cloud/sql/connector/instance.py Outdated Show resolved Hide resolved
@jackwotherspoon jackwotherspoon merged commit 821cef8 into main Jun 3, 2024
14 of 15 checks passed
@jackwotherspoon jackwotherspoon deleted the debug-logging branch June 3, 2024 15:51
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.

Add standardized debug logging
3 participants