Cleanup metrics handling

This commit is contained in:
Daniel Berteaud 2024-03-27 13:26:29 +01:00
parent 81b7e1beee
commit 24e9853c98
7 changed files with 26 additions and 19 deletions

View File

@ -11,6 +11,8 @@ job "postgres-manage" {
region = "global" region = "global"
group "manage" { group "manage" {
network { network {
mode = "bridge" mode = "bridge"

View File

@ -6,6 +6,13 @@ job "postgres" {
priority = 80 priority = 80
constraint {
operator = "distinct_hosts"
value = "true"
}
group "server" { group "server" {
ephemeral_disk { ephemeral_disk {
@ -13,14 +20,6 @@ job "postgres" {
size = 101 size = 101
} }
constraint {
operator = "distinct_hosts"
value = "true"
}
count = "1" count = "1"
network { network {
mode = "bridge" mode = "bridge"
@ -43,8 +42,13 @@ job "postgres" {
name = "postgres" name = "postgres"
port = 5432 port = 5432
meta { meta {
alloc = "${NOMAD_ALLOC_INDEX}" alloc = "${NOMAD_ALLOC_INDEX}"
job = "${NOMAD_JOB_NAME}" datacenter = "${NOMAD_DC}"
group = "${NOMAD_GROUP_NAME}"
job = "${NOMAD_JOB_NAME}"
namespace = "${NOMAD_NAMESPACE}"
node = "${node.unique.name}"
region = "${NOMAD_REGION}"
} }
connect { connect {

View File

@ -5,6 +5,8 @@ job "postgres-upgrade" {
region = "global" region = "global"
type = "batch" type = "batch"
meta { meta {

View File

@ -11,12 +11,10 @@ job "[[ .instance ]]" {
size = 101 size = 101
} }
[[ template "common/constraints" $c ]]
count = "[[ $c.recovery | ternary 1 $c.count ]]" count = "[[ $c.recovery | ternary 1 $c.count ]]"
network { network {
mode = "bridge" mode = "bridge"
[[- if $c.prometheus.enabled ]] [[- if conv.ToBool $c.prometheus.enabled ]]
port "metrics" {} port "metrics" {}
port "patroni-metrics" {} port "patroni-metrics" {}
[[- end ]] [[- end ]]
@ -92,7 +90,7 @@ job "[[ .instance ]]" {
enable_tag_override = true enable_tag_override = true
} }
[[- if $c.prometheus.enabled ]] [[- if conv.ToBool $c.prometheus.enabled ]]
# This service is just used to expose patroni metrics # This service is just used to expose patroni metrics
service { service {
name = "[[ .instance ]]-patroni[[ $c.consul.suffix ]]" name = "[[ .instance ]]-patroni[[ $c.consul.suffix ]]"
@ -321,7 +319,7 @@ _EOT
} }
[[- end ]] [[- end ]]
[[- if and $c.prometheus.enabled (not .pg.server.recovery) ]] [[- if and (conv.ToBool $c.prometheus.enabled) (not .pg.server.recovery) ]]
[[ $e := merge .pg.exporter .pg . ]] [[ $e := merge .pg.exporter .pg . ]]
[[ template "common/task.metrics_proxy" merge (dict "prometheus" (dict "additional_proxy_conf" (tmpl.Exec "postgres/nginx_patroni.conf.tpl" $e))) $c ]] [[ template "common/task.metrics_proxy" merge (dict "prometheus" (dict "additional_proxy_conf" (tmpl.Exec "postgres/nginx_patroni.conf.tpl" $e))) $c ]]

View File

@ -63,7 +63,7 @@ pg:
value: true value: true
# In recovery mode, neither patroni nor postgres will be started. The container will start and wait for manual recovery # In recovery mode, neither patroni nor postgres will be started. The container will start and wait for manual recovery
recovery: False recovery: false
# Recovery configuration to pass to patroni config # Recovery configuration to pass to patroni config
recovery_conf: {} recovery_conf: {}
@ -146,6 +146,7 @@ pg:
- postgres - postgres
prometheus: prometheus:
enabled: '[[ .prometheus.available ]]'
metrics_url: http://localhost:9187 metrics_url: http://localhost:9187
# Backup service uses pgbackrest to perform # Backup service uses pgbackrest to perform
@ -158,7 +159,7 @@ pg:
# pgbackrest based backups # pgbackrest based backups
pgbackrest: pgbackrest:
enabled: False enabled: false
# Schedules for backups. Empty string to disable # Schedules for backups. Empty string to disable
cron: cron:
@ -168,7 +169,7 @@ pg:
# pg_dump based backups # pg_dump based backups
dumps: dumps:
enabled: False enabled: false
format: custom format: custom
compression: 6 compression: 6
cron: 39 03 * * * cron: 39 03 * * *
@ -180,7 +181,7 @@ pg:
memory_max: 256 memory_max: 256
# Postgres exporter for prometheus # Postgres exporter for prometheus
# Only used if prometheus.enabled is True # Only used if prometheus.enabled is true
exporter: exporter:
# Image to use # Image to use
image: quay.io/prometheuscommunity/postgres-exporter:latest image: quay.io/prometheuscommunity/postgres-exporter:latest