Skip to content

Add script for migrating environment from Composer 2 to Composer 3 #13300

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 1 commit into from
Apr 17, 2025

Conversation

FilipStefaniuk
Copy link
Contributor

Description

Add script for migrating Composer 2 to Composer 3.

Checklist

@FilipStefaniuk FilipStefaniuk requested review from a team as code owners April 11, 2025 12:39
@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: composer Issues related to the Cloud Composer API. labels Apr 11, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @FilipStefaniuk, 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!

Summary of Changes

This pull request introduces a new script, composer_migrate.py, designed to facilitate the migration of Google Cloud Composer environments from version 2 to version 3. The script automates the process of creating a new Composer 3 environment with a configuration mirroring the source Composer 2 environment, pausing DAGs, saving a snapshot of the Composer 2 environment, loading it into the new Composer 3 environment, and then unpausing the DAGs that were active in the source environment. The PR also includes a markdown document composer_migrate.md that describes how to use the new script.

Highlights

  • Migration Script: Adds composer_migrate.py, a standalone script to migrate Composer 2 environments to Composer 3 using snapshots.
  • Configuration Conversion: Includes logic to convert Composer 2 environment configurations to compatible Composer 3 configurations, adjusting CPU, memory, and storage settings.
  • DAG Management: Automates pausing DAGs in the source environment before migration and unpausing them in the target environment after the snapshot is loaded.
  • Documentation: Provides a composer_migrate.md document detailing the script's usage, prerequisites, limitations, and troubleshooting steps.

Changelog

  • composer/tools/composer_migrate.md
    • Introduces a new markdown document explaining the usage of the composer_migrate.py script.
    • Details the prerequisites, limitations, and troubleshooting steps for migrating Composer 2 environments to Composer 3.
    • Provides examples for dry run and migration execution.
  • composer/tools/composer_migrate.py
    • Adds a new Python script for migrating Composer 2 environments to Composer 3.
    • Implements functions to interact with the Composer API using gcloud and curl.
    • Includes logic to fetch environment configurations, create new environments, pause/unpause DAGs, and save/load snapshots.
    • Adds functions to adjust workload configurations (CPU, memory, storage) for compatibility with Composer 3.
    • Implements a main function to orchestrate the migration process and command-line argument parsing.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and 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 to provide feedback.

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.


From two to three it goes,
Composer's versioning flows,
Snapshots pave the way,
To a brighter, newer day,
DAGs rise where old code shows.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a script to migrate Composer 2 environments to Composer 3, which is a valuable tool. The script automates the process of obtaining configurations, creating new environments, pausing/unpausing DAGs, and saving/loading snapshots. The documentation is also well-written and provides clear instructions on how to use the script. However, there are some areas that could be improved, particularly in error handling and validation.

Summary of Findings

  • Missing Error Handling: The script lacks comprehensive error handling, especially for gcloud commands. This could lead to unexpected failures and difficulties in troubleshooting. Adding more robust error handling would improve the script's reliability.
  • Missing Input Validation: The script does not perform sufficient validation of input parameters or environment configurations. This could cause the script to fail if the source environment has unsupported configurations or if the target Airflow version is incompatible. Input validation is crucial for preventing unexpected errors.
  • Potential Race Condition in DAG Pausing: Pausing DAGs one by one can be time-consuming and may lead to inconsistencies if DAGs are modified during the process. Consider pausing DAGs in batches or providing an option to pause them manually before running the script.

Merge Readiness

The pull request introduces a useful script with clear documentation. However, the identified issues related to error handling, input validation, and DAG pausing should be addressed before merging. Addressing these points will significantly improve the script's reliability and usability. I am unable to approve this pull request, and recommend that other reviewers also look at this code before merging.

@FilipStefaniuk FilipStefaniuk changed the title Add script for migrations from Composer 2 to Composer 3. Add script for migrating environment from Composer 2 to Composer 3. Apr 11, 2025
@FilipStefaniuk FilipStefaniuk changed the title Add script for migrating environment from Composer 2 to Composer 3. Add script for migrating environment from Composer 2 to Composer 3 Apr 11, 2025
@rbiegacz
Copy link

Reviewed.

@leahecole
Copy link
Collaborator

LGTM, talked to @FilipStefaniuk offline and I know this script has tests in g3, which is totally appropriate for this tool. @rbiegacz if you approve on Github we'll be able to merge!

@michalmodras michalmodras merged commit 2ed7720 into GoogleCloudPlatform:main Apr 17, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: composer Issues related to the Cloud Composer API. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants