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

refactor(ingest/bigquery): Standardize audit log parsing and make TopKDict a DefaultDict #7738

Merged
merged 6 commits into from
Apr 4, 2023

Conversation

asikowitz
Copy link
Collaborator

Bit again by not separating out some changes into a smaller PR. Takes changes from #7663 and extends them for lineage.py, i.e.:

  • Moves get_sanitized_table_ref calls to ReadEvent / QueryEvent creation
  • Standardizes how the audit log is read and parsed, unifying code when reading from gcp logging vs audit metadata (exported logs)
  • Adds error handling around the parsing of each event, to catch errors from the new get_sanitized_table_ref calls

Also. makes TopKDict inherit from DefaultDict and cleans up calls around that.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

…t creation; standardize audit log parsing; make TopKDict a DefaultDict
@github-actions github-actions bot added the ingestion PR or Issue related to the ingestion of metadata label Apr 1, 2023
Comment on lines -644 to -646
lineage_extractor: BigqueryLineageExtractor = BigqueryLineageExtractor(
config=self.config, report=self.report
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No clue why we were doing this... was in this code from the very first bigquery lineage PR. The only instance variables are self.config and self.report, which are passed thru anyway, so I think this should be safe to remove

raise e

def compute_bigquery_lineage_via_catalog_lineage_api(
def lineage_via_catalog_lineage_api(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed compute_bigquery_lineage_via_catalog_lineage_api to be a bit more concise

def _get_bigquery_log_entries(
self, client: GCPLoggingClient, limit: Optional[int] = None
) -> Union[Iterable[AuditLogEntry], Iterable[BigQueryAuditMetadata]]:
) -> Union[Iterable[AuditLogEntry]]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Think this is a more accurate typing. Technically it doesn't matter because both AuditLogEntry and BigQueryAuditMetadata are Any

Copy link
Collaborator

Choose a reason for hiding this comment

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

incredible

Comment on lines +418 to +420
logger.warning(
f"Unable to parse log missing {missing_entry}, missing v2 {missing_entry_v2} for {entry}",
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seemed more fitting as a log warning, rather than in the report as an error

Comment on lines +585 to +588
self.error(
logger,
"lineage",
f"{project_id}: {e}",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is to replace the self.error calls in the deleted compute_bigquery_lineage_via_gcp_logging and compute_bigquery_lineage_via_audit_metadata. Since this is catching unexpected errors and has a relatively clean message, I think this is valid to put in the report.

@@ -492,7 +487,7 @@ def _extract_operational_meta(
else:
return None

def _create_operation_aspect_work_unit(
def _create_operation_workunit(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another rename

@asikowitz asikowitz merged commit 06bc1c3 into datahub-project:master Apr 4, 2023
@asikowitz asikowitz deleted the bigquery-source-cleanup branch April 4, 2023 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ingestion PR or Issue related to the ingestion of metadata
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants