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 2021/09/21 11:31:48 UTC

[GitHub] [apisix] tinpad opened a new issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

tinpad opened a new issue #5109:
URL: https://github.com/apache/apisix/issues/5109


   ### Issue description
   
   I am using below command to enable proxy-cache plugin on my route -
   
   curl http://127.0.0.1:9080/apisix/admin/routes/73  -H 'X-API-KEY: xxxxxxxxxxxxxxxxxxx' -X PUT -d '{
       "plugins": {
           "proxy-cache": {
               "cache_key":  ["$uri", "-cache-id"],
               "cache_bypass": ["$arg_bypass"],
               "cache_method": ["GET"],
               "cache_http_status": [200],
               "hide_cache_headers": true,
               "no_cache": ["$arg_test"]
           }
       },
       "upstream": {
           "service_name": "ORDERSERVICE",
           "type": "roundrobin",
           "discovery_type": "eureka"
       },
       "uri": "/order/list"
   }'
   
   the configuration in config.yaml is as follows -
   
   proxy_cache:                       
         cache_ttl: 60s                 
         zones:                        
          - name: disk_cache_one                
            memory_size: 50m             
            disk_size: 1G                
            disk_path: "/tmp/disk_cache_one"
            cache_levels: "1:2"
   
   ### Environment
   
       apisix version (cmd: apisix version): 2.8
       OS (cmd: uname -a): 20.04.1-Ubuntu
       OpenResty / Nginx version (cmd: nginx -V or openresty -V): openresty/1.19.3.2
       etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API): 3.4.0
       apisix-dashboard version, if have: NA
       the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
       luarocks version, if the issue is about installation (cmd: luarocks --version): 3.4.0
   
   ### Steps to reproduce
   
   1. Enable proxy-cache plugin
   2. Add Configuration in config.yaml file as above.
   3. Test with curl http://127.0.0.1:9080/order/list?pageSize=10  -i
   
   
   ### Actual result
   
   Here are two tests, executed within approx. 20 seconds
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 99
   Date: Tue, 21 Sep 2021 11:22:07 GMT
   Server: APISIX/2.8
   X-Request-Id: fef66141-0931-4e7e-9997-ffa60c10a1ff
   Apisix-Cache-Status: EXPIRED
   
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 98
   Date: Tue, 21 Sep 2021 11:22:26 GMT
   Server: APISIX/2.8
   X-Request-Id: 4682662d-0690-4eb5-89a9-f2df49ba2c91
   Apisix-Cache-Status: EXPIRED
   
   ### Error log
   
   NA
   
   ### Expected result
   
   Here are two tests, executed within approx. 20 seconds
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 99
   Date: Tue, 21 Sep 2021 11:22:07 GMT
   Server: APISIX/2.8
   X-Request-Id: fef66141-0931-4e7e-9997-ffa60c10a1ff
   Apisix-Cache-Status: EXPIRED
   
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 98
   Date: Tue, 21 Sep 2021 11:22:26 GMT
   Server: APISIX/2.8
   X-Request-Id: 4682662d-0690-4eb5-89a9-f2df49ba2c91
   Apisix-Cache-Status: HIT


-- 
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 #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   It's weird that the no `Cache-Control` or `Pragma` headers are set in your response. Could you show the response when you request to the Upstream directly.


-- 
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] shuaijinchao commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   According to your configuration, I cannot reproduce the problem you provided. Is there an exception thrown in the error log when a timeout occurs?


-- 
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] tinpad commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   @shuaijinchao I don't see any specific error log for this particular scenario, however just for reference, below the latest error log - 
   
   2021/09/21 19:28:48 [error] 3187#3187: *30139 [lua] config_etcd.lua:596: failed to fetch data from etcd: http://127.0.0.1:2379: Service Unavailable,  etcd key: /apisix/upstreams, context: ngx.timer
   2021/09/21 19:28:48 [error] 3187#3187: *30187 [lua] config_etcd.lua:596: failed to fetch data from etcd: http://127.0.0.1:2379: Service Unavailable,  etcd key: /apisix/plugin_metadata, context: ngx.timer
   2021/09/21 19:28:48 [error] 3187#3187: *30378 [lua] config_etcd.lua:596: failed to fetch data from etcd: http://127.0.0.1:2379: Service Unavailable,  etcd key: /apisix/consumers, context: ngx.timer
   2021/09/21 19:28:48 [error] 3187#3187: *30268 [lua] config_etcd.lua:596: failed to fetch data from etcd: http://127.0.0.1:2379: Service Unavailable,  etcd key: /apisix/ssl, context: ngx.timer
   2021/09/21 19:28:48 [error] 3187#3187: *30119 [lua] config_etcd.lua:596: failed to fetch data from etcd: http://127.0.0.1:2379: Service Unavailable,  etcd key: /apisix/global_rules, context: ngx.timer
   2021/09/22 12:54:50 [warn] 2103#2103: *1 [lua] plugin.lua:150: load(): new plugins: {"redirect":true,"prometheus":true,"api-breaker":true,"server-info":true,"limit-count":true,"uri-blocker":true,"syslog":true,"request-id":true,"proxy-rewrite":true,"basic-auth":true,"fault-injection":true,"consumer-restriction":true,"proxy-cache":true,"response-rewrite":true,"request-validation":true,"http-logger":true}, context: init_worker_by_lua*
   2021/09/22 12:54:50 [warn] 2106#2106: *2 [lua] plugin.lua:150: load(): new plugins: {"redirect":true,"prometheus":true,"api-breaker":true,"server-info":true,"limit-count":true,"uri-blocker":true,"syslog":true,"request-id":true,"proxy-rewrite":true,"basic-auth":true,"fault-injection":true,"consumer-restriction":true,"proxy-cache":true,"response-rewrite":true,"request-validation":true,"http-logger":true}, context: init_worker_by_lua*
   2021/09/22 12:54:50 [warn] 2103#2103: *1 [lua] plugin.lua:192: load_stream(): new plugins: {"limit-conn":true,"ip-restriction":true,"mqtt-proxy":true}, context: init_worker_by_lua*
   2021/09/22 12:54:50 [warn] 2106#2106: *2 [lua] plugin.lua:192: load_stream(): new plugins: {"limit-conn":true,"ip-restriction":true,"mqtt-proxy":true}, context: init_worker_by_lua*
   2021/09/22 12:56:08 [warn] 2103#2103: *1638 [lua] plugin.lua:658: run_plugin(): basic-auth exits with http status code 401, client: 192.168.1.3, server: _, request: "GET /products/list HTTP/1.1", host: "x.x.x.x:9080"
   2021/09/22 12:56:39 [error] 2103#2103: *2699 [lua] batch-processor.lua:63: Batch Processor[http logger] failed to process entries: failed to connect to host[192.168.1.2] port[8060] timeout, context: ngx.timer, client: x.x.x.x, server: 0.0.0.0:9080
   2021/09/22 12:56:39 [error] 2103#2103: *2699 [lua] batch-processor.lua:70: Batch Processor[http logger] exceeded the max_retry_count[1] dropping the entries, context: ngx.timer, client: x.x.x.x, server: 0.0.0.0:9080


-- 
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] tinpad commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   I am using -i in curl


-- 
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] shuaijinchao commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   I tested it locally through the configuration you provided. The first access result was MISS, and the second time was HIT. From the test results, there is no problem. Can you provide a method that can stably reproduce the problem?


-- 
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] shuaijinchao commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   When you use curl to test, do you use `-i` or `-I` for the i parameter? If you use the uppercase `-I` because only the response header information is obtained, in this case the status of `Apisix-Cache-Status` will always respond as `EXPIRED`.


-- 
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 #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   Please wait a minute, it seems the result in the issue description is correct, `EXPIRED` means APISIX check the local cache and found it's expired, so it proxies requests to upstream. After 20 seconds, the local cache indeed was expired, so another request was sent to upstream and thus you saw the header `Apisix-Cache-Status` with value `EXPIRED` again.


-- 
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] tinpad closed issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

Posted by GitBox <gi...@apache.org>.
tinpad closed issue #5109:
URL: https://github.com/apache/apisix/issues/5109


   


-- 
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 #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   > 2\. Apisix-Cache-Status = HIT for 10 seconds only even if I have configured it to 1000s in the yaml file.
   
   It looks like you made a formatting error in your configuration, such as indent


-- 
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] tinpad commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   conf.yaml configuration - 
   
   proxy_cache:                       
         cache_ttl: 1000s                 
         zones:                         
          - name: disk_cache_one         
                                      
            memory_size: 50m            
            disk_size: 1G                
            disk_path: "/tmp/disk_cache_one" 
            cache_levels: "1:2"
   
   please refer below consecutive executions - 
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 96
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: 0b55cd16-60b1-4170-80d8-81d15c618554
   Apisix-Cache-Status: EXPIRED
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 95
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: 2814df47-8177-47c6-bb2a-ec6a740abe3b
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 94
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: c8903e4a-e45c-48f1-9695-827df576cb55
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 93
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: 95ad6997-e2e4-4c36-a0e4-6ac5179c2a8d
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 92
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: 0e4e4018-3cb2-4d91-b5a3-3548b9cbe318
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 99
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: 34771422-d0ab-4f3b-bd83-696728bb438c
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 98
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: 9622559b-7b31-40b7-98a5-562084873143
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 97
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: cd78d7c4-bb1c-480f-b70c-1c5207012729
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 96
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: f4c2bd6e-22bb-4fa1-b9ac-587164d70644
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 95
   Date: Tue, 21 Sep 2021 13:28:50 GMT
   Server: APISIX/2.8
   X-Request-Id: e8b67bd0-6371-4d0e-b7f4-de5ad521b879
   Apisix-Cache-Status: HIT
   
   curl http://127.0.0.1:9080/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Connection: keep-alive
   X-RateLimit-Limit: 100
   X-RateLimit-Remaining: 94
   Date: Tue, 21 Sep 2021 13:29:01 GMT
   Server: APISIX/2.8
   X-Request-Id: bd4485a1-00cd-4524-bb67-10e906c58e08
   Apisix-Cache-Status: EXPIRED
   
   Observations-
   1. Date header's value in response doesn't change as long as Apisix-Cache-Status = HIT [Date: Tue, 21 Sep 2021 13:28:50 GMT]
   2. Apisix-Cache-Status = HIT for 10 seconds only even if I have configured it to 1000s in the yaml file.
   3. We have also restarted APISIX, ETCD after modifying the yaml file but the results are still same as above.
   
   Could you please let me know why the cache_ttl value is not picked up by APISIX.
   Is there any other solution for this problem, or let us know if there is any other configuration we need to update in order to make it 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



[GitHub] [apisix] tinpad commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   @tokers please find below the response of a direct request to upstream -
   
   curl http://192.168.1.3:8090/order/list?pageSize=10 -i
   HTTP/1.1 200 
   Content-Type: application/json
   Transfer-Encoding: chunked
   Date: Wed, 22 Sep 2021 07:36:27 GMT
   


-- 
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] tinpad commented on issue #5109: bug: cache_ttl not working in proxy-cache plugin as expected

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


   @tzssangglass the issue resolved. There were two issues -
   1. I had defined the cache configuration under plugin_attr.
   2. Wrong Indentation 
   
   It is working fine now, Thanks for your help.


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