Lua Nginx 值为空或不存在

在我的 Lua 配置中,每个指标都报错

prometheus.lua:710: log_error(): No value passed for upstream_time while logging request

我已检查值是否为 nil 或空,但似乎解决不了问题

init_worker_by_lua_block {
...
metric_upstream_time = prometheus:histogram( "upstream_time", "Upstream", {"host"} )
...
}

log_by_lua_block {
...
if (not (ngx.var.upstream_response_time == nil or ngx.var.upstream_response_time == '' ))
then
  metric_upstream_time:observe(tonumber(ngx.var.upstream_response_time), {ngx.var.server_name})
end
...
}

nginx_error.log

Jan 25 13:56:41 host nginx: 2022/01/25 13:56:41 [error] 142#142: *106669580 [lua] prometheus.lua:734: log_error(): No value passed for upstream_time while logging request, client: xx.xx.201.231, server: xxxxxx, request: "GET /api/v1/xxxxxx HTTP/1.1", upstream: "http://127.0.0.1:20190/api/v1/images/xxxx", host: "xxxxxx", referrer: "xxxxxxx"

原文链接 https://stackoverflow.com/questions/70847822

点赞