Add service healthchecks

This commit is contained in:
IamTheFij 2024-01-23 12:08:47 -08:00
parent 0a2eace3dd
commit 35dfeb3093
6 changed files with 89 additions and 61 deletions

View File

@ -9,9 +9,11 @@ module "loki" {
service_port = 3100 service_port = 3100
ingress = true ingress = true
use_wesher = var.use_wesher use_wesher = var.use_wesher
service_check = {
path = "/ready"
}
sticky_disk = true sticky_disk = true
# healthcheck = "/ready"
templates = [ templates = [
{ {
data = file("${path.module}/loki-config.yml") data = file("${path.module}/loki-config.yml")

View File

@ -53,6 +53,9 @@ job "traefik" {
sticky = true sticky = true
} }
task "traefik" {
driver = "docker"
service { service {
name = "traefik" name = "traefik"
provider = "nomad" provider = "nomad"
@ -61,7 +64,6 @@ job "traefik" {
check { check {
type = "http" type = "http"
path = "/ping" path = "/ping"
port = "web"
interval = "10s" interval = "10s"
timeout = "2s" timeout = "2s"
} }
@ -73,15 +75,6 @@ job "traefik" {
] ]
} }
task "traefik" {
driver = "docker"
meta = {
"diun.sort_tags" = "semver"
"diun.watch_repo" = true
"diun.include_tags" = "^[0-9]+\\.[0-9]+$"
}
config { config {
image = "traefik:2.10" image = "traefik:2.10"

View File

@ -23,6 +23,9 @@ module "gitea" {
to = 22 to = 22
} }
] ]
service_check = {
path = "/api/healthz"
}
custom_services = [ custom_services = [
{ {

View File

@ -15,6 +15,7 @@ resource "nomad_job" "service" {
service_port = var.service_port service_port = var.service_port
service_port_static = var.service_port_static service_port_static = var.service_port_static
service_check = var.service_check
ports = var.ports ports = var.ports
sticky_disk = var.sticky_disk sticky_disk = var.sticky_disk
resources = var.resources resources = var.resources

View File

@ -73,6 +73,16 @@ job "${name}" {
source = "${host_volume.name}" source = "${host_volume.name}"
} }
%{~ endfor ~} %{~ endfor ~}
task "${name}" {
driver = "docker"
%{~ if length(task_meta) > 0 }
meta = {
%{ for k, v in task_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{~ endif ~}
%{~ if service_port != null } %{~ if service_port != null }
service { service {
name = "${replace(name, "_", "-")}" name = "${replace(name, "_", "-")}"
@ -97,9 +107,24 @@ job "${name}" {
"${tag}", "${tag}",
%{~ endfor ~} %{~ endfor ~}
] ]
%{~ if service_check != null ~}
check {
%{~ if service_check.name != "" ~}
name = "${service_check.name}"
%{~ endif ~}
%{~ if service_check.name != "" ~}
port = "${service_check.port}"
%{~ endif ~}
type = "${service_check.type}"
path = "${service_check.path}"
interval = "${service_check.interval}"
timeout = "${service_check.timeout}"
} }
%{~ endif ~} %{~ endif ~}
}
%{~ endif ~}
%{~ for custom_service in custom_services ~} %{~ for custom_service in custom_services ~}
service { service {
name = "${custom_service.name}" name = "${custom_service.name}"
@ -110,16 +135,6 @@ job "${name}" {
} }
%{~ endfor ~} %{~ endfor ~}
task "${name}" {
driver = "docker"
%{~ if length(task_meta) > 0 }
meta = {
%{ for k, v in task_meta ~}
${k} = ${jsonencode(v)}
%{ endfor ~}
}
%{~ endif ~}
config { config {
image = "${image}" image = "${image}"
%{~if image_pull_timeout != null ~} %{~if image_pull_timeout != null ~}

View File

@ -268,3 +268,17 @@ variable "use_wesher" {
description = "Indicates whether or not services should expose themselves on the wesher network" description = "Indicates whether or not services should expose themselves on the wesher network"
default = true default = true
} }
variable "service_check" {
description = "Health check for main ingress service"
type = object({
name = optional(string, "")
port = optional(string, "")
path = optional(string, "/")
interval = optional(string, "30s")
timeout = optional(string, "2s")
type = optional(string, "http")
})
default = {}
}