forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add metadata gcs sensor to Dagster (airbytehq#25055)
* Add solution skeleton * Add metadata blob resource * Wire up sensor * Fix report * Materialize metadata definitions from folder * Move metadata to own file * Run black * Add PR comments * Remove dockerhub from action
- Loading branch information
1 parent
7fc4bd8
commit e20d844
Showing
14 changed files
with
188 additions
and
44 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
2 changes: 2 additions & 0 deletions
2
airbyte-ci/connectors/metadata_service/lib/metadata_service/constants.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,2 @@ | ||
METADATA_FILE_NAME = "metadata.yaml" | ||
METADATA_FOLDER = "metadata" |
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
1 change: 1 addition & 0 deletions
1
airbyte-ci/connectors/metadata_service/orchestrator/orchestrator/config.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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
CATALOG_FOLDER = "catalogs" | ||
REPORT_FOLDER = "generated_reports" | ||
|
||
CONNECTOR_REPO_NAME = "airbytehq/airbyte" | ||
CONNECTORS_PATH = "airbyte-integrations/connectors" |
1 change: 1 addition & 0 deletions
1
airbyte-ci/connectors/metadata_service/orchestrator/orchestrator/jobs/catalog.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
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
44 changes: 44 additions & 0 deletions
44
airbyte-ci/connectors/metadata_service/orchestrator/orchestrator/sensors/metadata.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,44 @@ | ||
from dagster import sensor, RunRequest, SkipReason, SensorDefinition, SensorEvaluationContext, build_resources, DefaultSensorStatus | ||
from orchestrator.utils.dagster_helpers import deserialize_composite_etags_cursor, serialize_composite_etags_cursor | ||
|
||
|
||
def metadata_updated_sensor(job, resources_def) -> SensorDefinition: | ||
""" | ||
This sensor is responsible for polling the metadata folder in GCS for new or updated metadata files. | ||
If it notices that the etags have changed, it will trigger the given job. | ||
""" | ||
|
||
@sensor( | ||
name=f"{job.name}_on_metadata_updated", | ||
job=job, | ||
minimum_interval_seconds=30, | ||
default_status=DefaultSensorStatus.STOPPED, | ||
) | ||
def metadata_updated_sensor_definition(context: SensorEvaluationContext): | ||
context.log.info("Starting gcs_metadata_updated_sensor") | ||
|
||
with build_resources(resources_def) as resources: | ||
context.log.info("Got resources for gcs_metadata_updated_sensor") | ||
|
||
etags_cursor_raw = context.cursor or None | ||
etags_cursor = deserialize_composite_etags_cursor(etags_cursor_raw) | ||
etags_cursor_set = set(etags_cursor) | ||
|
||
context.log.info(f"Old etag cursor: {etags_cursor}") | ||
|
||
metadata_file_blobs = resources.metadata_file_blobs | ||
new_etags_cursor_set = {blob.etag for blob in metadata_file_blobs} | ||
context.log.info(f"New etag cursor: {new_etags_cursor_set}") | ||
|
||
# Note: ETAGs are GCS's way of providing a version number for a file | ||
# Another option would be to use the last modified date or MD5 hash | ||
if etags_cursor_set == new_etags_cursor_set: | ||
context.log.info("No new updated_metadata_files in GCS bucket") | ||
return SkipReason("No new updated_metadata_files in GCS bucket") | ||
|
||
serialized_new_etags_cursor = serialize_composite_etags_cursor(list(new_etags_cursor_set)) | ||
context.update_cursor(serialized_new_etags_cursor) | ||
context.log.info("New updated_metadata_files in GCS bucket") | ||
return RunRequest(run_key="updated_metadata_files") | ||
|
||
return metadata_updated_sensor_definition |
Oops, something went wrong.