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

Avoid cold starts #35

Merged
merged 42 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
621f40b
add some handling for a case where no fire boundary is detected - som…
GondekNP Feb 29, 2024
d0e4382
Initial pull of historic calfire data
GondekNP Mar 1, 2024
b0e0e6c
initial scaffold for batch process
GondekNP Mar 1, 2024
d520e6a
add cloud task for batch process
GondekNP Mar 3, 2024
85d1c42
light refactor to main classes for fastapi analysis and fetch, such t…
GondekNP Mar 3, 2024
d66e342
basic setup for batch
GondekNP Mar 3, 2024
0d4c6ca
setup basic ipynb to batch some example calfire boundaries
GondekNP Mar 3, 2024
382ae7e
setup basic ipynb to batch some example calfire boundaries
GondekNP Mar 3, 2024
e3b922f
setup for spatial sample of calfires sent to cloud task
GondekNP Mar 4, 2024
de777a2
add cloud tasks to prod env
GondekNP Mar 4, 2024
b165641
proper filtering of nps fires by spatial and year and agency
GondekNP Mar 4, 2024
1aa4f01
working to replicate valid geojson object from calfire gpd
GondekNP Mar 4, 2024
7c51013
working to hit analyze main func. Need to add upload shapefile zip an…
GondekNP Mar 4, 2024
19805ee
refactor out main for upload shapefile zip
GondekNP Mar 4, 2024
ce1e1aa
AOI draw refactor for main
GondekNP Mar 4, 2024
638aa1c
actually just use the cloud io client directly - currently that main …
GondekNP Mar 4, 2024
450867c
refactor for main
GondekNP Mar 4, 2024
844b826
tweak map to be more lenient of missing layers, add logging and job s…
GondekNP Mar 4, 2024
3888f94
ok proper upload log json
GondekNP Mar 4, 2024
94718b8
track time elapsed as well
GondekNP Mar 4, 2024
2cccdcf
properly wrap error in str for json serialization
GondekNP Mar 4, 2024
ca85d76
r-> w duh
GondekNP Mar 4, 2024
f372a2d
More logging, some light refactor for naming in RAP
GondekNP Mar 4, 2024
bfff4d8
fix rap tests for refactor
GondekNP Mar 4, 2024
35d139d
fix rap test key error
GondekNP Mar 4, 2024
353785e
Merge pull request #33 from SchmidtDSE/feat/cloud_tasks
GondekNP Mar 4, 2024
d0a8fd5
Collect TODO comments
todo-actions[bot] Mar 4, 2024
7e1c9a6
Update TODO references: #34
todo-actions[bot] Mar 4, 2024
be01933
strp the actual format of a str'd datetime from NPS
GondekNP Mar 5, 2024
56bc22f
merge tweak
GondekNP Mar 5, 2024
fef01d5
change prefix for calfire boundary
GondekNP Mar 5, 2024
0761a9b
fix bug in endpoint name for dev in tofu
GondekNP Mar 5, 2024
dfbb6f3
more logging to figure out our pain
GondekNP Mar 5, 2024
5266a22
convert to using python logging and setting google handler such that …
GondekNP Mar 5, 2024
bedbe2f
bugfixes for main workflow
GondekNP Mar 5, 2024
50207df
info
GondekNP Mar 5, 2024
9d39f62
fix post body
GondekNP Mar 5, 2024
97e1a74
remove the leading calfire bit from boundary for now, as it breaks so…
GondekNP Mar 5, 2024
dcdec34
reduce concurrency to hopefully avoid issues pulling from planetary c…
GondekNP Mar 5, 2024
b67efdf
clean up main.tf for demo
GondekNP Mar 14, 2024
b47a14b
pull dev
GondekNP Mar 14, 2024
35d54d7
have one instance at the ready to avoid cold starts (can maybe change…
GondekNP Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .deployment/prod_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- google-auth
- google-cloud-secret-manager
- google-cloud-logging
- google-cloud-tasks
- rioxarray
- stackstac
- gdal
Expand Down
2 changes: 0 additions & 2 deletions .deployment/tofu/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ locals {
google_project_number = data.google_project.project.number
aws_account_id = data.aws_caller_identity.current.account_id
aws_region = data.aws_region.current.name
# oidc_provider_domain_url = "https://accounts.google.com"
oidc_provider_domain_url = "accounts.google.com"
# gcp_cloud_run_client_id = "${terraform.workspace}" == "prod" ? "117526146749746854545" : "101023653831248304550"
}

# Initialize the modules
Expand Down
64 changes: 20 additions & 44 deletions .deployment/tofu/modules/burn_backend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,6 @@ resource "google_compute_router_nat" "burn_backend_nat" {
}
}

# Create a Cloud Run service for titiler - for later
# resource "google_cloud_run_v2_service" "titiler_service" {
# name = "titiler-service"
# location = "us-central1"

# template {
# service_account = google_service_account.burn-backend-service.email
# timeout = "3599s" # max timeout is one hour
# containers {
# image = "ghcr.io/developmentseed/titiler:0.15.8" # Use the titiler Docker image
# resources {
# limits = {
# cpu = "2"
# memory = "2Gi"
# }
# }
# }
# vpc_access {
# connector = google_vpc_access_connector.burn_backend_vpc_connector.id
# egress = "ALL_TRAFFIC"
# }
# }

# traffic {
# percent = 100
# type = "TRAFFIC_TARGET_ALLOCATION_TYPE_LATEST"
# }

# lifecycle { # This helps to not replace the service if it already exists
# ignore_changes = [
# template[0].containers[0].image,
# ]
# }
# }

# # Allow unauthenticated invocations
# resource "google_cloud_run_service_iam_member" "public_titiler" {
# service = google_cloud_run_v2_service.titiler_service.name
# location = google_cloud_run_v2_service.titiler_service.location
# role = "roles/run.invoker"
# member = "allUsers"
# }

# Create a Cloud Run service for burn-backend services
resource "google_cloud_run_v2_service" "tf-rest-burn-severity" {
name = "tf-rest-burn-severity-${terraform.workspace}"
Expand All @@ -121,7 +78,7 @@ resource "google_cloud_run_v2_service" "tf-rest-burn-severity" {
## TODO [#24]: self-referential endpoint, will be solved by refactoring out titiler and/or making fully static
env {
name = "GCP_CLOUD_RUN_ENDPOINT"
value = "${terraform.workspace}" == "prod" ? "https://tf-rest-burn-severity-ohi6r6qs2a-uc.a.run.app" : "https://tf-rest-burn-severity-dev-ohi6r6qs2a-uc.a.run.appz"
value = "${terraform.workspace}" == "prod" ? "https://tf-rest-burn-severity-ohi6r6qs2a-uc.a.run.app" : "https://tf-rest-burn-severity-dev-ohi6r6qs2a-uc.a.run.app"
}
env {
name = "CPL_VSIL_CURL_ALLOWED_EXTENSIONS"
Expand Down Expand Up @@ -174,6 +131,10 @@ resource "google_cloud_run_v2_service" "tf-rest-burn-severity" {
connector = google_vpc_access_connector.burn_backend_vpc_connector.id
egress = "ALL_TRAFFIC"
}
scaling {
min_instance_count = 1 # to reduce cold start time
max_instance_count = 100
}
}

traffic {
Expand All @@ -188,6 +149,21 @@ resource "google_cloud_run_v2_service" "tf-rest-burn-severity" {
}
}

# Create a Cloud Tasks queue for the Cloud Run service
resource "google_cloud_tasks_queue" "tf-rest-burn-severity-queue" {
name = "tf-rest-burn-severity-queue-${terraform.workspace}"
location = "us-central1"

rate_limits {
max_concurrent_dispatches = 2
}

retry_config {
max_attempts = "2"
}
}


# Allow unauthenticated invocations
resource "google_cloud_run_service_iam_member" "public" {
service = google_cloud_run_v2_service.tf-rest-burn-severity.name
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/dev_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- google-auth
- google-cloud-secret-manager
- google-cloud-logging
- google-cloud-tasks
- ipykernel
- rioxarray
- stackstac
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ src/__pycache__
*.pyc
.devcontainer/.env
.vscode/settings.json
exploratory/*.zip
exploratory/*.gdb

# Ignore generated credentials from google-github-actions/auth
gha-creds-*.json
Loading
Loading