feat: rerun rewrite phase for newly added plugins in consumer#6502
Conversation
Closes apache#6405 Signed-off-by: tzssangglass <[email protected]>
Signed-off-by: tzssangglass <[email protected]>
…be an auth class plugin Signed-off-by: tzssangglass <[email protected]>
|
only call core.consumer.attach_consumer is considered to be an auth class plugin. ref: #2898 |
Signed-off-by: tzssangglass <[email protected]>
Signed-off-by: tzssangglass <[email protected]>
Signed-off-by: tzssangglass <[email protected]>
| local runned_plugins = core.table.deepcopy(api_ctx.plugins) | ||
| core.table.clear(api_ctx.plugins) | ||
| api_ctx.plugins = plugin.filter(api_ctx, route, api_ctx.plugins) | ||
| local unrunn_plugins |
There was a problem hiding this comment.
Maybe we can add a flag in
Line 505 in c4229d1
Signed-off-by: tzssangglass <[email protected]>
Signed-off-by: tzssangglass <[email protected]>
| @@ -503,6 +503,11 @@ local function merge_consumer_route(route_conf, consumer_conf) | |||
| end | |||
|
|
|||
There was a problem hiding this comment.
we can use if new_route_conf.value.plugins[name] == nil then conf._from_consumer = true?
There was a problem hiding this comment.
tried, Test 2 will fail. We need to merge the `new_route_conf.value.plugins["proxy-rewrite"], it will not be nil.
There was a problem hiding this comment.
What about this change?
diff --git apisix/plugin.lua apisix/plugin.lua
index d66ec045..190b0833 100644
--- apisix/plugin.lua
+++ apisix/plugin.lua
@@ -502,12 +502,11 @@ local function merge_consumer_route(route_conf, consumer_conf)
new_route_conf.value.plugins = {}
end
- new_route_conf.value.plugins[name] = conf
-
- if (route_conf and route_conf.value and route_conf.value.plugins)
- and not route_conf.value.plugins[name] then
- new_route_conf.value.plugins[name]["_from_consumer"] = true
+ if new_route_conf.value.plugins[name] == nil then
+ conf._from_consumer = true
end
+
+ new_route_conf.value.plugins[name] = conf
end
core.log.info("merged conf : ", core.json.delay_encode(new_route_conf))
| function _M.rerun_plugins_of_consumer(plugins, api_ctx) | ||
| for i = 1, #plugins, 2 do | ||
| -- no need to rerun the auth plugins | ||
| if plugins[i + 1]["_from_consumer"] and plugins[i].type ~= "auth" then |
There was a problem hiding this comment.
Would be better to merge it in
Line 736 in 492f782
There was a problem hiding this comment.
I had thought about it, but if plugins[i + 1]["_from_consumer"] and plugins[i].type ~= "auth" then is difficult to port. Unless we add a flag or something like that. This makes run_plugin look even more complicated.
Another way is as follows:
for i = 1, #plugins, 2 do
-- no need to rerun the non-auth plugins
if plugins[i + 1]["_from_consumer"] and plugins[i].type ~= "auth" then
local new_plugins = core.table.new(2, 0)
core.table.insert(new_plugins, plugins[i])
core.table.insert(new_plugins, plugins[i + 1])
_M.run_plugin("rewrite", new_plugins, api_ctx)
end
end
return api_ctxthis adds some table overhead.
There was a problem hiding this comment.
The main reason is that the plugins here are used in the api_ctx in order to reduce the table overhead, so use the judgment condition.
There was a problem hiding this comment.
Maybe we can add another fake phase (rewrite_in_consumer) in run_plugin so we don't need to duplicate the conditions?
Signed-off-by: tzssangglass <[email protected]>
Closes #6405
Signed-off-by: tzssangglass [email protected]
What this PR does / why we need it:
Pre-submission checklist: