Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 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 All @@ -149,6 +153,8 @@ locals {
# Workflow & Helper Service
workflow_lock_acquisition_timeout = var.ingestion_workflow_lock_acquisition_timeout
helper_service_image = coalesce(var.ingestion_helper_service_image, "gcr.io/datcom-ci/datacommons-ingestion-helper:${var.dcp_version}")
helper_service_cpu_idle = var.ingestion_helper_service_cpu_idle
helper_service_startup_cpu_boost = var.ingestion_helper_service_startup_cpu_boost

# Dataflow Network & Scaling Configuration
dataflow_ip_configuration = var.ingestion_dataflow_ip_configuration
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
14 changes: 14 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,20 @@ 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
nullable = false
}

variable "startup_cpu_boost" {
type = bool
description = "Temporarily boost CPU allocation during container startup to reduce cold start latency."
default = true
nullable = false
}
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.
10 changes: 8 additions & 2 deletions infra/dcp/modules/stack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ module "ingestion_helper_service" {
redis_port = var.redis_config.enable && length(module.redis) > 0 ? tostring(module.redis[0].redis_port) : ""
ingestion_artifacts_path = "${var.ingestion_config.ingestion_artifacts_path}/metadata"
skip_container_restarts = var.global.skip_container_restarts
cpu_idle = var.ingestion_config.helper_service_cpu_idle
startup_cpu_boost = var.ingestion_config.helper_service_startup_cpu_boost
}


Expand Down Expand Up @@ -245,8 +247,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 +274,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
24 changes: 15 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 = number
vpc_connector_max_instances = number
})
}

Expand Down Expand Up @@ -106,6 +110,8 @@ variable "ingestion_config" {
# Workflow & Helper Service
workflow_lock_acquisition_timeout = number
helper_service_image = optional(string)
helper_service_cpu_idle = optional(bool)
helper_service_startup_cpu_boost = optional(bool)

# Dataflow network configuration
# Use WORKER_IP_PRIVATE when a compute.vmExternalIpAccess org policy
Expand Down
43 changes: 43 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 Expand Up @@ -428,6 +452,18 @@ variable "ingestion_helper_service_image" {
default = null
}

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

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

# =============================================================================
# Ingestion - Dataflow Network Configuration
# =============================================================================
Expand Down Expand Up @@ -500,3 +536,10 @@ check "ingestion_dataflow_workers_limits" {
}
}

check "redis_vpc_connector_instances_limits" {
assert {
condition = var.redis_vpc_connector_max_instances >= var.redis_vpc_connector_min_instances
error_message = "The redis_vpc_connector_max_instances must be greater than or equal to redis_vpc_connector_min_instances."
}
}