-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: validate the subordinate and check reference when deleting and adding… #8219
feat: validate the subordinate and check reference when deleting and adding… #8219
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add test in https://github.com/apache/apisix/blob/master/t/admin/stream-routes.t?
You can find some info at https://github.com/apache/apisix/blob/master/docs/en/latest/internal/testing-framework.md
I want to ask a question : core.etcd.set("/apisix/stream_routes/refer/12",{"/apisix/stream_routes/22":1}) Is additional serialization required? Can you give me some pointers? @spacewander |
read more: api7/lua-resty-etcd#180 (comment) |
|
Some problems have been changed; thank for the review, and hope to communicate @spacewander @tzssangglass |
Please make the test & lint pass, like:
https://github.com/apache/apisix/actions/runs/3376629320/jobs/5619505955
|
please approve running workflows @spacewander |
@@ -639,3 +639,30 @@ passed | |||
{"error_msg":"property \"faults\" validation failed: wrong type: expected array, got string"} | |||
--- no_error_log | |||
[error] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need three blank lines between test cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
apisix/admin/stream_routes.lua
Outdated
local referkey = "/stream_routes_refer/" .. id | ||
local _, err = core.etcd.delete(referkey) | ||
core.log.warn(err) | ||
core.log.warn(items) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
core.log.warn(items) | |
core.log.info("items:", core.json.delay_encode(items)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
apisix/admin/stream_routes.lua
Outdated
local refer_list = {} | ||
local referkey = "/stream_routes_refer/" .. id | ||
local _, err = core.etcd.delete(referkey) | ||
core.log.warn(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the err
here only printed and not processed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleting a stream route, check if it is referenced by another stream route ; before query ,delete previous value and then generate new。 Just delete previous , I choose to ignore exceptions handle because I can't think of errors happening
apisix/admin/stream_routes.lua
Outdated
else | ||
core.log.error("In function check_router_refer error: ", err) | ||
end | ||
local setres, err = core.etcd.set(setkey, data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid writing this data to etcd. You set here, I don't see where we delete key. so stream_routes_refer
will grow forever?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keys stream_routes_refer/super_ids will be update rather than grow .
ex:
/apisix/stream_routes_refer/12
{"_apisix_stream_routes_22":1,"_apisix_stream_routes_23":1}
it meas the stream_route 22 and 23 have protocol.superior_id 12; if the stream_routes rule no change ,the value no change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so at what point do we delete /apisix/stream_routes_refer/12
?
Anyway, I don't think it's a good solution to write this relationship to etcd.
Can we refer to the logic for removing the upstream?
apisix/apisix/admin/upstreams.lua
Lines 146 to 156 in a62d33f
if services_ver and services then | |
for _, service in ipairs(services) do | |
if type(service) == "table" and service.value | |
and service.value.upstream_id | |
and tostring(service.value.upstream_id) == id then | |
return 400, {error_msg = "can not delete this upstream," | |
.. " service [" .. service.value.id | |
.. "] is still using it now"} | |
end | |
end | |
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your suggestion I changed the implementation.
apisix/admin/stream_routes.lua
Outdated
if route.protocol and route.protocol.superior_id then | ||
local data | ||
local setkey = "/stream_routes_refer/" .. route.protocol.superior_id | ||
local res, err = core.etcd.get(setkey, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have to filter the data by superior_id
in etcd every time when we delete an item like this? That might be very inefficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For generate the reference-relationship while iterating over the items(stream_routes), only the data by superior_id exists reference-relationship.
thanks for your suggestion。
dac6b2b
to
94cdf53
Compare
apisix/admin/stream_routes.lua
Outdated
if item.value == nil then | ||
goto CONTINUE | ||
end | ||
local r_id = string.gsub(item["key"], "/", "_") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we replace string.gsub
with ngx.re.gsub
?
I successfully tested locally: -----request
|
apisix/admin/stream_routes.lua
Outdated
@@ -78,6 +102,14 @@ local function check_conf(id, conf, need_id) | |||
return need_id and id or true | |||
end | |||
|
|||
function _M.stream_routes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified,please have a look
apisix/admin/init.lua
Outdated
core.config.init() | ||
local router_stream = require("apisix.stream.router.ip_port") | ||
router_stream.stream_init_worker(filter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here: #8219 (comment) means move router_stream.stream_init_worker(filter)
to function _M.init_worker()
, not local function run()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
apisix/admin/init.lua
Outdated
@@ -19,6 +19,7 @@ local core = require("apisix.core") | |||
local route = require("apisix.utils.router") | |||
local plugin = require("apisix.plugin") | |||
local v3_adapter = require("apisix.admin.v3_adapter") | |||
local filter = require("apisix.router").filter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to export filter first so we can use it:
Line 30 in ae400b9
local function filter(route) |
apisix/admin/init.lua
Outdated
@@ -14,6 +14,7 @@ | |||
-- See the License for the specific language governing permissions and | |||
-- limitations under the License. | |||
-- | |||
local filter = require("apisix.router").filter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does module apisix.router
export the function filter
?
BTW, the require
call should be put under local require = require
.
apisix/admin/init.lua
Outdated
@@ -15,6 +15,7 @@ | |||
-- limitations under the License. | |||
-- | |||
local require = require | |||
local filter = require("apisix.router").filter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does module "apisix.router" export the filter function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry
…om/biakecw/apisix into check-the-subordinate-relationship
@@ -354,7 +353,7 @@ function _M.init_worker() | |||
|
|||
if local_conf.apisix.stream_proxy then | |||
local router_stream = require("apisix.stream.router.ip_port") | |||
router_stream.stream_init_worker(filter) | |||
router_stream.stream_init_worker() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to export the filter and pass it into stream_init_worker
, otherwise, the data structure may be different.
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions. |
This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
…route
Description
Fixes #6939
Checklist