From 17ab7f637fdba6a54305381e26876bb67b6aba21 Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Tue, 15 Nov 2022 09:00:37 -0800 Subject: [PATCH] Add metrics support to service template --- services/service/main.tf | 1 + services/service/service_template.nomad | 6 ++++++ services/service/vars.tf | 12 +++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/services/service/main.tf b/services/service/main.tf index a52b0bb..fa66efb 100644 --- a/services/service/main.tf +++ b/services/service/main.tf @@ -13,6 +13,7 @@ resource "nomad_job" "service" { ingress_rule = var.ingress_rule ingress_middlewares = var.ingress_middlewares healthcheck_path = var.healthcheck_path + metrics_port_name = var.metrics_port_name templates = var.templates host_volumes = var.host_volumes diff --git a/services/service/service_template.nomad b/services/service/service_template.nomad index 3a63368..5340d37 100644 --- a/services/service/service_template.nomad +++ b/services/service/service_template.nomad @@ -88,6 +88,12 @@ job "${name}" { timeout = "10s" } + %{ endif ~} + %{ if metrics_port_name != null ~} + meta { + metrics_addr = "$${NOMAD_ADDR_${metrics_port_name}}" + } + %{ endif ~} tags = [ %{ if ingress ~} diff --git a/services/service/vars.tf b/services/service/vars.tf index d4d09ee..3e640c0 100644 --- a/services/service/vars.tf +++ b/services/service/vars.tf @@ -11,7 +11,13 @@ variable "image" { variable "service_port" { type = number 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" { @@ -73,8 +79,8 @@ variable "templates" { change_signal = optional(string) left_delimiter = optional(string) right_delimiter = optional(string) - mount = optional(bool) - env = optional(bool) + mount = optional(bool, true) + env = optional(bool, false) })) default = [] description = "Templates to be used"