You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/06/24 08:59:03 UTC

[GitHub] [apisix] jinnyu opened a new issue, #7324: help request: How to use `map` defined variable for `http-logger` plugin metadata `log_format`?

jinnyu opened a new issue, #7324:
URL: https://github.com/apache/apisix/issues/7324

   ### Description
   
   Hi, I'm using `http-logger` plugin to log request to Loki.
   I configed `log_format` to this
   ```
   {
       "log_format": {
           "streams": [
               {
                   "stream": {
                       "serviceName": "$service_name",
                       "routeName": "$route_name",
                       "host": "$host",
                       "balancer": "$balancer_ip:$balancer_port"
                   },
                   "values": [
                       [
                           "$unix_ts",
                           "{\"ts\":\"$unix_ts\",\"status\":\"$status\",\"request\":{\"ua\":\"$http_user_agent\",\"body-size\":\"$body_bytes_sent\",\"request\":\"$request\"},\"upstream\":{\"addr\":\"$upstream_addr\",\"host\":\"$upstream_host\",\"uri\":\"$upstream_uri\",\"status\":\"$upstream_status\",\"responseTime\":\"$upstream_response_time\"}}"
                       ]
                   ]
               }
           ]
       }
   }
   ```
   (`$unix_ts` is defined by `map` config in apisix main config)
   ```
   apisix: 
     nginx_config:
       http_configuration_snippet: |
         map $msec $unix_ts {
           ~(.*)\.(.*) $1$2;
         }
   ```
   
   All config done, send request to apisix,
   Apisix report an error
   ```
   2022/06/24 14:14:27 [error] 49#49: *935 failed to run log_by_lua*: /usr/local/apisix/apisix/utils/log-util.lua:46: attempt to call method 'byte' (a nil value)
   stack traceback:
           /usr/local/apisix/apisix/utils/log-util.lua:46: in function 'create_obj_fun'
           /usr/local/apisix/apisix/core/lrucache.lua:95: in function 'lru_log_format'
           /usr/local/apisix/apisix/utils/log-util.lua:57: in function 'get_custom_format_log'
           /usr/local/apisix/apisix/plugins/http-logger.lua:167: in function 'phase_func'
           /usr/local/apisix/apisix/plugin.lua:771: in function 'run_plugin'
           /usr/local/apisix/apisix/plugin.lua:804: in function 'run_global_rules'
           /usr/local/apisix/apisix/init.lua:311: in function 'common_phase'
           /usr/local/apisix/apisix/init.lua:710: in function 'http_log_phase'
           log_by_lua(nginx.conf:309):2: in main chunk while logging request, client: 172.17.132.35, server: _, request: "GET /rest/2.0/ocr/v1/idcard HTTP/1.1", upstream: "[https://somehost.com:443/somepath](https://somehost.com/somepath)", host: "10.26.20.220:4006"
   ```
   
   So, are variables defined by the map method not supported in the plugin?
   And how to solve this?
   
   ### Environment
   
   - APISIX version (run `apisix version`): 2.14.1-centos (offical docker image)
   - Operating system (run `uname -a`): offical docker image
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`): offical docker image
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`): 3.4.18
   - APISIX Dashboard version, if relevant: 2.13-centos (offical docker image)
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] jinnyu commented on issue #7324: help request: How to use `map` defined variable for `http-logger` plugin's metadata `log_format`?

Posted by GitBox <gi...@apache.org>.
jinnyu commented on issue #7324:
URL: https://github.com/apache/apisix/issues/7324#issuecomment-1168420327

   For non Lua developers, it is difficult to customize plugins / variables,
   I'm not going to directly use `http-logger` to send logs to `Loki`,
   
   And after deep understanding, I found that the native `http-logger` could not cover my requirement
   I turned to use Java runner to send logs to Loki.
   
   But still thank you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] jinnyu commented on issue #7324: help request: How to use `map` defined variable for `http-logger` plugin's metadata `log_format`?

Posted by GitBox <gi...@apache.org>.
jinnyu commented on issue #7324:
URL: https://github.com/apache/apisix/issues/7324#issuecomment-1166790218

   When the `http-logger` plugin is not loaded, the `access_log` can be read to `$unix_ts` variable


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tokers commented on issue #7324: help request: How to use `map` defined variable for `http-logger` plugin's metadata `log_format`?

Posted by GitBox <gi...@apache.org>.
tokers commented on issue #7324:
URL: https://github.com/apache/apisix/issues/7324#issuecomment-1165436689

   Looks like the regex pattern is correct, could you add another `default` directive and try to see the value after the logs are handled by the `http-logger`?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] jinnyu closed issue #7324: help request: How to use `map` defined variable for `http-logger` plugin's metadata `log_format`?

Posted by GitBox <gi...@apache.org>.
jinnyu closed issue #7324: help request: How to use `map` defined variable for `http-logger` plugin's metadata `log_format`?
URL: https://github.com/apache/apisix/issues/7324


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] tzssangglass commented on issue #7324: help request: How to use `map` defined variable for `http-logger` plugin's metadata `log_format`?

Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #7324:
URL: https://github.com/apache/apisix/issues/7324#issuecomment-1168137024

   You can register custom variables for this purpose, see: https://github.com/apache/apisix/blob/master/docs/en/latest/plugin-develop.md#register-custom-variable, and example: https://github.com/apache/apisix/pull/6163/files


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [apisix] jinnyu commented on issue #7324: help request: How to use `map` defined variable for `http-logger` plugin's metadata `log_format`?

Posted by GitBox <gi...@apache.org>.
jinnyu commented on issue #7324:
URL: https://github.com/apache/apisix/issues/7324#issuecomment-1166790402

   > Looks like the regex pattern is correct, could you add another `default` directive and try to see the value after the logs are handled by the `http-logger`?
   
   When the http-logger plugin is not loaded, the access_log can be read to $unix_ts variable


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org