Add metrics support to service template

This commit is contained in:
IamTheFij 2022-11-15 09:00:37 -08:00
parent e104cbccc4
commit 17ab7f637f
3 changed files with 16 additions and 3 deletions

View File

@ -13,6 +13,7 @@ resource "nomad_job" "service" {
ingress_rule = var.ingress_rule ingress_rule = var.ingress_rule
ingress_middlewares = var.ingress_middlewares ingress_middlewares = var.ingress_middlewares
healthcheck_path = var.healthcheck_path healthcheck_path = var.healthcheck_path
metrics_port_name = var.metrics_port_name
templates = var.templates templates = var.templates
host_volumes = var.host_volumes host_volumes = var.host_volumes

View File

@ -88,6 +88,12 @@ job "${name}" {
timeout = "10s" timeout = "10s"
} }
%{ endif ~}
%{ if metrics_port_name != null ~}
meta {
metrics_addr = "$${NOMAD_ADDR_${metrics_port_name}}"
}
%{ endif ~} %{ endif ~}
tags = [ tags = [
%{ if ingress ~} %{ if ingress ~}

View File

@ -11,7 +11,13 @@ variable "image" {
variable "service_port" { variable "service_port" {
type = number type = number
default = null default = null
description = "Port used by the service for ingress" description = "Port number used by the service"
}
variable "metrics_port_name" {
type = string
default = null
description = "Name of port that /metrics can be scraped from"
} }
variable "ingress" { variable "ingress" {
@ -73,8 +79,8 @@ variable "templates" {
change_signal = optional(string) change_signal = optional(string)
left_delimiter = optional(string) left_delimiter = optional(string)
right_delimiter = optional(string) right_delimiter = optional(string)
mount = optional(bool) mount = optional(bool, true)
env = optional(bool) env = optional(bool, false)
})) }))
default = [] default = []
description = "Templates to be used" description = "Templates to be used"