Skip to content

Commit

Permalink
feat: Add more fields to limit-count plugin (apache#2322)
Browse files Browse the repository at this point in the history
  • Loading branch information
oil-oil authored Feb 23, 2022
1 parent fc62ca3 commit fd44364
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ context('Create and delete route with limit-count form', () => {
key: '#key',
rejected_code: '#rejected_code',
policy: '#policy',
group: '#group',
redis_host: '#redis_host',
redis_port: '#redis_port',
redis_password: '#redis_password',
Expand Down Expand Up @@ -85,6 +86,7 @@ context('Create and delete route with limit-count form', () => {
cy.get(selector.count).type(1);
cy.get(selector.time_window).type(1);
cy.get(selector.rejected_code).type(500);
cy.get(selector.group).type('test_group');
cy.get(selector.drawer).within(() => {
cy.contains('Submit').click({
force: true,
Expand Down
31 changes: 30 additions & 1 deletion web/src/components/Plugin/UI/limit-count.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
import React, { useState } from 'react';
import type { FormInstance } from 'antd/es/form';
import { Button, Col, Form, Input, InputNumber, Row, Select } from 'antd';
import { Button, Col, Form, Input, InputNumber, Row, Select, Switch } from 'antd';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { useIntl } from 'umi';

Expand Down Expand Up @@ -323,6 +323,35 @@ const LimitCount: React.FC<Props> = ({ form, schema }) => {
))}
</Select>
</Form.Item>
<Form.Item
label="group"
name="group"
tooltip={formatMessage({ id: 'component.pluginForm.limit-count.key.tooltip' })}
>
<Input />
</Form.Item>
<Form.Item
initialValue={properties.allow_degradation.default}
label="allow_degradation"
name="allow_degradation"
tooltip={formatMessage({
id: 'component.pluginForm.limit-count.allow_degradation.tooltip',
})}
valuePropName="checked"
>
<Switch />
</Form.Item>
<Form.Item
initialValue={properties.show_limit_quota_header.default}
label="show_limit_quota_header"
name="show_limit_quota_header"
tooltip={formatMessage({
id: 'component.pluginForm.limit-count.show_limit_quota_header.tooltip',
})}
valuePropName="checked"
>
<Switch />
</Form.Item>
<Form.Item
shouldUpdate={(prev, next) => prev.policy !== next.policy}
style={{ display: 'none' }}
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/Plugin/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ export default {
'The HTTP status code returned when the request exceeds the threshold is rejected, default 503.',
'component.pluginForm.limit-count.policy.tooltip':
'The rate-limiting policies to use for retrieving and incrementing the limits. Available values are local(the counters will be stored locally in-memory on the node) and redis(counters are stored on a Redis server and will be shared across the nodes, usually use it to do the global speed limit) and redis-cluster(the same function as redis, only use Redis cluster pattern).',
'component.pluginForm.limit-count.allow_degradation.tooltip':
'Whether to enable plugin degradation when the limit-count function is temporarily unavailable(e.g. redis timeout). Allow requests to continue when the value is set to true',
'component.pluginForm.limit-count.show_limit_quota_header.tooltip':
'Whether show X-RateLimit-Limit and X-RateLimit-Remaining (which mean the total number of requests and the remaining number of requests that can be sent) in the response header',
'component.pluginForm.limit-count.group.tooltip':
'Route configured with the same group will share the same counter',
'component.pluginForm.limit-count.redis_host.tooltip':
'When using the redis policy, this property specifies the address of the Redis server.',
'component.pluginForm.limit-count.redis_port.tooltip':
Expand Down
6 changes: 6 additions & 0 deletions web/src/components/Plugin/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ export default {
'当请求超过阈值被拒绝时,返回的 HTTP 状态码。',
'component.pluginForm.limit-count.policy.tooltip':
'用于检索和增加限制的速率限制策略。可选的值有:local(计数器被以内存方式保存在节点本地,默认选项) 和 redis(计数器保存在 Redis 服务节点上,从而可以跨节点共享结果,通常用它来完成全局限速);以及redis-cluster,跟 redis 功能一样,只是使用 redis 集群方式。',
'component.pluginForm.limit-count.allow_degradation.tooltip':
'当限流插件功能临时不可用时(例如,Redis 超时)是否允许请求继续。当值设置为 true 时则自动允许请求继续',
'component.pluginForm.limit-count.show_limit_quota_header.tooltip':
'是否在响应头中显示 X-RateLimit-Limit 和 X-RateLimit-Remaining (限制的总请求数和剩余还可以发送的请求数)',
'component.pluginForm.limit-count.group.tooltip':
'配置同样的 group 的 Route 将共享同样的限流计数器',
'component.pluginForm.limit-count.redis_host.tooltip':
'当使用 redis 限速策略时,该属性是 Redis 服务节点的地址。',
'component.pluginForm.limit-count.redis_port.tooltip':
Expand Down

0 comments on commit fd44364

Please sign in to comment.