feat: add consumer group#7980
Conversation
| 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.
Don't hijack the schema of plugin_config in other places.
| end | ||
|
|
||
|
|
||
| function _M.put(id, conf) |
There was a problem hiding this comment.
We should also add a check in consumers. Let's make sure consumer.group_id points to an actual consumer group.
| local err | ||
| consumer_groups, err = core.config.new("/consumer_groups", { | ||
| automatic = true, | ||
| item_schema = nil, |
There was a problem hiding this comment.
Why don't we use schema to check the item?
| $block->set_value("request", "GET /t"); | ||
| } | ||
|
|
||
| if (!$block->no_error_log) { |
There was a problem hiding this comment.
It is more common to use this style:
Line 44 in 3bbc7ae
| } | ||
| } | ||
| --- response_body | ||
| passed |
There was a problem hiding this comment.
- 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.
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.
| end | ||
|
|
||
| if conf.group_id then | ||
| if consumer_group.get(conf.group_id) == nil then |
There was a problem hiding this comment.
For code style, I will recommend using the same solution in
apisix/apisix/admin/routes.lua
Line 79 in 3c18031
- 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.
| 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.
Better to put the order to one place:
|
|
||
| For example, if we configure a Consumer Group as shown below | ||
|
|
||
| ``` |
There was a problem hiding this comment.
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.
We should also update the admin-api.md?
| local apisix_var_names = { | ||
| balancer_ip = true, | ||
| balancer_port = true, | ||
| consumer_group_id = true, |
There was a problem hiding this comment.
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.
Add . or : in the end of sentence
| } | ||
| ``` | ||
|
|
||
| to a Consumer as shown below, |
There was a problem hiding this comment.
| 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.
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.
| 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`. |
| | 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.
| | consumer_group_id | core | Group name of Consumer. | | | |
| | consumer_group_id | core | Group ID of Consumer. | | |
| | 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.
Let's update the Resources that support paging queries: list in this page
| | 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.
Let's sync the change to the Chinese version too
Description
add consumer group
Checklist