-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/issue111 #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
499ed77
add data uploading session and also add its sample code
satoshi-kondo 9dfd5fd
refactor: introduce BaseSession to eliminate code duplication across …
satoshi-kondo 323a109
refactor test code
satoshi-kondo dc0e899
update document
satoshi-kondo 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,187 @@ | ||
| """ | ||
| Wasabi Data Upload Session Example | ||
|
|
||
| This example demonstrates a complete Wasabi data upload session: | ||
| 1. Send START event when upload begins with nominal time period | ||
| 2. Simulate data upload to Wasabi cloud storage | ||
| 3. Send COMPLETE event when upload ends | ||
|
|
||
| It shows how to: | ||
| - Use WasabiUploadSession class to manage upload session lifecycle | ||
| - Create CommonRunFacet with robot and repository information | ||
| - Automatically track run_id without manual management | ||
| - Specify robot_id and location to identify the robot and its location | ||
| - Specify repository information (hash, URI, tag, branch) for traceability | ||
| - Specify nominal time period (the time range of data being processed) | ||
| - Use facet_prefix to namespace custom facets (e.g., "airoa_common") | ||
| - Track a complete Wasabi data upload session with OpenLineage | ||
| """ | ||
|
|
||
| import os | ||
| import time | ||
| from datetime import datetime, timedelta, timezone | ||
|
|
||
| from airoa_lineage.facets import CommonRunFacet | ||
| from airoa_lineage.marquez_client import MarquezClient | ||
| from airoa_lineage.wasabi_upload import WasabiUploadSession | ||
|
|
||
|
|
||
| def main(): | ||
| """Run a complete Wasabi data upload session simulation.""" | ||
|
|
||
| # Session configuration | ||
| marquez_url = os.getenv("MARQUEZ_URL", "http://localhost:9000") | ||
| namespace = "airoa_examples" | ||
| job_name = "wasabi-data-upload" | ||
|
|
||
| # Robot and repository information | ||
| robot_id = "hsr001" # Robot identifier | ||
| location = "weblab" # Location identifier | ||
| repository_hash = "df110d5" # Git commit hash | ||
| repository_uri = "https://github.com/AIRoA/airoa-lineage.git" # Repository URL | ||
| repository_tag = "v1.0.0" # Git tag | ||
| repository_branch = "main" # Git branch | ||
|
|
||
| # Calculate nominal time period (data time range) | ||
| # nominal_start: 1 day ago from now | ||
| # nominal_end: 5 hours after nominal_start | ||
| now = datetime.now(timezone.utc) | ||
| nominal_start = now - timedelta(days=1) | ||
| nominal_end = nominal_start + timedelta(hours=5) | ||
|
|
||
| # Create common facet with robot and repository information | ||
| common_facet = CommonRunFacet( | ||
| robotId=robot_id, | ||
| location=location, | ||
| repositoryHash=repository_hash, | ||
| repositoryUri=repository_uri, | ||
| repositoryTag=repository_tag, | ||
| repositoryBranch=repository_branch, | ||
| ) | ||
|
|
||
| # Create session instance | ||
| # This automatically generates a run_id and initializes the Marquez client | ||
| # Using facet_prefix="airoa" to namespace our custom facets | ||
| session = WasabiUploadSession( | ||
| namespace=namespace, | ||
| common_facet=common_facet, | ||
| job_name=job_name, | ||
| marquez_url=marquez_url, | ||
| facet_prefix="airoa", | ||
| ) | ||
|
|
||
| print("=" * 60) | ||
| print("Wasabi Data Upload Session Example") | ||
| print("=" * 60) | ||
| print(f"Namespace: {namespace}") | ||
| print(f"Job Name: {job_name}") | ||
| print() | ||
| print("Robot & Repository Information:") | ||
| print(f" Robot ID: {robot_id}") | ||
| print(f" Location: {location}") | ||
| print(f" Repo Hash: {repository_hash}") | ||
| print(f" Repo URI: {repository_uri}") | ||
| print(f" Repo Tag: {repository_tag}") | ||
| print(f" Repo Branch: {repository_branch}") | ||
| print() | ||
| print(f"Run ID: {session.run_id}") | ||
| print(f"Marquez: {marquez_url}") | ||
| print() | ||
| print("Nominal Time Period (data time range):") | ||
| print(f" Start: {nominal_start.isoformat()}") | ||
| print(f" End: {nominal_end.isoformat()}") | ||
| print() | ||
|
|
||
| # ========== START Event ========== | ||
| print("[1/4] Sending START event...") | ||
|
|
||
| # Send START event with nominal time period | ||
| # This specifies the time range of the data being processed | ||
| session.start( | ||
| nominal_start_time=nominal_start.isoformat(), | ||
| nominal_end_time=nominal_end.isoformat(), | ||
| ) | ||
|
|
||
| print("✓ START event sent successfully") | ||
| print() | ||
|
|
||
| # ========== Simulate Data Upload ========== | ||
| print("[2/4] Simulating data upload to Wasabi...") | ||
|
|
||
| # In a real scenario, this is where you would: | ||
| # - Prepare data files for upload | ||
| # - Connect to Wasabi S3-compatible API | ||
| # - Upload files to Wasabi bucket | ||
| # - Verify upload integrity | ||
| upload_duration = 3 # seconds | ||
| time.sleep(upload_duration) | ||
|
|
||
| print(f"✓ Data upload completed ({upload_duration} seconds)") | ||
| print(" - In a real scenario, this would:") | ||
| print(" • Prepare data files for upload") | ||
| print(" • Connect to Wasabi S3-compatible API") | ||
| print(" • Upload files to Wasabi bucket") | ||
| print(" • Verify upload integrity") | ||
| print() | ||
|
|
||
| # ========== COMPLETE Event ========== | ||
| print("[3/4] Sending COMPLETE event...") | ||
|
|
||
| # Send COMPLETE event using the session | ||
| # This sends an OpenLineage COMPLETE event to Marquez | ||
| session.complete() | ||
|
|
||
| print("✓ COMPLETE event sent successfully") | ||
| print() | ||
|
|
||
| # ========== Query Lineage ========== | ||
| print("[4/4] Querying job information...") | ||
| time.sleep(1) # Give Marquez time to process | ||
|
|
||
| try: | ||
| # Initialize client to query job information | ||
| client = MarquezClient(marquez_url, namespace=namespace) | ||
|
|
||
| # Query job information | ||
| job = client.get_job(job_name) | ||
| print("✓ Job information retrieved:") | ||
| print(f" - Latest run state: {job.get('latestRun', {}).get('state', 'N/A')}") | ||
| print(f" - Job type: {job.get('type', 'N/A')}") | ||
| print() | ||
|
|
||
| except Exception as e: | ||
| print(f"⚠ Failed to query job: {e}") | ||
| print(" (This is expected if Marquez is still processing the events)") | ||
| print() | ||
|
|
||
| # ========== Summary ========== | ||
| print("=" * 60) | ||
| print("Session Summary") | ||
| print("=" * 60) | ||
| print("✓ Wasabi data upload session completed successfully") | ||
| print(f"✓ Robot ID: {robot_id}") | ||
| print(f"✓ Location: {location}") | ||
| print(f"✓ Repository: {repository_uri}") | ||
| print(f"✓ Commit: {repository_hash} ({repository_branch})") | ||
| print(f"✓ Tag: {repository_tag}") | ||
| print(f"✓ Run ID: {session.run_id}") | ||
| print() | ||
| print("Next steps:") | ||
| print("1. View lineage in Marquez Web UI:") | ||
| print( | ||
| f" {marquez_url.replace(':9000', ':3000')}/lineage/job/{namespace}/{job_name}" | ||
| ) | ||
| print() | ||
| print("2. Query job via API:") | ||
| print(f" curl {marquez_url}/api/v1/namespaces/{namespace}/jobs/{job_name}") | ||
| print() | ||
| print("3. Query this specific run:") | ||
| print( | ||
| f" curl {marquez_url}/api/v1/namespaces/{namespace}/jobs/{job_name}/runs/{session.run_id}" | ||
| ) | ||
| print() | ||
| print("=" * 60) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Wasabiという固有サービス名に限定しないほうが良いのかなとちょっと思いましたがNITSです。
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.
おっしゃるとおりで、USB のところもどうしようかなと思いました。
現状では USB や Wasabi の方が直感的でわかりやすいですし、ストレージが変わるタイミングがあれば、Rename するだけでコストは掛からないので、一旦、わかりやすさをとった感じです。