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

   ### Current Behavior
   
   When I use meta.filter in the plugin like this:
   
   ```
   curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{
     "plugins": {
       "file-logger": {
            "_meta": {
               "filter": [
                   ["upstream_status", "~=", 200]
               ]
           },
         "path": "logs/file.log"
       }
     },
     "upstream": {
       "type": "roundrobin",
       "nodes": {
         "httpbin.org": 1
       }
     },
     "uri": "/*"
   }'
   ```
   
   What I expect is that when the upstream_status is not equal to 200, then we 
will write a log into the file.
   But now, the plugin will be executed even if the upstream_status is 200.
   
   Reason:
   Because when we do the plugin filter, we can't get the upstream_status 
(because we hadn't send request to upstream), so the value of 
`ngx.var.upstream_status` is nil, and the filter is always matched.
   
   
https://github.com/apache/apisix/blob/47187faccd96d02773fb1c71980c8ca0ea838d6a/apisix/plugin.lua#L421-L458
   
   
   
   
   ### Expected Behavior
   
   The meta.filter can work even if the plugin is run at the log phase.
   
   ### Error Logs
   
   _No response_
   
   ### Steps to Reproduce
   
   1. Create route
   
   ```
   curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '{
     "plugins": {
       "file-logger": {
            "_meta": {
               "filter": [
                   ["upstream_status", "~=", 200]
               ]
           },
         "path": "logs/file.log"
       }
     },
     "upstream": {
       "type": "roundrobin",
       "nodes": {
         "httpbin.org": 1
       }
     },
     "uri": "/*"
   }'
   ```
   
   2. Send two requests
   
   ```
   curl localhost:9080/status/200 -v
   ```
   
   ```
   curl localhost:9080/status/400 -v
   ```
   
   3. We can see both requests are logged.
   <img width="1877" alt="image" 
src="https://user-images.githubusercontent.com/25628854/188102089-0ec70f70-0ff6-4036-9a50-bf858a9b097b.png";>
   
   
   
   ### Environment
   
   - APISIX version (run `apisix version`): 2.15.0
   - Operating system (run `uname -a`): 
   - 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:
   - 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to