-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(redshift): Improve redshift error handling with new structur…
…ed reporting system (#10870) Co-authored-by: John Joyce <[email protected]> Co-authored-by: Harshal Sheth <[email protected]>
- Loading branch information
1 parent
43ae12f
commit 8967db0
Showing
8 changed files
with
231 additions
and
42 deletions.
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.