mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
The swarm openresty restart used 'container service update --force --detach' (fire-and-forget), so the deploy + e2e proceeded before openresty reconverged with prometheus.conf. The per-vhost log_by_lua then saw a nil metric_requests ('attempt to index global metric_requests') and the prometheus metricz/scrape e2e failed. Drop --detach so the update waits for convergence (bounded by the existing timeout 600). Also guard the per-vhost log_by_lua against a nil metric so any residual pre-init window can't throw.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
19 lines
1.1 KiB
Django/Jinja
19 lines
1.1 KiB
Django/Jinja
# Per-request metrics collection — records data after the response is sent.
|
|
# Included in every prometheus-enabled app vhost. Metrics are labelled by
|
|
# host + app so a single /metricz scrape on the prometheus domain covers all
|
|
# applications without redundancy.
|
|
log_by_lua_block {
|
|
-- The metrics are defined together in prometheus.conf's init_worker. During an
|
|
-- openresty reconverge a vhost can load before that init runs, so guard against
|
|
-- a nil metric (otherwise log_by_lua throws "index global 'metric_requests'").
|
|
if metric_requests then
|
|
metric_requests:inc(1, {ngx.var.host, ngx.var.app_id, ngx.var.request_method, ngx.var.status})
|
|
metric_latency:observe(tonumber(ngx.var.request_time), {ngx.var.host, ngx.var.app_id})
|
|
metric_bytes_sent:inc(tonumber(ngx.var.bytes_sent) or 0, {ngx.var.host, ngx.var.app_id})
|
|
metric_bytes_received:inc(tonumber(ngx.var.request_length) or 0, {ngx.var.host, ngx.var.app_id})
|
|
if ngx.var.ssl_protocol and ngx.var.ssl_protocol ~= "" then
|
|
metric_tls_handshakes:inc(1, {ngx.var.host, ngx.var.app_id, ngx.var.ssl_protocol})
|
|
end
|
|
end
|
|
}
|