You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "yujinchoi-94 (via GitHub)" <gi...@apache.org> on 2023/10/23 01:57:19 UTC

[I] help request: upstream related header is missing when using external plugins [apisix]

yujinchoi-94 opened a new issue, #10369:
URL: https://github.com/apache/apisix/issues/10369

   ### Description
   
   Hi,
   
   I am using `ext-plugin-post-req`, `ext-plugin-post-resp` and sending logs to loki using `loki-logger`. However, when i enabled external plugins, upstream related header is missing in logs.
   
   It [seems](https://github.com/apache/apisix/blob/master/apisix/utils/log-util.lua#L151) that upstream related variables is using nginx variable. I tried to log them in the external plugin code but it returns nothing.
   
   TestFilter
   ```java
       @Override
       public void filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
           LOG.error("[TestFilter - postReq]" + NginxVars.UPSTREAM_RESPONSE_TIME.getValue() + ": " + request.getVars(NginxVars.UPSTREAM_RESPONSE_TIME.getValue()));
           LOG.error("[TestFilter - postReq]" + NginxVars.UPSTREAM_ADDR.getValue() + ": " + request.getVars(NginxVars.UPSTREAM_ADDR.getValue()));
           LOG.error("[TestFilter - postReq]" + NginxVars.REQUEST_URI.getValue() + ": " + request.getVars(NginxVars.REQUEST_URI.getValue()));
           chain.filter(request, response);
       }
   
       @Override
       public void postFilter(PostRequest request, PostResponse response, PluginFilterChain chain) {
           response.setHeader(NginxVars.UPSTREAM_ADDR.getValue(),
                   request.getVars(NginxVars.UPSTREAM_ADDR.getValue()));
           response.setHeader(NginxVars.UPSTREAM_RESPONSE_TIME.getValue(),
                   request.getVars(NginxVars.UPSTREAM_RESPONSE_TIME.getValue()));
   
           LOG.error("[TestFilter - postRes]" + NginxVars.UPSTREAM_RESPONSE_TIME.getValue() + ": " + request.getVars(NginxVars.UPSTREAM_RESPONSE_TIME.getValue()));
           LOG.error("[TestFilter - postRes]" + NginxVars.UPSTREAM_ADDR.getValue() + ": " + request.getVars(NginxVars.UPSTREAM_ADDR.getValue()));
           LOG.error("[TestFilter - postRes]" + NginxVars.REQUEST_URI.getValue() + ": " + request.getVars(NginxVars.REQUEST_URI.getValue()));
           chain.postFilter(request, response);
       }
   
       @Override
       public List<String> requiredVars() {
           List<String> vars = new ArrayList<>();
           vars.add(NginxVars.HTTP_ACCEPT.getValue());
           vars.add(NginxVars.REQUEST_URI.getValue());
           vars.add(NginxVars.HTTP_OPENAPI_ORIGINAL_ACCEPT.getValue());
           vars.add(NginxVars.HTTP_OPENAPIKEY.getValue());
           vars.add(NginxVars.UPSTREAM_RESPONSE_TIME.getValue());
           vars.add(NginxVars.UPSTREAM_ADDR.getValue());
           return vars;
       }
   ```
   Plugins Logs
   ```
   2023-10-23 01:53:43,844 ERROR epollEventLoopGroup-2-5          - [TestFilter - postReq]upstream_response_time:
    2023-10-23 01:53:43,844 ERROR epollEventLoopGroup-2-5          - [TestFilter - postReq]upstream_addr:
    2023-10-23 01:53:43,844 ERROR epollEventLoopGroup-2-5          - [TestFilter - postReq]request_uri: /rest/.../...(omit for security)
    2023-10-23 01:53:43,862 ERROR epollEventLoopGroup-2-5          - [TestFilter - postRes]upstream_response_time:
    2023-10-23 01:53:43,862 ERROR epollEventLoopGroup-2-5          - [TestFilter - postRes]upstream_addr:
    2023-10-23 01:53:43,863 ERROR epollEventLoopGroup-2-5          - [TestFilter - postRes]request_uri: /rest/../...(omit for security)
   ```
   
   
   Loki (without external plugins)
   <img width="594" alt="스크린샷 2023-10-23 오전 10 44 47" src="https://github.com/apache/apisix/assets/30385786/eb10f56d-2b30-440e-a444-02af8165b6c6">
   
   Loki (with external plugins)
   <img width="585" alt="스크린샷 2023-10-23 오전 10 45 12" src="https://github.com/apache/apisix/assets/30385786/04905c57-13d4-4326-b36c-56c11483bac3">
   
   Here's my plugin configuration
   ```
         plugins:
           - config:
               client_headers:
                 ...
               request_headers:
                 ...
               request_method: GET
               upstream_headers:
                 ...
               uri: '...'
             enable: true
             name: forward-auth
           - config:
               disable: false
               prefer_name: true
             enable: true
             name: prometheus
           - config:
               endpoint_addrs:
                 - >-
                   http://loki-loki-distributed-gateway.monitor.svc.cluster.local:80
               include_req_body: true
               include_req_body_expr:
                 - - http_response_status
                   - ~*
                   - '200'
               include_resp_body: true
               include_resp_body_expr:
                 - - http_response_status
                   - ~*
                   - '200'
               tenant_id: dev-openapi-logging
             enable: true
             name: loki-logger
           - config:
               headers:
                 ...
               uri: ...
             enable: true
             name: proxy-rewrite
           - config:
               conf:
                 - name: TestFilter
                   value: |
                     test
             enable: true
             name: ext-plugin-post-req
           - config:
               conf:
                 - name: TestFilter
                   value: |
                     test
             enable: true
             name: ext-plugin-post-resp
   ```
   
   
   Could you help me to get upstream related headers?
   Thanks,
   
   ### Environment
   
   - APISIX version (run `apisix version`):
   ```
   apisix version
   /usr/local/openresty//luajit/bin/luajit /usr/local/apisix/apisix/cli/apisix.lua version
   3.4.0
   ```
   - Operating system (run `uname -a`):
   ```
   uname -a
   Linux dev-apisix-56c7dc6b9-m2mfx 5.10.192-183.736.amzn2.x86_64 #1 SMP Wed Sep 6 21:15:41 UTC 2023 x86_64 GNU/Linux
   ```
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners: apisix-java-plugin-runner 0.4.0
   - 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


Re: [I] help request: upstream related header is missing when using external plugins [apisix]

Posted by "sheharyaar (via GitHub)" <gi...@apache.org>.
sheharyaar commented on issue #10369:
URL: https://github.com/apache/apisix/issues/10369#issuecomment-1888775493

   @monkeyDluffy6017 @shreemaan-abhishek , can you please assign me this ?


-- 
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


Re: [I] help request: upstream related header is missing when using external plugins [apisix]

Posted by "MariaLapovska (via GitHub)" <gi...@apache.org>.
MariaLapovska commented on issue #10369:
URL: https://github.com/apache/apisix/issues/10369#issuecomment-3900366603

   @sheharyaar @shreemaan-abhishek 
   
   These Nginx variables are set by Nginx's proxy module when it makes the upstream request. But `ext-plugin-post-resp` uses `lua-resty-http` to make the upstream request instead of Nginx's proxy module.
   
   Since `lua-resty-http` bypasses Nginx's proxy, specifically these two variables are never set:
   - $upstream_addr
   - $upstream_response_time 
   
   That's why when `log-util.lua` tries to obtain them from nginx vars, it can't find anything.
   
   This is an issue with `ext-plugin-post-resp` - I'm facing the same thing.


-- 
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


Re: [I] help request: upstream related header is missing when using external plugins [apisix]

Posted by "sheharyaar (via GitHub)" <gi...@apache.org>.
sheharyaar commented on issue #10369:
URL: https://github.com/apache/apisix/issues/10369#issuecomment-1909467901

   @yujinchoi-94 did this solution work ?


-- 
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


Re: [I] help request: upstream related header is missing when using external plugins [apisix]

Posted by "sheharyaar (via GitHub)" <gi...@apache.org>.
sheharyaar commented on issue #10369:
URL: https://github.com/apache/apisix/issues/10369#issuecomment-1894193859

   Hi @yujinchoi-94 , can you try using extra-info as done here.
   Definition : https://github.com/apache/apisix/blob/master/t/lib/ext-plugin.lua#L59
   Invocation : https://github.com/apache/apisix/blob/master/t/plugin/ext-plugin/extra-info.t#L106-L130
   
   Source Reference : 
   - https://github.com/apache/apisix-java-plugin-runner/blob/main/runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/RpcCallHandler.java#L110-L145


-- 
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


Re: [I] help request: upstream related header is missing when using external plugins [apisix]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #10369:
URL: https://github.com/apache/apisix/issues/10369#issuecomment-2024818987

   This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.


-- 
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


Re: [I] help request: upstream related header is missing when using external plugins [apisix]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed issue #10369: help request: upstream related header is missing when using external plugins
URL: https://github.com/apache/apisix/issues/10369


-- 
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


Re: [I] help request: upstream related header is missing when using external plugins [apisix]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #10369:
URL: https://github.com/apache/apisix/issues/10369#issuecomment-2017628135

   Due to lack of the reporter's response this issue has been labeled with "no response". It will be close in 3 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.


-- 
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