You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/10/08 05:07:35 UTC

[GitHub] [apisix] spacewander commented on a diff in pull request #7980: feat: add consumer group

spacewander commented on code in PR #7980:
URL: https://github.com/apache/apisix/pull/7980#discussion_r990590742


##########
docs/en/latest/terminology/consumer-group.md:
##########
@@ -0,0 +1,101 @@
+---
+title: Consumer Group
+keywords:
+  - API gateway
+  - Apache APISIX
+  - Consumer Group
+description: Consumer Group in Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+Consumer Groups are used to extract commonly used [Plugin](./plugin.md) configurations and can be bound directly to a [Consumer](./consumer.md).
+
+With consumer groups, you can define any number of plugins, e.g. rate limiting and apply them to a set of consumers,
+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`.
+
+The example below illustrates how to create a Consumer Group and bind it to a Consumer:
+
+```shell
+curl http://127.0.0.1:9180/apisix/admin/consumer_groups/company_a -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "plugins": {
+        "limit-count": {
+            "count": 200,
+            "time_window": 60,
+            "rejected_code": 503,
+            "group": "$consumer_group_id"
+        }
+    }
+}'
+```
+
+```shell
+curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "username": "jack",
+    "plugins": {
+        "key-auth": {
+            "key": "auth-one"
+        }
+    },
+    "group_id": "company_a"
+}'
+```
+
+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.
+
+For example, if we configure a Consumer Group as shown below
+
+```

Review Comment:
   Let's add language mark like other examples



##########
docs/en/latest/terminology/consumer-group.md:
##########
@@ -0,0 +1,101 @@
+---
+title: Consumer Group
+keywords:
+  - API gateway
+  - Apache APISIX
+  - Consumer Group
+description: Consumer Group in Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+Consumer Groups are used to extract commonly used [Plugin](./plugin.md) configurations and can be bound directly to a [Consumer](./consumer.md).
+
+With consumer groups, you can define any number of plugins, e.g. rate limiting and apply them to a set of consumers,
+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`.
+
+The example below illustrates how to create a Consumer Group and bind it to a Consumer:
+
+```shell
+curl http://127.0.0.1:9180/apisix/admin/consumer_groups/company_a -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "plugins": {
+        "limit-count": {
+            "count": 200,
+            "time_window": 60,
+            "rejected_code": 503,
+            "group": "$consumer_group_id"
+        }
+    }
+}'
+```
+
+```shell
+curl http://127.0.0.1:9180/apisix/admin/consumers -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "username": "jack",
+    "plugins": {
+        "key-auth": {
+            "key": "auth-one"
+        }
+    },
+    "group_id": "company_a"
+}'
+```
+
+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.

Review Comment:
   ```suggestion
   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.
   ```



##########
docs/en/latest/terminology/consumer-group.md:
##########
@@ -0,0 +1,101 @@
+---
+title: Consumer Group
+keywords:
+  - API gateway
+  - Apache APISIX
+  - Consumer Group
+description: Consumer Group in Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+Consumer Groups are used to extract commonly used [Plugin](./plugin.md) configurations and can be bound directly to a [Consumer](./consumer.md).

Review Comment:
   We should update the admin-api.md?



##########
apisix/core/ctx.lua:
##########
@@ -206,6 +206,7 @@ do
     local apisix_var_names = {
         balancer_ip = true,
         balancer_port = true,
+        consumer_group_id = true,

Review Comment:
   Need to update https://github.com/apache/apisix/blob/master/docs/en/latest/apisix-variable.md for the new variable.



##########
docs/en/latest/terminology/consumer-group.md:
##########
@@ -0,0 +1,101 @@
+---
+title: Consumer Group
+keywords:
+  - API gateway
+  - Apache APISIX
+  - Consumer Group
+description: Consumer Group in Apache APISIX.
+---
+
+<!--
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+-->
+
+Consumer Groups are used to extract commonly used [Plugin](./plugin.md) configurations and can be bound directly to a [Consumer](./consumer.md).
+
+With consumer groups, you can define any number of plugins, e.g. rate limiting and apply them to a set of consumers,
+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`.

Review Comment:
   Better to put the order to one place: https://github.com/apache/apisix/blob/61afafdd46fe40c03955b6cb058df3e6fad5db45/docs/en/latest/terminology/plugin.md?plain=1#L30



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org