-
Notifications
You must be signed in to change notification settings - Fork 0
isolate prefect resources by environment #207
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
87 commits
Select commit
Hold shift + click to select a range
60a0804
GTC-3451 Add TCL pipeline
manukala6 816b544
Merge branch 'main' into feature/tcl_pipeline
manukala6 ddc4959
GTC-3451 Sum carbon emissions with pixel area for TCL
manukala6 baac141
Merge branch 'feature/tcl_pipeline' of https://github.com/wri/project…
manukala6 519f202
Merge branch 'main' into feature/tcl_pipeline
manukala6 4ab5970
GTC-3451 Add ifl, drivers, primary forest contextual layers
manukala6 e2a69a3
GTC-3451 Correct contextual column names
manukala6 89ba809
GTC-3451 Align schema with TCL parquet
manukala6 a28d145
GTC-3451 TCL unit tests
manukala6 824be97
Make test dataset repository still use geometry mask
jterry64 b665440
Merge branch 'main' of https://github.com/wri/project-zeno-data-infra
jterry64 7b325b4
GTC-3451 TCL integration test
manukala6 3fabb91
Merge branch 'main' into feature/tcl_pipeline
manukala6 e513f48
Merge branch 'main' of https://github.com/wri/project-zeno-data-infra
jterry64 b865b7e
GTC-3451 Refactor to use xr.concat() for handling mismatched sparsity…
manukala6 2cc3d0b
Merge branch 'feature/tcl_pipeline' of https://github.com/wri/project…
manukala6 0f3c246
GTC-3451 Linting fixes
manukala6 44cae5c
Refactor TCL pipeline to decouple prefect from main flow
jterry64 d89b2e8
Fix gitignore
jterry64 41c3419
Add bbox test
jterry64 01bf793
Merge branch 'main' of https://github.com/wri/project-zeno-data-infra
jterry64 a66d101
Fix TCL test
jterry64 e6079db
Merge with main
jterry64 ba32126
Fix test for bbox to actually filter
jterry64 b26e833
Fix circular dependency
jterry64 de3cdd3
Make validation unit tests
jterry64 71fb389
Create unit test for sample statistics
jterry64 50d2b1a
Use Xee and GEE repository
jterry64 94c789f
Read GEE service account creds from github secrets
jterry64 0f9ff23
Do QC on a geojson
jterry64 7de0f1e
Fix circular dependency, get full flow tested
jterry64 ad6b7ff
Fix main flow test for TCL to use QC
jterry64 e6535e4
Add full integration test
jterry64 22ca1bf
Get real data test working
jterry64 24f2efe
Fix tests
jterry64 088e4c6
Add GEE service account creds to test runs
jterry64 63d5e3d
Add GEE service account creds to test runs
jterry64 efc8669
Use base64 encoded GEE account creds
jterry64 dba6e79
Fix GEE initialization, make lazy
jterry64 e0dadbf
Add additional features for QC set
jterry64 5a1c714
Use fixture for QC features in test
jterry64 ad4ec9f
Add natural forests
jterry64 0e19032
Fix tests
jterry64 fe09f29
Merge branch 'add_natural_forest' into validation_pipeline
jterry64 7222f2c
Add changes for natural forest class
jterry64 4ce1be5
Merge with main
jterry64 cd0c169
Update TCL test with real data
jterry64 9c75c43
Refactor drivers gee call
jterry64 1b6f71b
Stop swallowing errors
jterry64 53dc60f
Return multiple validation
jterry64 1837cc7
Return dict
jterry64 9f3a0a7
Use dict
jterry64 ce65efe
Validate natural forests intersection
jterry64 ea27204
Fix test
jterry64 47512b6
Move all postprocessing into postprocess stage for TCL
jterry64 b6c4edd
Use aoi_id instead of country/region/subregion for TCL
jterry64 1ef75ba
Get tests passing
jterry64 73237d8
isolate prefect resources by environment
solomon-negusse 746945b
Create TCL update script
jterry64 47ae82b
Add prefect deployment for tcl update
jterry64 562f4e8
Create flow options for run_updates
jterry64 a5dad61
Write out QC file
jterry64 e66cc47
Deal with corner case
jterry64 ad8a2b7
Deal with PR comments
jterry64 f45eb62
Fix PR comments, get tests passing
jterry64 68d5aa2
Use update flows
jterry64 c89e72d
separate out new relic monitoring by environment
solomon-negusse 7cf1737
fix container definition
solomon-negusse 638cb10
add type hint for flow types and minor fixes
solomon-negusse cb8bba4
Merge branch 'add_natural_forest' into isolated-envs
solomon-negusse 7ec9276
surface pipeline update parameters in prefect UI for test runs
solomon-negusse 9ebbfad
remove redundant main function
solomon-negusse fc957e8
fix tcl results location
solomon-negusse d514b38
Merge branch 'add_natural_forest' into isolated-envs
solomon-negusse dae042d
move sbtn natural forests to gnw account
solomon-negusse 2a49419
move sbtn natural forests zarr to gnw account
solomon-negusse 2212ca6
Merge branch 'main' into add_natural_forest
solomon-negusse 0217945
fix docstring; add parameter description
solomon-negusse 47a035f
add type hint for flow name and minor fixes
solomon-negusse 4dab956
prefect cli
solomon-negusse 7d22fe7
Merge branch 'main' into isolated-envs
solomon-negusse 70702d5
Merge branch 'main' into isolated-envs
solomon-negusse 477800e
add local pipeline instructions
solomon-negusse e4e436a
add prefect cloud pipeline run option
solomon-negusse b502fff
remove tfvars thats not ready for operational use
solomon-negusse 0f645b2
add doc on staging deployment
solomon-negusse 4ffa5c9
Merge branch 'main' into isolated-envs
solomon-negusse 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,162 @@ | ||
| =================================================== | ||
|
|
||
| To run tests: | ||
|
|
||
| `cd pipelines` | ||
| `uv sync` [if not already done] | ||
| `source .venv/bin/activate` [if not already activated] | ||
| `AWS_PROFILE=<GFW Data API production profile> pytest test` | ||
|
|
||
| =================================================== | ||
|
|
||
| If you want to run the prefect server and worker tasks locally (but with | ||
| xarray.reduce tasks still in coiled), from the top level of the repo do: | ||
| `cd pipelines` | ||
| `uv sync` [if not already done] | ||
| `source .venv/bin/activate` [if not already activated] | ||
| `coiled login` | ||
| `cd ..` | ||
| `prefect server start` (in a separate window, also activated) | ||
| `AWS_PROFILE=<zeno profile> python -m pipelines.run_updates` | ||
| # Pipelines | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ```bash | ||
| cd pipelines | ||
| uv sync # if not already done | ||
| source .venv/bin/activate # if not already activated | ||
| AWS_PROFILE=<GFW Data API production profile> pytest test | ||
| ``` | ||
|
|
||
| ## Running Pipeline Code Locally | ||
|
|
||
| ### AWS Permissions | ||
|
|
||
| Pipelines interact with S3 resources in the Zeno AWS account. Make sure you have a valid AWS profile configured with the necessary permissions before running any pipeline: | ||
|
|
||
| ```bash | ||
| export AWS_PROFILE=<zeno-profile> | ||
| ``` | ||
|
|
||
| ### Coiled (Dask Cluster) | ||
|
|
||
| Pipeline zonal stats computations run on a Dask cluster managed by [Coiled](https://cloud.coiled.io/). If not already logged in, authenticate from the terminal: | ||
|
|
||
| ```bash | ||
| coiled login | ||
| ``` | ||
|
|
||
| Coiled syncs your local Python environment to the remote Dask scheduler and workers. Before running a pipeline, make sure: | ||
|
|
||
| 1. **Activate the pipelines virtual environment** — the Coiled cluster is provisioned using packages from your active environment. | ||
| 2. **Keep the environment up to date** — run `uv sync` so the packages Coiled syncs to the cluster match what the pipeline code expects. | ||
|
|
||
| ```bash | ||
| cd pipelines | ||
| uv sync | ||
| source .venv/bin/activate | ||
| ``` | ||
|
|
||
| > **⚠ Architecture note:** The Coiled cluster in `run_updates.py` uses ARM-based instances (`r7g` family). If your local machine is not ARM (e.g. Intel/AMD x86_64), you may encounter package incompatibilities when Coiled attempts to sync your environment. Running from an Apple Silicon Mac or another ARM host avoids this issue. | ||
|
|
||
| ### Prefect | ||
|
|
||
| To monitor pipeline flows via the Prefect UI, there are two options depending on what's configured in `~/.prefect/profiles.toml`: | ||
|
|
||
| #### Option 1: Local Prefect Server | ||
|
|
||
| Spin up a local Prefect server in a separate terminal session: | ||
|
|
||
| ```bash | ||
| prefect server start | ||
| ``` | ||
|
|
||
| The Prefect dashboard will be available at http://127.0.0.1:4200 and local pipeline runs will show up there. | ||
|
|
||
| #### Option 2: Prefect Cloud | ||
|
|
||
| If the active profile in `~/.prefect/profiles.toml` points to a Prefect Cloud workspace, runs will appear in the cloud dashboard instead. Example `profiles.toml`: | ||
|
|
||
| ```toml | ||
| active = "local" | ||
|
|
||
| [profiles.local] | ||
| PREFECT_API_URL = "https://api.prefect.cloud/api/accounts/<account-id>/workspaces/<workspace-id>" | ||
| PREFECT_API_KEY = "*********" | ||
| ``` | ||
|
|
||
| ### Running a Pipeline | ||
|
|
||
| Pipelines are launched via the Click CLI in `run_updates.py`. Run with `--help` to see all available options: | ||
|
|
||
| ```bash | ||
| python -m pipelines.run_updates --help | ||
| ``` | ||
|
|
||
| ``` | ||
| Usage: python -m pipelines.run_updates [OPTIONS] | ||
|
|
||
| Options: | ||
| --flow [dist_update|tcl_update] | ||
| Which update flow to run. | ||
| --version TEXT Dataset version (required for tcl_update). | ||
| --overwrite Overwrite existing outputs. | ||
| --is-latest Mark this version as latest. | ||
| --help Show this message and exit. | ||
| ``` | ||
|
|
||
| Example — run the DIST alerts update: | ||
|
|
||
| ```bash | ||
| python -m pipelines.run_updates --flow dist_update --version v20260301 | ||
| ``` | ||
|
|
||
| ## Running Pipeline from Prefect Cloud UI | ||
|
|
||
| ### Architecture Overview | ||
|
|
||
|  | ||
|
|
||
| Pipelines are deployed to **Prefect Cloud** and execute on **AWS ECS Fargate**. The infrastructure is managed via Terraform (see `terraform/prefect.tf`). Here's how the pieces fit together: | ||
|
|
||
| 1. A **Deployment** (defined in Terraform) schedules a job or a user triggers a run from the Dashboard UI. | ||
| 2. The job is submitted to an **ECS Work Pool**, which defines the Fargate task template (CPU, memory, container image, IAM role). | ||
| 3. A **Worker** running continuously in the ECS cluster polls the work pool for pending jobs and spawns an ephemeral **Flow Runner Task** on Fargate. | ||
| 4. The Flow Runner executes the pipeline code and reports status and logs back to the Prefect Server, visible in the Dashboard UI. | ||
|
|
||
| ### Pipeline Docker Image | ||
|
|
||
| Both the ECS Fargate task and the Coiled Dask cluster require a Docker image containing the pipeline code and dependencies. This image is configured via the `PIPELINES_IMAGE` environment variable: | ||
|
|
||
| - **ECS (Prefect):** The deployment's job variables in Terraform set `image` to the value of `var.pipelines_image`, which is also passed as the `PIPELINES_IMAGE` env var inside the container. | ||
| - **Coiled:** The `create_cluster()` task in `run_updates.py` reads `os.getenv("PIPELINES_IMAGE")` to specify the container image for the Dask scheduler and workers. | ||
|
|
||
| Make sure the image is up to date and pushed to the container registry before triggering a run. | ||
|
|
||
| ### Triggering a Run from the Dashboard | ||
|
|
||
| There are two deployments available: | ||
|
|
||
| | Deployment | Purpose | | ||
| |---|---| | ||
| | **gnw-zonal-stats-update** | Production — runs against production resources. | | ||
| | **gnw-zonal-stats-update-staging** | Staging — runs against staging resources. Allows you to override the Docker image used by the flow runner and Coiled cluster (see below). | | ||
|
|
||
| > **⚠ Warning:** The staging deployment is **not fully isolated** from production. It shares the same AWS account and can access production S3 buckets and other resources. Take care when running staging flows — use the **overwrite** and **is_latest** flags with caution, as they can modify or replace production data. Always double-check parameters before submitting a run. | ||
|
|
||
| 1. Open the [Prefect Cloud Dashboard](https://app.prefect.cloud/). | ||
| 2. Navigate to **Deployments** and find **gnw-zonal-stats-update** (production) or **gnw-zonal-stats-update-staging** (staging). | ||
| 3. Click **Run** → **Custom Run** to configure parameters: | ||
|
|
||
|  | ||
|
|
||
| - **flow_name** — `dist_update` or `tcl_update` | ||
| - **version** — the dataset version (e.g. `v20260301`; required for `tcl_update`) | ||
| - **overwrite** — set to `true` to re-run over existing outputs | ||
| - **is_latest** — set to `true` to mark this version as the latest served by the analytics API | ||
|
|
||
|  | ||
|
|
||
| 4. Submit the run. The ECS worker will pick it up and execute it on Fargate. | ||
|
|
||
| #### Updating the Docker Image for Staging | ||
|
|
||
| The **gnw-zonal-stats-update-staging** deployment lets you override the ECR image used by both the ECS flow runner task and the Coiled Dask cluster. This is useful for testing a new image before promoting it to production. | ||
|
|
||
| To change the image: | ||
|
|
||
| 1. Navigate to **Deployments** and find **gnw-zonal-stats-update-staging**. | ||
| 2. Click the **three-dot menu (⋯)** in the top-right corner and select **Edit**. | ||
|
|
||
|  | ||
|
|
||
| 3. In the **Job Variables** section, update the following values with the desired ECR image URI: | ||
| - **`image`** — the container image for the ECS flow runner task. | ||
| - **`PIPELINES_IMAGE`** — the container image passed to the Coiled Dask cluster. | ||
|
|
||
| 4. Save the deployment. Subsequent runs will use the updated image for both the ECS task and the Coiled cluster. | ||
|
|
||
| ### Automatic Triggers | ||
|
|
||
| A **webhook + automation** is configured so that when a new DIST alerts version is published, the `dist_update` flow is triggered automatically with the version from the event payload. This is defined in `terraform/prefect.tf` as the `run-gnw-zonal-stats-on-dist-update` automation. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.