Skip to content

Commit

Permalink
Fix liveness probe (#12)
Browse files Browse the repository at this point in the history
* Fix liveness probe

* Make health check times configurable
  • Loading branch information
bruce-y authored Nov 7, 2023
1 parent 52e734b commit c80061d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module "cloud_run" {
internal = false

container_image = "us-east1-docker.pkg.dev/superblocks-registry/superblocks/agent"
container_port = "8020"
container_port = "8080"

container_env = {
"SUPERBLOCKS_ORCHESTRATOR_LOG_LEVEL" = "${var.superblocks_log_level}"
Expand Down
3 changes: 3 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ module "cloud_run" {
container_limits_memory = var.container_limits_memory
container_max_capacity = var.container_max_capacity
container_min_capacity = var.container_min_capacity

health_check_failure_threshold = var.health_check_failure_threshold
health_check_period = var.health_check_period
}

#################################################################
Expand Down
15 changes: 15 additions & 0 deletions modules/cloud-run/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "google_cloud_run_service" "superblocks" {
project = var.project_id
name = "${var.name_prefix}-cloud-run-service"
location = var.region

Expand Down Expand Up @@ -33,6 +34,20 @@ resource "google_cloud_run_service" "superblocks" {
value = env.value
}
}
startup_probe {
tcp_socket {
port = var.container_port
}
}

liveness_probe {
failure_threshold = var.health_check_failure_threshold
period_seconds = var.health_check_period
http_get {
path = "/health"
port = var.container_port
}
}
}
}
metadata {
Expand Down
2 changes: 1 addition & 1 deletion modules/cloud-run/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 3.5.0"
version = ">= 5.0.0"
}
}
}
12 changes: 12 additions & 0 deletions modules/cloud-run/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,15 @@ variable "cloud_run_member" {
type = string
default = "allUsers"
}

variable "health_check_period" {
type = number
default = 10
description = "The interval between health checks in seconds"
}

variable "health_check_failure_threshold" {
type = number
default = 6
description = "The number of consecutive failed health checks before considering the agent unhealthy"
}
2 changes: 1 addition & 1 deletion provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 3.5.0"
version = ">= 5.0.0"
}
}
}
4 changes: 2 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ variable "superblocks_agent_handle_cors" {
}

variable "superblocks_additional_env_vars" {
type = map(any)
default = {}
type = map(any)
default = {}
description = "Additional environment variables to specify for the Superblocks Agent container."
}

Expand Down

0 comments on commit c80061d

Please sign in to comment.