-
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
feat(ingestion): file-based state checkpoint provider #9029
Merged
hsheth2
merged 14 commits into
datahub-project:master
from
shubhamjagtap639:file-based-checkpoint-provider
Nov 10, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1bd06b9
File checkpointing provider code and test case added
shubhamjagtap639 39439ee
Code modified as per review comment
shubhamjagtap639 c976462
Code modified as per review comment
shubhamjagtap639 03e2348
Refector lookml stateful ingetion test case
shubhamjagtap639 acdc248
Code changes as per review comment
shubhamjagtap639 82b657b
dummy source and stateful ingestion test cases added
shubhamjagtap639 43ea9fe
Restore deleted golden file
shubhamjagtap639 4bed619
Merge branch 'master' into file-based-checkpoint-provider
shubhamjagtap639 69b75e6
Both Ingestion checkpoint provider class create method modified
shubhamjagtap639 084364d
Test cases for stateful ingestion and its provider modified
shubhamjagtap639 7866081
stateful ingestion test configs modified
shubhamjagtap639 f6bacd2
file formatted
shubhamjagtap639 777e743
Code changes as per review comments
shubhamjagtap639 202b73e
Ingestion checkpoint provider test case modified
shubhamjagtap639 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
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
108 changes: 108 additions & 0 deletions
108
...tion/src/datahub/ingestion/source/state_provider/file_ingestion_checkpointing_provider.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,108 @@ | ||
import logging | ||
import pathlib | ||
from datetime import datetime | ||
from typing import Any, Dict, List, Optional | ||
|
||
from datahub.emitter.mcp import MetadataChangeProposalWrapper | ||
from datahub.ingestion.api.common import PipelineContext | ||
from datahub.ingestion.api.ingestion_job_checkpointing_provider_base import ( | ||
IngestionCheckpointingProviderBase, | ||
IngestionCheckpointingProviderConfig, | ||
JobId, | ||
) | ||
from datahub.ingestion.sink.file import write_metadata_file | ||
from datahub.ingestion.source.file import read_metadata_file | ||
from datahub.metadata.schema_classes import DatahubIngestionCheckpointClass | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class FileIngestionStateProviderConfig(IngestionCheckpointingProviderConfig): | ||
filename: str | ||
|
||
|
||
class FileIngestionCheckpointingProvider(IngestionCheckpointingProviderBase): | ||
orchestrator_name: str = "file" | ||
|
||
def __init__(self, config: FileIngestionStateProviderConfig): | ||
super().__init__(self.__class__.__name__) | ||
self.config = config | ||
|
||
@classmethod | ||
def create( | ||
cls, config_dict: Dict[str, Any], ctx: PipelineContext | ||
) -> "FileIngestionCheckpointingProvider": | ||
config = FileIngestionStateProviderConfig.parse_obj(config_dict) | ||
return cls(config) | ||
|
||
def get_latest_checkpoint( | ||
self, | ||
pipeline_name: str, | ||
job_name: JobId, | ||
) -> Optional[DatahubIngestionCheckpointClass]: | ||
logger.debug( | ||
f"Querying for the latest ingestion checkpoint for pipelineName:'{pipeline_name}'," | ||
f" job_name:'{job_name}'" | ||
) | ||
|
||
data_job_urn = self.get_data_job_urn( | ||
self.orchestrator_name, pipeline_name, job_name | ||
) | ||
latest_checkpoint: Optional[DatahubIngestionCheckpointClass] = None | ||
try: | ||
for obj in read_metadata_file(pathlib.Path(self.config.filename)): | ||
if ( | ||
isinstance(obj, MetadataChangeProposalWrapper) | ||
and obj.entityUrn == data_job_urn | ||
and obj.aspect | ||
and isinstance(obj.aspect, DatahubIngestionCheckpointClass) | ||
and obj.aspect.get("pipelineName", "") == pipeline_name | ||
): | ||
latest_checkpoint = obj.aspect | ||
break | ||
except FileNotFoundError: | ||
logger.debug(f"File {self.config.filename} not found") | ||
|
||
if latest_checkpoint: | ||
logger.debug( | ||
f"The last committed ingestion checkpoint for pipelineName:'{pipeline_name}'," | ||
f" job_name:'{job_name}' found with start_time:" | ||
f" {datetime.utcfromtimestamp(latest_checkpoint.timestampMillis/1000)}" | ||
) | ||
return latest_checkpoint | ||
else: | ||
logger.debug( | ||
f"No committed ingestion checkpoint for pipelineName:'{pipeline_name}'," | ||
f" job_name:'{job_name}' found" | ||
) | ||
|
||
return None | ||
|
||
def commit(self) -> None: | ||
if not self.state_to_commit: | ||
logger.warning(f"No state available to commit for {self.name}") | ||
return None | ||
|
||
checkpoint_workunits: List[MetadataChangeProposalWrapper] = [] | ||
for job_name, checkpoint in self.state_to_commit.items(): | ||
# Emit the ingestion state for each job | ||
logger.debug( | ||
f"Committing ingestion checkpoint for pipeline:'{checkpoint.pipelineName}', " | ||
f"job:'{job_name}'" | ||
) | ||
datajob_urn = self.get_data_job_urn( | ||
self.orchestrator_name, | ||
checkpoint.pipelineName, | ||
job_name, | ||
) | ||
checkpoint_workunits.append( | ||
MetadataChangeProposalWrapper( | ||
entityUrn=datajob_urn, | ||
aspect=checkpoint, | ||
) | ||
) | ||
write_metadata_file(pathlib.Path(self.config.filename), checkpoint_workunits) | ||
self.committed = True | ||
logger.debug( | ||
f"Committed all ingestion checkpoints for pipeline:'{checkpoint.pipelineName}'" | ||
) |
26 changes: 26 additions & 0 deletions
26
metadata-ingestion/tests/integration/lookml/golden_test_state.json
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,26 @@ | ||
[ | ||
{ | ||
"entityType": "dataJob", | ||
"entityUrn": "urn:li:dataJob:(urn:li:dataFlow:(file,lookml_stateful,prod),lookml_stale_entity_removal)", | ||
"changeType": "UPSERT", | ||
"aspectName": "datahubIngestionCheckpoint", | ||
"aspect": { | ||
"json": { | ||
"timestampMillis": 1586847600000, | ||
"partitionSpec": { | ||
"type": "FULL_TABLE", | ||
"partition": "FULL_TABLE_SNAPSHOT" | ||
}, | ||
"pipelineName": "lookml_stateful", | ||
"platformInstanceId": "", | ||
"config": "", | ||
"state": { | ||
"formatVersion": "1.0", | ||
"serde": "base85-bz2-json", | ||
"payload": "LRx4!F+o`-Q(4)<4JiNuUmt)_WdINa0@Mn>@BivB0a-v1sF;Ar&}h&A0K-EjK*+=xnKU%Oib;?JVrrXB7?aRqCarWwpZm8v5Yh+DsN{|c*msMh9%WJXjKPvIPsDn^@g3;DD9Q9kBh?*|=8M4uRW$_0HKn3XhN;RhAcLIBhLnO2%UA@Ykl;h&Xx(^@2;Y9C#d4g3K_2CA-I*M)h{NMA8Nu4C3XjEQYdh{nR--&lfRUsTL}OOkOO435f=1nKzYJ^9)mbBljM0}gaqy26URw1=q<80Eb9y)y?Vl88kG;g~MToq#r%6tr<yx^i_E#v)8~7vUJum>K9U`U?k}RS<@^?i@<c?y}RaZG9JGf09m`0f!sz%!^wDYcoJR{ix%d2rWCL+XvG>1M1@9*%tk}1N3hRzUaNB" | ||
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. eventually I'd like to change this so that the compression is tied to the state provider, not the checkpoint object - but we can save that for a future PR |
||
}, | ||
"runId": "lookml-test" | ||
} | ||
} | ||
} | ||
] |
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.
this should remain optional
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 is no use of making it optional. It will just add the extra useless if condition of checking datahub_api because of lint error.
Still if it needs to remain optional let me know.