-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
refactor(redshift): Improve redshift error handling with new structured reporting system #10870
Merged
hsheth2
merged 7 commits into
datahub-project:master
from
jjoyce0510:jj--add-error-handling-redshift
Jul 15, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fcd31c3
Adding redshift error handling
118b337
Merge remote-tracking branch 'acryl/jj--add-error-handling-redshift' …
31f5788
Revert bad changes
116d315
Update metadata-ingestion/src/datahub/ingestion/source/ge_data_profil…
jjoyce0510 3aae262
Update metadata-ingestion/src/datahub/ingestion/source/redshift/redsh…
jjoyce0510 2655152
Addressing comments
c8819dd
Adding comment
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
65 changes: 65 additions & 0 deletions
65
metadata-ingestion/src/datahub/ingestion/source/redshift/exception.py
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from typing import Callable, Iterable, TypeVar, Union | ||
|
||
import redshift_connector | ||
from typing_extensions import ParamSpec | ||
|
||
from datahub.ingestion.source.redshift.report import RedshiftReport | ||
|
||
T = TypeVar("T") | ||
P = ParamSpec("P") | ||
|
||
|
||
def handle_redshift_exceptions( | ||
report: RedshiftReport, | ||
func: Callable[P, T], | ||
*args: P.args, | ||
**kwargs: P.kwargs, | ||
) -> Union[T, None]: | ||
try: | ||
return func(*args, **kwargs) | ||
except redshift_connector.Error as e: | ||
report_redshift_failure(report, e) | ||
return None | ||
|
||
|
||
def handle_redshift_exceptions_yield( | ||
report: RedshiftReport, | ||
func: Callable[P, Iterable[T]], | ||
*args: P.args, | ||
**kwargs: P.kwargs, | ||
) -> Iterable[T]: | ||
try: | ||
yield from func(*args, **kwargs) | ||
except redshift_connector.Error as e: | ||
report_redshift_failure(report, e) | ||
|
||
|
||
def report_redshift_failure( | ||
report: RedshiftReport, e: redshift_connector.Error | ||
) -> None: | ||
error_message = str(e).lower() | ||
if "permission denied" in error_message: | ||
if "svv_table_info" in error_message: | ||
report.report_failure( | ||
title="Permission denied", | ||
message="Failed to extract metadata due to insufficient permission to access 'svv_table_info' table. Please ensure the provided database user has access.", | ||
exc=e, | ||
) | ||
elif "svl_user_info" in error_message: | ||
report.report_failure( | ||
title="Permission denied", | ||
message="Failed to extract metadata due to insufficient permission to access 'svl_user_info' table. Please ensure the provided database user has access.", | ||
exc=e, | ||
) | ||
else: | ||
report.report_failure( | ||
title="Permission denied", | ||
message="Failed to extract metadata due to insufficient permissions.", | ||
exc=e, | ||
) | ||
else: | ||
report.report_failure( | ||
title="Failed to extract some metadata", | ||
message="Failed to extract some metadata from Redshift.", | ||
exc=e, | ||
) |
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
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
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
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.
not a huge fan of this pattern - ideally error handling code should be close to the code that causes the errors, especially for these sorts of cases where the error message is extremely custom
For the generic permission denied / failed to extract metadata, they're fine here. But the svv and svl table ones feel like they should be caught closer to the cause of the error
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.
These happen in like 3 places across lineage, usage, and just normal table stuff.
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.
Also the code is a mess in there so I think this fallback is okay.
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.
In general I agree though that this is too much of a fallback, but in this case it would be a pretty significant undertaking to cover each place we are issuing queries via the client object
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.
(And this covered the cases I tested with a new sample user who I progressively added privileges for)
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.
You can also see I'm just catching the "redshift" connector errors here as of now, also. So it's fairly targeted to mean that the exception came from a redshift connector call.