-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: support limit-conn in workflow plugin #12465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nic-6443
merged 14 commits into
apache:master
from
Revolyssup:revolyssup/limit-conn-workflow
Aug 6, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
32eff7d
feat: support limit-conn in workflow plugin
Revolyssup 5a47efd
update doc
Revolyssup d065edf
fix lint
Revolyssup 3327c7d
add caching on conf and ctx
Revolyssup 09f5a3d
change order
Revolyssup 2e3c4eb
fix lint
Revolyssup 503511b
set workflow_cache unconditionally
Revolyssup 6aab274
apply suggestion
Revolyssup 029829d
apply
Revolyssup aefe1d6
lint
Revolyssup 23775ea
apply suggestion
Revolyssup 8189952
apply suggetions
Revolyssup 8fd98c5
fix lint
Revolyssup e11192c
revert suggestion
Revolyssup File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| BEGIN { | ||
| if ($ENV{TEST_NGINX_CHECK_LEAK}) { | ||
| $SkipReason = "unavailable for the hup tests"; | ||
|
|
||
| } else { | ||
| $ENV{TEST_NGINX_USE_HUP} = 1; | ||
| undef $ENV{TEST_NGINX_USE_STAP}; | ||
| } | ||
| } | ||
|
|
||
| use t::APISIX 'no_plan'; | ||
|
|
||
| repeat_each(1); | ||
| no_long_string(); | ||
| no_root_location(); | ||
| no_shuffle(); | ||
| add_block_preprocessor(sub { | ||
| my ($block) = @_; | ||
| my $port = $ENV{TEST_NGINX_SERVER_PORT}; | ||
| my $config = $block->config // <<_EOC_; | ||
| location /access_root_dir { | ||
| content_by_lua_block { | ||
| local httpc = require "resty.http" | ||
| local hc = httpc:new() | ||
|
|
||
| local res, err = hc:request_uri('http://127.0.0.1:$port/limit_conn') | ||
| if res then | ||
| ngx.exit(res.status) | ||
| end | ||
| } | ||
| } | ||
|
|
||
| location /test_concurrency { | ||
| content_by_lua_block { | ||
| local reqs = {} | ||
| for i = 1, 10 do | ||
| reqs[i] = { "/access_root_dir" } | ||
| end | ||
| local resps = { ngx.location.capture_multi(reqs) } | ||
| for i, resp in ipairs(resps) do | ||
| ngx.say(resp.status) | ||
| end | ||
| } | ||
| } | ||
| _EOC_ | ||
|
|
||
| $block->set_value("config", $config); | ||
| if (!$block->request) { | ||
| $block->set_value("request", "GET /t"); | ||
| } | ||
| }); | ||
|
|
||
| run_tests(); | ||
|
|
||
|
|
||
| __DATA__ | ||
|
|
||
| === TEST 1: limit-conn | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local json = require("toolkit.json") | ||
| local t = require("lib.test_admin").test | ||
| local data = { | ||
| uri = "/*", | ||
| plugins = { | ||
| workflow = { | ||
| rules = { | ||
| { | ||
| case = { | ||
| {"uri", "==", "/limit_conn"} | ||
| }, | ||
| actions = { | ||
| { | ||
| "limit-conn", | ||
| { | ||
| conn = 2, | ||
| burst = 1, | ||
| default_conn_delay = 0.1, | ||
| rejected_code = 503, | ||
| key = "remote_addr" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| upstream = { | ||
| nodes = { | ||
| ["127.0.0.1:1980"] = 1 | ||
| }, | ||
| type = "roundrobin" | ||
| } | ||
| } | ||
| local code, body = t('/apisix/admin/routes/1', | ||
| ngx.HTTP_PUT, | ||
| json.encode(data) | ||
| ) | ||
|
|
||
| if code >= 300 then | ||
| ngx.status = code | ||
| end | ||
|
|
||
| ngx.say(body) | ||
| } | ||
| } | ||
| --- response_body | ||
| passed | ||
|
|
||
|
|
||
|
|
||
| === TEST 2: exceeding the burst | ||
| --- request | ||
| GET /test_concurrency | ||
| --- timeout: 10s | ||
| --- response_body | ||
| 200 | ||
| 200 | ||
| 200 | ||
| 503 | ||
| 503 | ||
| 503 | ||
| 503 | ||
| 503 | ||
| 503 | ||
| 503 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.