Ingress-nginx: log-format-stream doesn't quote custom value properly

Created on 17 Jul 2018  路  3Comments  路  Source: kubernetes/ingress-nginx

Is this a BUG REPORT or FEATURE REQUEST? (choose one):

BUG REPORT

NGINX Ingress controller version: 0.17.0

Kubernetes version (use kubectl version): 1.9.6

Environment:

  • Cloud provider or hardware configuration: Azure
  • OS (e.g. from /etc/os-release): CoreOS
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:

What happened:

Setting a custom log-format-stream option with log-format-escape-json set to true results in invalid configuration (log_format not terminated with ;). It appears there are two problems here. Setting log-format-escape-json, does not set the escape=json parameter for the stream log and the stream log is not surrounded by single quotes. I can workaround the single quotes by adding them to my configuration, but the lack of escape json will produce sometimes invalid json.

What you expected to happen:

The stream format log option can be set to a json format.

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know:

kinbug

Most helpful comment

@aledbf: Could we re-open this? The TCP and UDP features were removed but was reverted, and this is a legit issue. I can't use a custom log format for stream either:

2019/03/08 09:03:41 [emerg] 72#72: directive "log_format" is not terminated by ";" in /tmp/nginx-cfg220452230:2234
nginx: [emerg] directive "log_format" is not terminated by ";" in /tmp/nginx-cfg220452230:2234
nginx: configuration file /tmp/nginx-cfg220452230 test failed

EDIT: OK, I found a workaround. I have this config now:

  log-format-stream: '''{"time":"$time_iso8601","accessType":"stream","remote_addr":"$remote_addr","bytes_sent":$bytes_sent,"status":$status,"request_protocol":"$protocol","session_time":$session_time,"upstream_name":"$proxy_upstream_name","upstream_addr":"$upstream_addr"}'''

Note the extra qoutes at the start to force it between qoutes. I'm also not using any variables that could cause JSON issues, so the JSON escaping won't be an issue for me (even though I think we should have support for the escaping).

EDIT 2: OK, I found another workaround, for the escaping. This is my config now:

  log-format-stream: 'escape=json ''{"time":"$time_iso8601","accessType":"stream","remote_addr":"$remote_addr","bytes_sent":$bytes_sent,"status":$status,"request_protocol":"$protocol","session_time":$session_time,"upstream_name":"$proxy_upstream_name","upstream_addr":"$upstream_addr"}'''

Looks a bit strange, but it generates a correct config file. :)

All 3 comments

/kind bug

Closing. The TCP and UDP features are being removed.

@aledbf: Could we re-open this? The TCP and UDP features were removed but was reverted, and this is a legit issue. I can't use a custom log format for stream either:

2019/03/08 09:03:41 [emerg] 72#72: directive "log_format" is not terminated by ";" in /tmp/nginx-cfg220452230:2234
nginx: [emerg] directive "log_format" is not terminated by ";" in /tmp/nginx-cfg220452230:2234
nginx: configuration file /tmp/nginx-cfg220452230 test failed

EDIT: OK, I found a workaround. I have this config now:

  log-format-stream: '''{"time":"$time_iso8601","accessType":"stream","remote_addr":"$remote_addr","bytes_sent":$bytes_sent,"status":$status,"request_protocol":"$protocol","session_time":$session_time,"upstream_name":"$proxy_upstream_name","upstream_addr":"$upstream_addr"}'''

Note the extra qoutes at the start to force it between qoutes. I'm also not using any variables that could cause JSON issues, so the JSON escaping won't be an issue for me (even though I think we should have support for the escaping).

EDIT 2: OK, I found another workaround, for the escaping. This is my config now:

  log-format-stream: 'escape=json ''{"time":"$time_iso8601","accessType":"stream","remote_addr":"$remote_addr","bytes_sent":$bytes_sent,"status":$status,"request_protocol":"$protocol","session_time":$session_time,"upstream_name":"$proxy_upstream_name","upstream_addr":"$upstream_addr"}'''

Looks a bit strange, but it generates a correct config file. :)

Was this page helpful?
0 / 5 - 0 ratings