Skip to content

change: Improve results from admin API while GET all plugins#9580

Merged
juststillthinking merged 34 commits into
apache:masterfrom
Revolyssup:revolyssup/fix9577
Jul 19, 2023
Merged

change: Improve results from admin API while GET all plugins#9580
juststillthinking merged 34 commits into
apache:masterfrom
Revolyssup:revolyssup/fix9577

Conversation

@Revolyssup

@Revolyssup Revolyssup commented May 31, 2023

Copy link
Copy Markdown
Contributor

Description

  • When subsystem is wrong, return a 400 error.
  • When subsystem is unspecified and all is true, return all plugins and not just http plugins
    err

Fixes #9577

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@Revolyssup Revolyssup changed the title [draft]fix: Improve results from admin API while GET all plugins fix: Improve results from admin API while GET all plugins May 31, 2023
Signed-off-by: revolyssup <[email protected]>
Signed-off-by: revolyssup <[email protected]>
Signed-off-by: revolyssup <[email protected]>
Comment thread apisix/admin/plugins.lua
Signed-off-by: revolyssup <[email protected]>
@Revolyssup

Copy link
Copy Markdown
Contributor Author

@monkeyDluffy6017 Please approve CI

@Revolyssup

Copy link
Copy Markdown
Contributor Author

@monkeyDluffy6017 the failing tests are unrelated to the PR. Can you rerun CI? These tests are flaky

Comment thread apisix/admin/plugins.lua Outdated
Comment thread apisix/admin/plugins.lua
Comment thread apisix/admin/plugins.lua Outdated
Comment thread apisix/admin/plugins.lua Outdated
Comment thread apisix/admin/plugins.lua Outdated
Comment thread apisix/admin/plugins.lua Outdated
@juststillthinking

Copy link
Copy Markdown
Contributor

@kayx23 Should we change the default behaviour of this interface? or just add a parameter subsystem=all to get all plugins?

Signed-off-by: revolyssup <[email protected]>
Signed-off-by: revolyssup <[email protected]>
@kayx23

kayx23 commented Jun 7, 2023

Copy link
Copy Markdown
Member

Should we change the default behaviour

Breaking changes aside:

  1. If by default behaviour you mean to return all plugins when subsystem is not specified after all=true, and use subsystem for filtering purpose, personally I think this makes the most sense.

  2. Note that all=true seems to be a fixed pre-req for using subsystem. If I set it to false, it errors out:

curl -s "http://127.0.0.1:9180/apisix/admin/plugins?all=false"
{"error_msg":"not found plugin name"}

But does this make sense? Why is all=true needed at all?

@Revolyssup

Copy link
Copy Markdown
Contributor Author

Current state of this PR reflects this proposal: #9577 (comment)

Signed-off-by: revolyssup <[email protected]>
Signed-off-by: revolyssup <[email protected]>
@moonming

Copy link
Copy Markdown
Member

@monkeyDluffy6017 ping

Signed-off-by: revolyssup <[email protected]>
Comment thread apisix/admin/plugins.lua Outdated
local err = "failed to load plugin " .. name .. " in subsystem " .. subsystem
core.log.warn("failed to load plugin [", name, "] err: ", plugin)
return 400, {error_msg = "failed to load plugin " .. name}
return 400, {error_msg = err }

@juststillthinking juststillthinking Jul 14, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to return an error here? If the plugin doesn't exist, it is fine to return nil?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread apisix/admin/plugins.lua
function _M.get_plugins_list()
local plugins = core.config.local_conf().plugins
function _M.get_plugins_list(subsystem)
local http_plugins

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you check the subsystem here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean before defining stream_plugins variable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread apisix/admin/plugins.lua Outdated
Comment thread apisix/admin/plugins.lua
local plugin_name = "apisix.plugins." .. name
local ok, plugin = pcall(require, plugin_name)
if ok and plugin.priority then
priorities[name] = plugin.priority

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these two function be used here?

local plugin_get_http = require("apisix.plugin").get
local plugin_get_stream = require("apisix.plugin").get_stream

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those functions are to get the entire plugin loaded with plugin.load(). Here we just need the names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread apisix/admin/plugins.lua Outdated
Comment on lines +130 to +134
local plugin_name = "apisix.stream.plugins." .. name
local ok, plugin = pcall(require, plugin_name)
if ok and plugin.priority then
priorities[name] = plugin.priority
table_insert(success, name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those functions are to get the entire plugin loaded with plugin.load(). Here we just need the names.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread docs/en/latest/admin-api.md Outdated
| --------- | ----------------------------- | ------- |
| subsystem | The subsystem of the Plugins. | http |

The plugin can be filtered on subsystem so that the ({plugin_name}) is searched in the subsystem passed through query params. Note that this query parameter is not available on `/apisix/admin/plugins/list`

@juststillthinking juststillthinking Jul 14, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's supported on /apisix/admin/plugins/list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't present present previously and was later added in the pull request. I removed the later comment.

Comment thread docs/en/latest/admin-api.md Outdated
Comment thread docs/zh/latest/admin-api.md Outdated
| --------- | -------------------------------------- | -------- |
| subsystem | 插件子系统。 | http |

可以在子系统上过滤插件,以便在通过查询参数传递的子系统中搜索 ({plugin_name})。请注意,此查询参数在“/apisix/admin/plugins/list”上不可用

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's supported on /apisix/admin/plugins/list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't present present previously and was later added in the pull request. I removed the later comment.

Comment thread docs/zh/latest/admin-api.md Outdated
Comment on lines +1366 to +1369

你可以使用 `/apisix/admin/plugins?all=true` 接口获取所有插件的所有属性,每个插件包括 `name`,`priority`,`type`,`schema`,`consumer_schema` 和 `version`。

默认情况下,该接口只返回 L7 插件。如果你需要获取 L4 / Stream 插件,需要使用 `/apisix/admin/plugins?all=true&subsystem=stream`
您可以使用“/apisix/admin/plugins?all=true”API 获取所有插件的所有属性。查询参数 `?all=true` 将很快被弃用

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the whole tip, use the following one intead:

您可以使用 “/apisix/admin/plugins?all=true” 获取所有插件的所有属性。这个 API 将很快被弃用

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@juststillthinking

Copy link
Copy Markdown
Contributor

Please fix the doc lint

Signed-off-by: revolyssup <[email protected]>
Comment thread apisix/admin/plugins.lua Outdated
Comment on lines +48 to +51
local subsystem = arg["subsystem"]
if subsystem and subsystem ~= "http" and subsystem ~= "stream" then
return 400, {error_msg = "unsupported subsystem: "..subsystem}
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
local subsystem = arg["subsystem"]
if subsystem and subsystem ~= "http" and subsystem ~= "stream" then
return 400, {error_msg = "unsupported subsystem: "..subsystem}
end
local subsystem = arg["subsystem"] or "http"
if subsystem ~= "http" and subsystem ~= "stream" then
return 400, {error_msg = "unsupported subsystem: "..subsystem}
end

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread apisix/admin/plugins.lua Outdated
end
local plugin
-- By default search through http subsystems
subsystem = subsystem or "http"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

subsystem = subsystem or "http"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread apisix/admin/plugins.lua Outdated
Comment on lines +84 to +85
local err = "failed to load plugin " .. name .. " in subsystem " .. subsystem
core.log.warn("failed to load plugin [", name, "] err: ", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The msg should be changed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread apisix/admin/plugins.lua Outdated
stream_plugins = core.config.local_conf().stream_plugins
end


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant blank

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread apisix/admin/plugins.lua Outdated
if not plugin then
local err = "failed to load plugin " .. name .. " in subsystem " .. subsystem
core.log.warn("failed to load plugin [", name, "] err: ", err)
return 404, {error_msg = "plugin not found"}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"plugin " .. name .. " is not found in subsystem " .. subsystem

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Signed-off-by: revolyssup <[email protected]>
Signed-off-by: revolyssup <[email protected]>
Comment thread Makefile Outdated
@$(call func_echo_status, "$@ -> [ Start ]")
$(ENV_GIT) submodule update --init --recursive
prove -I../test-nginx/lib -I./ -r -s t/
prove -I../test-nginx/lib -I./ -r -s t/admin/plugins.t

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you add this?

@juststillthinking juststillthinking changed the title fix: Improve results from admin API while GET all plugins change: Improve results from admin API while GET all plugins Jul 19, 2023
@juststillthinking
juststillthinking merged commit 26ba567 into apache:master Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Admin API: Plugins URL Query subsystem

6 participants