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

Update fix/clean up #4066

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

NicholasTurner23
Copy link
Contributor

@NicholasTurner23 NicholasTurner23 commented Dec 13, 2024

Description

[Provide a brief description of the changes made in this PR]
Enable re-streaming of daily device measurements using the original execution date.

Summary by CodeRabbit

  • New Features
    • Added documentation for daily measurement processes, enhancing clarity on data handling.
    • Introduced three new Airflow DAGs: Cleanup, Realtime, and Historical Daily Measurements, with improved documentation links.
  • Bug Fixes
    • Enhanced error handling in DAG tasks with retry logic and context provision.

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request introduce new documentation strings and enhance the functionality of Airflow DAGs related to daily measurements in BigQuery. Three new documentation strings are added to describe processes for cleaning and aggregating device measurements. Additionally, the DAGs are updated to include these documentation strings and improve error handling by modifying task decorators to allow retries and provide context.

Changes

File Path Change Summary
src/workflows/dags/dag_docs.py Added documentation strings: daily_measurements_clean_up_doc, daily_devices_measurements_realtime_doc, and daily_devices_measurements_historical_doc.
src/workflows/dags/daily_measurements.py Updated DAGs to include doc_md linking to new documentation strings. Enhanced @task decorators for error handling with retries and context.

Possibly related PRs

Suggested reviewers

  • Baalmart
  • BenjaminSsempala

🎉 In the world of data, where measurements flow,
New docs shine brightly, helping us know.
With retries and context, our tasks now stand tall,
In BigQuery's realm, we won't let data fall!
So here's to the changes, let's give them a cheer,
For clearer insights, and progress is near! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
src/workflows/dags/dag_docs.py (1)

78-90: Documentation could be more comprehensive

The documentation would benefit from additional details in the following areas:

  • Notes section is empty but could include important information about:
    • The criteria for identifying duplicates
    • The retention policy for removed data
    • The impact on downstream processes
  • Purpose section could elaborate on why duplicate removal is necessary
src/workflows/dags/daily_measurements.py (2)

Line range hint 78-81: Add retry logic to resample task

The resample task is missing retry logic while extract and load tasks have it. Since it performs data transformations that could fail, it should have similar error handling capabilities.

Apply this diff to add retry logic:

-    @task()
+    @task(retries=3, retry_delay=timedelta(minutes=5))
     def resample(data: pd.DataFrame):

Line range hint 119-122: Standardize task configurations across the DAG

There are inconsistencies in the task configurations:

  1. The resample task is missing retry logic
  2. The load task is missing provide_context=True compared to other DAGs

Apply these diffs to standardize the configurations:

-    @task()
+    @task(retries=3, retry_delay=timedelta(minutes=5))
     def resample(data: pd.DataFrame):

-    @task(retries=3, retry_delay=timedelta(minutes=5))
+    @task(provide_context=True, retries=3, retry_delay=timedelta(minutes=5))
     def load(data: pd.DataFrame):

Also applies to: 125-126

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c54fd12 and 8c75b3d.

📒 Files selected for processing (2)
  • src/workflows/dags/dag_docs.py (1 hunks)
  • src/workflows/dags/daily_measurements.py (5 hunks)
🔇 Additional comments (1)
src/workflows/dags/daily_measurements.py (1)

4-9: LGTM! Well-structured imports

The imports are properly organized and align with the new functionality being added.

Comment on lines +106 to +118
daily_devices_measurements_historical_doc = """
### AirQo daily measurements data clean up - historical
#### Purpose
Aggregate daily device measurements using hourly devices measurements stored in bigquery going back a couple of days.
#### Notes


Data sources:
- BigQuery: daily_device_measurements
Data Destinations:
- BigQuery: daily_device_measurements
- <a href="https://airqo.africa/" target="_blank">AirQo</a>
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix title and add historical processing details

Similar to the realtime documentation, this needs attention:

  1. The title incorrectly mentions "data clean up"
  2. The Notes section should include:
    • The historical data retention period
    • How backfilling works
    • Any special handling for historical data

Apply this diff to fix the title:

-### AirQo daily measurements data clean up - historical
+### AirQo historical daily measurements aggregation

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +92 to +104
daily_devices_measurements_realtime_doc = """
### AirQo daily measurements data clean up
#### Purpose
Aggregate daily device measurements using hourly devices measurements stored in bigquery
#### Notes


Data sources:
- BigQuery: daily_device_measurements
Data Destinations:
- BigQuery: daily_device_measurements
- <a href="https://airqo.africa/" target="_blank">AirQo</a>
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect title and enhance documentation

There are a few issues with this documentation:

  1. The title incorrectly states "data clean up" when the purpose is about aggregation
  2. The Notes section could include:
    • The aggregation method used
    • The frequency of updates
    • Any data quality checks performed

Apply this diff to fix the title:

-### AirQo daily measurements data clean up
+### AirQo daily measurements aggregation

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +23 to +27
@task(
provide_context=True,
retries=3,
retry_delay=timedelta(minutes=5),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add retry logic to cleanup_and_load task

While the extract task has proper retry logic, the cleanup_and_load task is missing similar error handling. Since it performs database operations, it should also have retry capabilities.

Apply this diff to add retry logic:

-    @task()
+    @task(retries=3, retry_delay=timedelta(minutes=5))
     def cleanup_and_load(data: pd.DataFrame):

Also applies to: 41-42

@Baalmart Baalmart merged commit 78c653a into airqo-platform:staging Dec 13, 2024
46 checks passed
@Baalmart Baalmart mentioned this pull request Dec 13, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants