Conversation
…ery queue + Rabbitmq in order to run queue every hour using airflow
Summary of ChangesHello @LuisJG8, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes a robust integration between Airflow and Celery, leveraging RabbitMQ as a message broker, all orchestrated within a shared Docker network. The primary goal is to enable Airflow to schedule and trigger Celery tasks hourly for data processing, enhancing the system's distributed task execution capabilities. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request establishes a shared Docker network to integrate Airflow with your Celery and RabbitMQ services. While enabling intended functionality, it introduces a security risk by exposing unauthenticated services, specifically Redis, on the shared network (etl-shared), increasing the attack surface. It is recommended to secure the Redis instance with a password and review the necessity of exposing RabbitMQ and Flower ports to the host if they are only for internal container communication. Additionally, the review suggests improving the new Airflow DAG by promoting best practices like using Airflow Connections for secrets and parameterizing tasks, and cleaning up the Docker Compose configuration for better maintainability.
| networks: | ||
| - etl-shared |
There was a problem hiding this comment.
The Redis service is configured without authentication and is being added to an external shared network (etl-shared). This allows any other container on the same host that joins this network to access the Redis instance without a password. Since Redis is used as a Celery backend, an attacker on the same network could read or manipulate task results, potentially leading to data corruption or unauthorized access to processed information. It is highly recommended to secure Redis with a password and ensure that the shared network is restricted to only necessary services.
| broker = os.getenv('CELERY_BROKER_URL'), | ||
| backend = os.getenv('CELERY_BACKEND_URL') |
There was a problem hiding this comment.
Using os.getenv to fetch connection details directly within a DAG is not a recommended practice. It makes the DAG less portable and harder to manage as it creates a tight coupling with the execution environment's environment variables. A more robust and secure approach is to use Airflow Connections. You can store your broker and backend URLs as a Celery connection in the Airflow UI and then retrieve them in your DAG using an Airflow hook. This centralizes connection management and enhances security.
| @task | ||
| def run_the_queue(): | ||
| print("hello") | ||
| app.send_task("worker.get_github_data", args=[0, 500]) |
There was a problem hiding this comment.
The arguments 0 and 500 are hardcoded in the send_task call. This limits the DAG's flexibility and reusability. To make this task more dynamic, consider using Airflow's params feature. You can define default values in the @dag decorator and override them when triggering the DAG manually.
For example:
@dag(
# ... other arguments
params={"start_in_repo_num": 0, "batch_size": 500},
)You would then access these parameters within your task via the task context.
|
|
||
| networks: | ||
| etl-shared: | ||
| external: true No newline at end of file |
| networks: | ||
| etl-shared: | ||
| external: true No newline at end of file |
There was a problem hiding this comment.
The etl-shared network is defined as external in both docker-compose.yml and airflow/docker-compose.override.yml. This is redundant. To adhere to the DRY (Don't Repeat Yourself) principle, it's best to define the network in a single location. Since docker-compose.yml serves as the base configuration, I recommend keeping the definition here and removing the networks block from airflow/docker-compose.override.yml.
|
|
||
| networks: | ||
| etl-shared: | ||
| external: true No newline at end of file |
created a shared Docker network and added airflow (astro cli) and Celery queue + Rabbitmq in order to run queue every hour using airflow