-
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: add consumer group #7980
feat: add consumer group #7980
Conversation
apisix/admin/consumer_group.lua
Outdated
conf.id = id | ||
|
||
core.log.info("conf: ", core.json.delay_encode(conf)) | ||
local ok, err = core.schema.check(core.schema.plugin_config, conf) |
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.
Don't hijack the schema of plugin_config in other places.
end | ||
|
||
|
||
function _M.put(id, conf) |
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 also add a check in consumers. Let's make sure consumer.group_id
points to an actual consumer group.
apisix/consumer_group.lua
Outdated
local err | ||
consumer_groups, err = core.config.new("/consumer_groups", { | ||
automatic = true, | ||
item_schema = nil, |
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.
Why don't we use schema to check the item?
t/admin/consumer-group.t
Outdated
$block->set_value("request", "GET /t"); | ||
} | ||
|
||
if (!$block->no_error_log) { |
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.
It is more common to use this style:
Line 44 in 3bbc7ae
if ((!defined $block->error_log) && (!defined $block->no_error_log)) { |
} | ||
} | ||
--- response_body | ||
passed |
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 verify that the plugin works well in the consumer_group
- we need to verify that consumer_group and consumer work well together
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.
Just like what other resources does, e.g. plugin_config, consumer, this test file is only for admin api test.
I would put plugin test and consumer stuff in t/node/consumer-group.t
, and moreover, t/config-center-yaml/consumer-group.t
, please keep in patient.
apisix/admin/consumers.lua
Outdated
@@ -62,6 +63,12 @@ local function check_conf(username, conf) | |||
end | |||
end | |||
|
|||
if conf.group_id then | |||
if consumer_group.get(conf.group_id) == nil then |
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 code style, I will recommend using the same solution in
apisix/apisix/admin/routes.lua
Line 79 in 3c18031
if upstream_id then |
- fetch the data from etcd if possible
- use a similar error message
e36abeb
|
||
When APISIX can't find the Consumer Group with the `group_id`, the Admin API is terminated with a status code of 400. | ||
|
||
If a Consumer already has the `plugins` field configured, the plugins in the Consumer Group will effectively be merged to it. The same plugin in the Consumer Group will not override the ones configured directly in the Consumer. |
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.
If a Consumer already has the `plugins` field configured, the plugins in the Consumer Group will effectively be merged to it. The same plugin in the Consumer Group will not override the ones configured directly in the Consumer. | |
If a Consumer already has the `plugins` field configured, the plugins in the Consumer Group will effectively be merged into it. The same plugin in the Consumer Group will not override the one configured directly in the Consumer. |
instead of managing each consumer individually. | ||
|
||
While configuring the same plugin for the same route, only one copy of the configuration is valid. | ||
The order of precedence is `Consumer` > `Consumer Group` > `Route` > `plugin_config` > `Service`. |
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.
Better to put the order to one place:
While configuring the same plugin, only one copy of the configuration is valid. The order of precedence is always `Consumer` > `Route` > `Plugin Config` > `Service`. |
|
||
For example, if we configure a Consumer Group as shown below | ||
|
||
``` |
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.
Let's add language mark like other examples
# | ||
--> | ||
|
||
Consumer Groups are used to extract commonly used [Plugin](./plugin.md) configurations and can be bound directly to a [Consumer](./consumer.md). |
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 also update the admin-api.md?
@@ -206,6 +206,7 @@ do | |||
local apisix_var_names = { | |||
balancer_ip = true, | |||
balancer_port = true, | |||
consumer_group_id = true, |
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 to update https://github.com/apache/apisix/blob/master/docs/en/latest/apisix-variable.md for the new variable.
|
||
If a Consumer already has the `plugins` field configured, the plugins in the Consumer Group will effectively be merged to it. The same plugin in the Consumer Group will not override the ones configured directly in the Consumer. | ||
|
||
For example, if we configure a Consumer Group as shown below |
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.
Add .
or :
in the end of sentence
} | ||
``` | ||
|
||
to a Consumer as shown below, |
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.
to a Consumer as shown below, | |
To a Consumer as shown below. |
|
||
to a Consumer as shown below, | ||
|
||
``` |
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 to add code language too
}' | ||
``` | ||
|
||
When APISIX can't find the Consumer Group with the `group_id`, the Admin API is terminated with a status code of 400. |
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.
When APISIX can't find the Consumer Group with the `group_id`, the Admin API is terminated with a status code of 400. | |
When APISIX can't find the Consumer Group with the `group_id`, the Admin API is terminated with a status code of `400`. |
docs/en/latest/apisix-variable.md
Outdated
@@ -38,6 +38,7 @@ additional variables. | |||
| balancer_ip | core | The IP of picked upstream server. | 192.168.1.2 | | |||
| balancer_port | core | The port of picked upstream server. | 80 | | |||
| consumer_name | core | Username of Consumer. | | | |||
| consumer_group_id | core | Group name of Consumer. | | |
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.
| consumer_group_id | core | Group name of Consumer. | | | |
| consumer_group_id | core | Group ID of Consumer. | | |
@@ -947,6 +948,35 @@ Sets Plugins which run globally. i.e these Plugins will be run before any Route/ | |||
| create_time | False | Epoch timestamp (in seconds) of the created time. If missing, this field will be populated automatically. | 1602883670 | | |||
| update_time | False | Epoch timestamp (in seconds) of the updated time. If missing, this field will be populated automatically. | 1602883670 | | |||
|
|||
## Consumer group |
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.
Let's update the Resources that support paging queries:
list in this page
docs/zh/latest/apisix-variable.md
Outdated
@@ -37,6 +37,7 @@ APISIX 除了支持 [NGINX 变量](http://nginx.org/en/docs/varindex.html)外, | |||
| balancer_ip | core | 上游服务器的 IP 地址。 | 192.168.1.2 | | |||
| balancer_port | core | 上游服务器的端口。 | 80 | | |||
| consumer_name | core | 消费者的名称。 | | | |||
| consumer_group_id | core | 消费者所在的组的名称。 | | |
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.
Let's sync the change to the Chinese version too
Description
add consumer group
Checklist