tzssangglass commented on a change in pull request #5881:
URL: https://github.com/apache/apisix/pull/5881#discussion_r774361920



##########
File path: t/plugin/limit-count2.t
##########
@@ -480,11 +448,240 @@ passed
             ngx.say(json.encode(ress))
         }
     }
---- request
-GET /t
---- no_error_log
-[error]
 --- response_body
 [200,200,503,503]
 --- error_log
 The value of the configured key is empty, use client IP instead
+
+
+
+=== TEST 15: limit count in group
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "limit-count": {
+                            "count": 2,
+                            "time_window": 60,
+                            "rejected_code": 503,
+                            "group": "services_1"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/hello"
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+
+            local code, body = t('/apisix/admin/routes/2',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "limit-count": {
+                            "count": 2,
+                            "time_window": 60,
+                            "rejected_code": 503,
+                            "group": "services_1"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    },
+                    "uri": "/hello_chunked"
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 16: hit multiple paths
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require "t.toolkit.json"
+            local http = require "resty.http"
+            local uri1 = "http://127.0.0.1:"; .. ngx.var.server_port
+                        .. "/hello"
+            local uri2 = "http://127.0.0.1:"; .. ngx.var.server_port
+                        .. "/hello_chunked"
+            local ress = {}
+            for i = 1, 4 do
+                local httpc = http.new()
+                local uri
+                if i % 2 == 1 then
+                    uri = uri1
+                else
+                    uri = uri2
+                end
+
+                local res, err = httpc:request_uri(uri)
+                if not res then
+                    ngx.say(err)
+                    return
+                end
+                table.insert(ress, res.status)
+            end
+            ngx.say(json.encode(ress))
+        }
+    }
+--- response_body
+[200,200,503,503]
+
+
+
+=== TEST 17: limit count in group, configuration is from services
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/services/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "limit-count": {
+                            "count": 2,
+                            "time_window": 60,
+                            "rejected_code": 503,
+                            "group": "afafafhao"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    }
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+
+
+            local code, body = t('/apisix/admin/routes/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "service_id": "1",
+                    "uri": "/hello"
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+            local code, body = t('/apisix/admin/routes/2',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "service_id": "1",
+                    "uri": "/hello_chunked"
+                }]]
+                )
+            if code >= 300 then
+                ngx.status = code
+                return
+            end
+            ngx.say(body)
+        }
+    }
+--- response_body
+passed
+
+
+
+=== TEST 18: hit multiple paths
+--- config
+    location /t {
+        content_by_lua_block {
+            local json = require "t.toolkit.json"
+            local http = require "resty.http"
+            local uri1 = "http://127.0.0.1:"; .. ngx.var.server_port
+                        .. "/hello"
+            local uri2 = "http://127.0.0.1:"; .. ngx.var.server_port
+                        .. "/hello_chunked"
+            local ress = {}
+            for i = 1, 4 do
+                local httpc = http.new()
+                local uri
+                if i % 2 == 1 then
+                    uri = uri1
+                else
+                    uri = uri2
+                end
+
+                local res, err = httpc:request_uri(uri)
+                if not res then
+                    ngx.say(err)
+                    return
+                end
+                table.insert(ress, res.status)
+            end
+            ngx.say(json.encode(ress))
+        }
+    }
+--- response_body
+[200,200,503,503]
+
+
+
+=== TEST 19: configuration from the same group should be the same
+--- config
+    location /t {
+        content_by_lua_block {
+            local t = require("lib.test_admin").test
+            local code, body = t('/apisix/admin/services/1',
+                 ngx.HTTP_PUT,
+                 [[{
+                    "plugins": {
+                        "limit-count": {
+                            "count": 1,
+                            "time_window": 60,
+                            "rejected_code": 503,
+                            "group": "afafafhao"
+                        }
+                    },
+                    "upstream": {
+                        "nodes": {
+                            "127.0.0.1:1980": 1
+                        },
+                        "type": "roundrobin"
+                    }
+                }]]
+                )
+
+            if code >= 300 then
+                ngx.status = code
+            end
+            ngx.print(body)
+        }
+    }
+--- error_code: 400
+--- error_log
+[error]
+--- response_body
+{"error_msg":"failed to check the configuration of plugin limit-count err: 
group conf mismatched"}

Review comment:
       How can we update the limit-count config?

##########
File path: docs/zh/latest/plugins/limit-count.md
##########
@@ -112,6 +113,54 @@ curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 
'X-API-KEY: edd1c9f034335
 你也可以通过 web 界面来完成上面的操作,先增加一个 route,然后在插件页面中添加 limit-count 插件:
 ![添加插件](../../../assets/images/plugin/limit-count-1.png)
 
+我们也支持在多个 Route 间共享同样的限流计数器。举个例子,

Review comment:
       ```suggestion
   我们也支持在多个 Route 间共享同一个限流计数器。举个例子,
   ```
   
   When different limit-count plugins have the same group, it means that these 
plugins share a unique limit counter and requests passing through them will 
increment on this counter.
   
   I don't know if I'm wrong.
   




-- 
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-unsubscr...@apisix.apache.org

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


Reply via email to