Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 6 additions & 2 deletions infra/dcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ locals {
max_instances = var.datacommons_services_max_instances
cpu = var.datacommons_services_cpu
memory = var.datacommons_services_memory
cpu_idle = var.datacommons_services_cpu_idle
startup_cpu_boost = var.datacommons_services_startup_cpu_boost
google_analytics_tag = var.datacommons_services_google_analytics_tag_id
enable_mcp = var.datacommons_services_enable_mcp
search_scope = var.datacommons_services_mcp_search_scope
Expand All @@ -121,8 +123,10 @@ locals {
location_id = var.redis_location_id
alternative_location_id = var.redis_alternative_location_id
replica_count = var.redis_replica_count
vpc_network_name = var.redis_vpc_network_name
vpc_connector_cidr = var.redis_vpc_connector_cidr
vpc_network_name = var.redis_vpc_network_name
vpc_connector_cidr = var.redis_vpc_connector_cidr
vpc_connector_min_instances = var.redis_vpc_connector_min_instances
vpc_connector_max_instances = var.redis_vpc_connector_max_instances
}

ingestion_config = {
Expand Down
2 changes: 2 additions & 0 deletions infra/dcp/modules/datacommons_services/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ resource "google_cloud_run_v2_service" "dc_web_service" {
containers {
image = var.image
resources {
cpu_idle = var.cpu_idle
startup_cpu_boost = var.startup_cpu_boost
limits = {
cpu = var.cpu
memory = var.memory
Expand Down
12 changes: 12 additions & 0 deletions infra/dcp/modules/datacommons_services/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ variable "memory" {
type = string
}

variable "cpu_idle" {
type = bool
description = "When true, CPU is only allocated during request processing (cheaper for low-traffic services). When false, CPU is always allocated (better performance, avoids cold starts)."
default = false
}

variable "startup_cpu_boost" {
type = bool
description = "Temporarily boost CPU allocation during container startup to reduce cold start latency."
default = true
}

variable "min_instances" {
type = number
}
Expand Down
4 changes: 4 additions & 0 deletions infra/dcp/modules/ingestion/helper_service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ resource "google_cloud_run_v2_service" "ingestion_helper" {
timeout = "1800s"
containers {
image = var.image
resources {
cpu_idle = var.cpu_idle
startup_cpu_boost = var.startup_cpu_boost
}

env {
name = "PROJECT_ID"
Expand Down
12 changes: 12 additions & 0 deletions infra/dcp/modules/ingestion/helper_service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ variable "ingestion_artifacts_path" {
description = "Path where pre-processed files are placed for the next stage"
}

variable "cpu_idle" {
type = bool
description = "When true, CPU is only allocated during request processing (cheaper for low-traffic services). When false, CPU is always allocated."
default = false
}

variable "startup_cpu_boost" {
type = bool
description = "Temporarily boost CPU allocation during container startup to reduce cold start latency."
default = true
}
Comment thread
saurabh-google marked this conversation as resolved.

variable "skip_container_restarts" {
type = bool
description = "Set to true to skip updating container restart timestamps, speeding up terraform apply when container images have not changed."
Expand Down
4 changes: 2 additions & 2 deletions infra/dcp/modules/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ resource "google_vpc_access_connector" "connector" {
region = var.region
network = var.vpc_network_id
ip_cidr_range = var.vpc_connector_cidr
min_instances = 2
max_instances = 10
min_instances = var.vpc_connector_min_instances
max_instances = var.vpc_connector_max_instances
}
12 changes: 12 additions & 0 deletions infra/dcp/modules/redis/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,15 @@ variable "enable_connector" {
type = bool
default = true
}

variable "vpc_connector_min_instances" {
type = number
description = "Minimum number of VPC Access Connector instances."
default = 2
}

variable "vpc_connector_max_instances" {
type = number
description = "Maximum number of VPC Access Connector instances."
default = 10
}
Comment thread
saurabh-google marked this conversation as resolved.
8 changes: 6 additions & 2 deletions infra/dcp/modules/stack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ module "redis" {
alternative_location_id = var.redis_config.alternative_location_id
replica_count = var.redis_config.replica_count
vpc_network_id = data.google_compute_network.default.id
vpc_connector_cidr = var.redis_config.vpc_connector_cidr
enable_connector = true
vpc_connector_cidr = var.redis_config.vpc_connector_cidr
vpc_connector_min_instances = var.redis_config.vpc_connector_min_instances
vpc_connector_max_instances = var.redis_config.vpc_connector_max_instances
enable_connector = true
}

module "auth" {
Expand All @@ -270,6 +272,8 @@ module "datacommons_services" {
image = var.datacommons_services_config.image
cpu = var.datacommons_services_config.cpu
memory = var.datacommons_services_config.memory
cpu_idle = var.datacommons_services_config.cpu_idle
startup_cpu_boost = var.datacommons_services_config.startup_cpu_boost
min_instances = var.datacommons_services_config.min_instances
max_instances = var.datacommons_services_config.max_instances
make_public = var.datacommons_services_config.allow_unauthenticated_access
Expand Down
22 changes: 13 additions & 9 deletions infra/dcp/modules/stack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ variable "datacommons_services_config" {
max_instances = number
cpu = string
memory = string
cpu_idle = optional(bool, false)
startup_cpu_boost = optional(bool, true)
google_analytics_tag = string
enable_mcp = bool
search_scope = string
Expand All @@ -69,15 +71,17 @@ variable "auth_config" {

variable "redis_config" {
type = object({
enable = bool
instance_name = string
memory_size_gb = number
tier = string
location_id = string
alternative_location_id = string
replica_count = number
vpc_network_name = string
vpc_connector_cidr = string
enable = bool
instance_name = string
memory_size_gb = number
tier = string
location_id = string
alternative_location_id = string
replica_count = number
vpc_network_name = string
vpc_connector_cidr = string
vpc_connector_min_instances = optional(number, 2)
Comment thread
saurabh-google marked this conversation as resolved.
Outdated
vpc_connector_max_instances = optional(number, 10)
})
}

Expand Down
12 changes: 12 additions & 0 deletions infra/dcp/terraform.tfvars.template
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ storage_create_artifacts_bucket = true
# significantly improving performance. You may want to set this to true in production.
enable_redis = false

# VPC connector scaling for Redis. Lower min_instances reduces baseline cost.
Comment thread
saurabh-google marked this conversation as resolved.
Outdated
# redis_vpc_connector_min_instances = 2
# redis_vpc_connector_max_instances = 10

# =============================================================================
# Spanner Module
# =============================================================================
Expand All @@ -59,6 +63,14 @@ spanner_create_instance = true
# Data Commons documentation.
datacommons_services_allow_unauthenticated_access = false

# CPU idle mode: when true, CPU is only allocated during request processing (saves costs
# for low-traffic services). When false (default), CPU is always allocated for better
# performance and avoids cold starts.
# datacommons_services_cpu_idle = false

# Boost CPU allocation during container startup to reduce cold start latency (default: true).
# datacommons_services_startup_cpu_boost = true

# Track traffic and user interactions with your site using Google Analytics.
# datacommons_services_google_analytics_tag_id = "your-analytics-tag-id"

Expand Down
24 changes: 24 additions & 0 deletions infra/dcp/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ variable "redis_vpc_connector_cidr" {
default = "10.13.0.0/28"
}

variable "redis_vpc_connector_min_instances" {
description = "Minimum number of VPC Access Connector instances. Lower values reduce baseline cost."
type = number
default = 2
}

variable "redis_vpc_connector_max_instances" {
description = "Maximum number of VPC Access Connector instances."
type = number
default = 10
}
Comment thread
saurabh-google marked this conversation as resolved.

# =============================================================================
# Spanner Module
# =============================================================================
Expand Down Expand Up @@ -279,6 +291,18 @@ variable "datacommons_services_memory" {
default = "16G"
}

variable "datacommons_services_cpu_idle" {
description = "When true, CPU is only allocated during request processing (cheaper for low-traffic services). When false, CPU is always allocated (better performance, avoids cold starts within running instances)."
type = bool
default = false
}

variable "datacommons_services_startup_cpu_boost" {
description = "Temporarily boost CPU allocation during container startup to reduce cold start latency."
type = bool
default = true
}

variable "datacommons_services_allow_unauthenticated_access" {
description = "Allow unauthenticated access to the public-facing services of the Data Commons Platform"
type = bool
Expand Down