-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[#3078] [CDK] Add support for enabling debug from command line and some basic general debug logs #14521
Conversation
if airbyte_level == "DEBUG": | ||
extras = self.extract_extra_args_from_record(record) | ||
debug_dict = {"type": "DEBUG", "message": record.getMessage(), "data": extras} | ||
return filter_secrets(json.dumps(debug_dict)) |
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.
An alternative is to create an entirely new AirbyteDebugMessage
that supplies the same flexibility to log variables. I didn't really envision the --debug
command ever being invoked at prod level, but if it is, its definitely worth investing in a new type of message into the protocol. Otherwise I'm not married to either. Updating json creation to use a new message type isn't too massive a change here
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.
does this produce messages that are accepted by the platform? While we probably won't use --debug in production, I would imagine us using it on a dev machine or locally so we should make sure we can still run syncs with --debug
100% fine if the platform just ends up ignoring them
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.
Based on this it should treat any non message JSON as a defacto log message, might lose some prettification on the platform, but also saves us from committing Debug messages to being a first class citizen in the protocol right at this moment.
@@ -67,6 +68,12 @@ def run(self, parsed_args: argparse.Namespace) -> Iterable[str]: | |||
if not cmd: | |||
raise Exception("No command passed") | |||
|
|||
if parsed_args.debug: | |||
self.logger.setLevel(logging.DEBUG) |
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.
note: This does actually override the TRACE
debug level, but going through the code, I don't see it used anywhere and it appears to be legacy code from the deprecated custom built AirbyteDebugger that was removed in favor of pythons default logger. Also occasionally introduces bugs:
https://airbytehq-team.slack.com/archives/C02TL38U5L7/p1649731849925669
Given the lack of usage, I'm partial yanking the entire TRACE message from the logger entirely
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.
should we check the log level with self.logger.getEffectiveLevel()
and fail if it's TRACE
(and add a comment for future reference)
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.
I think the issue is that by default we used to always set the logger to TRACE
in logger.__init__
which has a value of 5. So it was inclusive of all logs higher than it. So at this moment, it will always be TRACE
and it would fail.
Something I just thought of is changing the TRACE log to 15
. And if --debug
is not present, then set level to TRACE. That way debug is exclusive by default, but we still capture TRACE at all levels. A little hacky, but TRACE is already a hack haha
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.
I'm like 99% confident we can just remove the TRACE
level (as long as it's not backwards breaking) -- do you know if that's an easy removal?
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.
Yep should be straightforward in the logger, it just the reference to the leveling and we'll use the remaining presets
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.
a bit of nitpicking, but this is
@@ -67,6 +68,12 @@ def run(self, parsed_args: argparse.Namespace) -> Iterable[str]: | |||
if not cmd: | |||
raise Exception("No command passed") | |||
|
|||
if parsed_args.debug: | |||
self.logger.setLevel(logging.DEBUG) |
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.
should we check the log level with self.logger.getEffectiveLevel()
and fail if it's TRACE
(and add a comment for future reference)
if airbyte_level == "DEBUG": | ||
extras = self.extract_extra_args_from_record(record) | ||
debug_dict = {"type": "DEBUG", "message": record.getMessage(), "data": extras} | ||
return filter_secrets(json.dumps(debug_dict)) |
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.
does this produce messages that are accepted by the platform? While we probably won't use --debug in production, I would imagine us using it on a dev machine or locally so we should make sure we can still run syncs with --debug
100% fine if the platform just ends up ignoring them
@@ -142,7 +150,7 @@ def _read_stream( | |||
connector_state: MutableMapping[str, Any], | |||
internal_config: InternalConfig, | |||
) -> Iterator[AirbyteMessage]: | |||
|
|||
self._apply_log_level_to_stream_logger(logger, stream_instance) |
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.
should this be applied on line https://github.com/airbytehq/airbyte/pull/14521/files#diff-51c861828e0a614ef6ee21390f3ba17d7138549f0575051fdb24868ee05eabbbR106 just in case?
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.
I think we should be in the clear because the logger passed into the read()
method is always coming from entrypoint()
which is the source level logger and is already set.
Although I'm gonna move the debug statement you mentioned down a level to the stream level since it makes more sense for it to be logged by the stream logger instead of source logger
@@ -14,6 +14,7 @@ class YamlDeclarativeSource(DeclarativeSource): | |||
def __init__(self, path_to_yaml): | |||
self._factory = DeclarativeComponentFactory() | |||
self._source_config = self._read_and_parse_yaml_file(path_to_yaml) | |||
self.logger = logging.getLogger(f"airbyte.{self.name or ''}") |
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.
what would cause self.name
to be None?
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.
Probably me just being overly cautious, will remove.
parsed_config = YamlParser().parse(config_content) | ||
self.logger.debug( | ||
"parsed YAML into declarative source", | ||
extra={"path_to_yaml_file": path_to_yaml_file, "source_name": self.name, "parsed_config": parsed_config}, |
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.
very nice
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.
This looks great! One requested addition: can you add a note in the docs which tells a developer they can use the --debug
flag when developing their own connector or when contributing to the CDK itself?
@@ -67,6 +68,12 @@ def run(self, parsed_args: argparse.Namespace) -> Iterable[str]: | |||
if not cmd: | |||
raise Exception("No command passed") | |||
|
|||
if parsed_args.debug: | |||
self.logger.setLevel(logging.DEBUG) |
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.
I'm like 99% confident we can just remove the TRACE
level (as long as it's not backwards breaking) -- do you know if that's an easy removal?
logger.debug( | ||
f"Syncing stream: {configured_stream.stream.name}", | ||
extra={ | ||
"stream_name": configured_stream.stream.name, |
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.
nit: extraneous since stream name is already in the above formatted string
"stream_name": configured_stream.stream.name, |
@@ -286,8 +286,11 @@ def _send(self, request: requests.PreparedRequest, request_kwargs: Mapping[str, | |||
Unexpected transient exceptions use the default backoff parameters. | |||
Unexpected persistent exceptions are not handled and will cause the sync to fail. | |||
""" | |||
self.logger.debug( | |||
"Making outbound API request", extra={"headers": request.headers, "url": request.url, "request_body": request.body} |
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.
url includes qparams right?
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.
yup!
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.
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.
Addresses: #3078
What
Adds the ability for custom debug statements to be emitted to stdout (same as airbyte messages and logs) when running a connector locally using the
--debug
command. An example would look like:python main.py read --config secrets/config_oauth.json --catalog sample_files/basic_read_oauth_catalog.json --debug | jq
There are some general debug statements added to the CDK that provide helpful context out of the box, but custom debug statements at the CDK or connector level can also be added. It also allows for custom fields to be passed via
extra
instead of just crammed into the string message:It would then be presented as a debug in the output:
How
We primarily leverage the existing debugger to handle filtering and formatting of logs according to the set log level. Using the
--debug
flag to determine whether the log level is set toINFO
orDEBUG
accordingly. There are a few little tricks that needed to be done to propagate the log level since streams and the source emit using different logger names.There's also some custom formatting to make writing new logs a little nicer and make them easier to read in stdout.
Recommended reading order
logger.py
entrypoint.py
abstract_source.py
🚨 User Impact 🚨
Are there any breaking changes? What is the end result perceived by the user? If yes, please merge this PR with the 🚨🚨 emoji so changelog authors can further highlight this if needed.
Pre-merge Checklist
Expand the relevant checklist and delete the others.
New Connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampledocs/integrations/README.md
airbyte-integrations/builds.md
Airbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereUpdating a connector
Community member or Airbyter
airbyte_secret
./gradlew :airbyte-integrations:connectors:<name>:integrationTest
.README.md
bootstrap.md
. See description and examplesdocs/integrations/<source or destination>/<name>.md
including changelog. See changelog exampleAirbyter
If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.
/test connector=connectors/<name>
command is passing/publish
command described hereConnector Generator
-scaffold
in their name) have been updated with the latest scaffold by running./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates
then checking in your changesTests
Unit
Put your unit tests output here.
Integration
Put your integration tests output here.
Acceptance
Put your acceptance tests output here.