I'm trying to get Nginx (running as a Kubernetes ingress controller) to log in milliseconds rather then seconds. (This is so we can ingest the logs into our existing Elasticsearch system, which already has other systems logging in ms)
Based on this blog post I've tried the following in the 'http' context:
map $host $request_time_ms {
default 'test';
}
log_by_lua_block {
ngx.var.request_time_ms = 'foo'
}
And then in my log string:
'{...."duration_ms":"$request_time_ms",....}'
But the logged value is always the default value of test
rather than the expected one of foo
.
Ultimately it should end up like:
ngx.var.request_time_ms = math.floor(tonumber(ngx.var.request_time) * 1000)
But I'm just trying to get the basic situation to work first.
Any idea why this doesn't work? It's as if the log_by_lua_block
just isn't running.