common/templates/task.metrics_proxy

86 lines
2.0 KiB
HCL

[[- if conv.ToBool .prometheus.enabled ]]
[[- /*
vim: syntax=hcl
*/]]
# The prometheus metrics proxy, adding mTLS to the metrics endpoint
task "metrics-proxy" {
driver = "docker"
user = 8995
# Reduce Docker logs collection (huge) overhead
logs {
disabled = true
}
config {
image = "nginxinc/nginx-unprivileged:alpine"
force_pull = true
volumes = [
"local/default.conf:/etc/nginx/conf.d/default.conf:ro"
]
pids_limit = 100
}
lifecycle {
hook = "poststart"
sidecar = true
}
vault {
policies = ["metrics[[ .consul.suffix ]]"]
disable_file = true
env = false
change_mode = "noop"
}
[[ template "common/metrics_cert" . ]]
template {
data =<<_EOT
server {
listen {{ env "NOMAD_ALLOC_PORT_metrics" }} ssl;
http2 on;
ssl_certificate /secrets/metrics.bundle.pem;
ssl_certificate_key /secrets/metrics.bundle.pem;
ssl_client_certificate /local/monitoring.ca.pem;
ssl_verify_client on;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1h;
ssl_session_tickets off;
gzip on;
gzip_types
text/plain;
gzip_vary on;
server_tokens off;
if ($request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
location /metrics {
proxy_pass [[ .prometheus.metrics_url ]];
}
[[- if has .prometheus "additional_proxy_locations" ]]
[[ .prometheus.additional_proxy_locations | indent 2 ]]
[[- end ]]
}
[[- if has .prometheus "additional_proxy_conf" ]]
[[ .prometheus.additional_proxy_conf ]]
[[- end ]]
_EOT
destination = "local/default.conf"
}
resources {
cpu = 10
memory = 10
memory_max = 20
}
}
[[- end ]]