-
Notifications
You must be signed in to change notification settings - Fork 4.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
Emit multiple error trace messages and continue syncs by default #34636
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
469f82b
Emit multiple error trace messages and continue syncs by default
brianjlai 5c89869
fix flake checks
brianjlai e126c44
fix more integration tests
brianjlai d69114e
fix imports
brianjlai 28c5f0b
formatting
brianjlai 09c08de
fix discover for test connector
brianjlai fc5c5d1
Merge branch 'master' into brian/per_stream_error_reporting
brianjlai 57e8ad5
rewrite abstract_source to still emit at least one exception to ensur…
brianjlai f0cd314
remove stop_sync_on_stream_failure override from klaviyo
brianjlai b942080
only one error stream
brianjlai 91b6fa9
fix failing test but slight divergence from concurrent behavior
brianjlai 76be107
remove klaviyo pre-release testing code
brianjlai 3ff86e0
formatting and add back the original method
brianjlai 1a2c77c
remove extra comments
brianjlai 0ab8ae6
Merge branch 'master' into brian/per_stream_error_reporting
brianjlai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
ConfiguredAirbyteCatalog, | ||
ConfiguredAirbyteStream, | ||
Status, | ||
StreamDescriptor, | ||
SyncMode, | ||
) | ||
from airbyte_cdk.models import Type as MessageType | ||
|
@@ -27,6 +28,7 @@ | |
from airbyte_cdk.sources.utils.record_helper import stream_data_to_airbyte_message | ||
from airbyte_cdk.sources.utils.schema_helpers import InternalConfig, split_config | ||
from airbyte_cdk.sources.utils.slice_logger import DebugSliceLogger, SliceLogger | ||
from airbyte_cdk.utils.airbyte_secrets_utils import filter_secrets | ||
from airbyte_cdk.utils.event_timing import create_timer | ||
from airbyte_cdk.utils.stream_status_utils import as_airbyte_message as stream_status_as_airbyte_message | ||
from airbyte_cdk.utils.traced_exception import AirbyteTracedException | ||
|
@@ -133,27 +135,44 @@ def read( | |
logger.info(f"Marking stream {configured_stream.stream.name} as STOPPED") | ||
yield stream_status_as_airbyte_message(configured_stream.stream, AirbyteStreamStatus.COMPLETE) | ||
except AirbyteTracedException as e: | ||
logger.exception(f"Encountered an exception while reading stream {configured_stream.stream.name}") | ||
logger.info(f"Marking stream {configured_stream.stream.name} as STOPPED") | ||
yield stream_status_as_airbyte_message(configured_stream.stream, AirbyteStreamStatus.INCOMPLETE) | ||
if self.continue_sync_on_stream_failure: | ||
stream_name_to_exception[stream_instance.name] = e | ||
else: | ||
raise e | ||
yield e.as_sanitized_airbyte_message(stream_descriptor=StreamDescriptor(name=configured_stream.stream.name)) | ||
stream_name_to_exception[stream_instance.name] = e | ||
if self.stop_sync_on_stream_failure: | ||
logger.info( | ||
f"Stopping sync on error from stream {configured_stream.stream.name} because {self.name} does not support continuing syncs on error." | ||
) | ||
break | ||
except Exception as e: | ||
yield from self._emit_queued_messages() | ||
logger.exception(f"Encountered an exception while reading stream {configured_stream.stream.name}") | ||
logger.info(f"Marking stream {configured_stream.stream.name} as STOPPED") | ||
yield stream_status_as_airbyte_message(configured_stream.stream, AirbyteStreamStatus.INCOMPLETE) | ||
display_message = stream_instance.get_error_display_message(e) | ||
if display_message: | ||
raise AirbyteTracedException.from_exception(e, message=display_message) from e | ||
raise e | ||
traced_exception = AirbyteTracedException.from_exception(e, message=display_message) | ||
else: | ||
traced_exception = AirbyteTracedException.from_exception(e) | ||
yield traced_exception.as_sanitized_airbyte_message( | ||
stream_descriptor=StreamDescriptor(name=configured_stream.stream.name) | ||
) | ||
stream_name_to_exception[stream_instance.name] = traced_exception | ||
if self.stop_sync_on_stream_failure: | ||
logger.info(f"{self.name} does not support continuing syncs on error from stream {configured_stream.stream.name}") | ||
break | ||
finally: | ||
timer.finish_event() | ||
logger.info(f"Finished syncing {configured_stream.stream.name}") | ||
logger.info(timer.report()) | ||
|
||
if self.continue_sync_on_stream_failure and len(stream_name_to_exception) > 0: | ||
raise AirbyteTracedException(message=self._generate_failed_streams_error_message(stream_name_to_exception)) | ||
if len(stream_name_to_exception) > 0: | ||
error_message = self._generate_failed_streams_error_message(stream_name_to_exception) | ||
logger.info(error_message) | ||
# We still raise at least one exception when a stream raises an exception because the platform | ||
# currently relies on a non-zero exit code to determine if a sync attempt has failed | ||
raise AirbyteTracedException(message=error_message) | ||
logger.info(f"Finished syncing {self.name}") | ||
|
||
@property | ||
|
@@ -282,17 +301,17 @@ def message_repository(self) -> Union[None, MessageRepository]: | |
return _default_message_repository | ||
|
||
@property | ||
def continue_sync_on_stream_failure(self) -> bool: | ||
def stop_sync_on_stream_failure(self) -> bool: | ||
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. If we're 👍 w/ this interface name I can remove the warning |
||
""" | ||
WARNING: This function is in-development which means it is subject to change. Use at your own risk. | ||
|
||
By default, a source should raise an exception and stop the sync when it encounters an error while syncing a stream. This | ||
method can be overridden on a per-source basis so that a source will continue syncing streams other streams even if an | ||
exception is raised for a stream. | ||
By default, when a source encounters an exception while syncing a stream, it will emit an error trace message and then | ||
continue syncing the next stream. This can be overwridden on a per-source basis so that the source will stop the sync | ||
on the first error seen and emit a single error trace message for that stream. | ||
""" | ||
return False | ||
|
||
@staticmethod | ||
def _generate_failed_streams_error_message(stream_failures: Mapping[str, AirbyteTracedException]) -> str: | ||
failures = ", ".join([f"{stream}: {exception.__repr__()}" for stream, exception in stream_failures.items()]) | ||
failures = ", ".join([f"{stream}: {filter_secrets(exception.__repr__())}" for stream, exception in stream_failures.items()]) | ||
return f"During the sync, the following streams did not sync successfully: {failures}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
😠