From fd44364d2563aac83e2ad8f4a340fc64af4375d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?oil=E6=AC=A7=E5=91=A6?= <2228586315@qq.com> Date: Wed, 23 Feb 2022 09:53:52 +0800 Subject: [PATCH] feat: Add more fields to limit-count plugin (#2322) --- ...route-with-limit-count-plugin-form.spec.js | 2 ++ web/src/components/Plugin/UI/limit-count.tsx | 31 ++++++++++++++++++- web/src/components/Plugin/locales/en-US.ts | 6 ++++ web/src/components/Plugin/locales/zh-CN.ts | 6 ++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/web/cypress/integration/route/create-route-with-limit-count-plugin-form.spec.js b/web/cypress/integration/route/create-route-with-limit-count-plugin-form.spec.js index bf5814f5e4..e2a2ad47df 100644 --- a/web/cypress/integration/route/create-route-with-limit-count-plugin-form.spec.js +++ b/web/cypress/integration/route/create-route-with-limit-count-plugin-form.spec.js @@ -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', @@ -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, diff --git a/web/src/components/Plugin/UI/limit-count.tsx b/web/src/components/Plugin/UI/limit-count.tsx index adb384fc1c..51ecd535d8 100644 --- a/web/src/components/Plugin/UI/limit-count.tsx +++ b/web/src/components/Plugin/UI/limit-count.tsx @@ -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'; @@ -323,6 +323,35 @@ const LimitCount: React.FC = ({ form, schema }) => { ))} + + + + + + + + + prev.policy !== next.policy} style={{ display: 'none' }} diff --git a/web/src/components/Plugin/locales/en-US.ts b/web/src/components/Plugin/locales/en-US.ts index 365e5b3546..c7cefd9e64 100644 --- a/web/src/components/Plugin/locales/en-US.ts +++ b/web/src/components/Plugin/locales/en-US.ts @@ -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': diff --git a/web/src/components/Plugin/locales/zh-CN.ts b/web/src/components/Plugin/locales/zh-CN.ts index 43f38c40cd..77d8a1ddc3 100644 --- a/web/src/components/Plugin/locales/zh-CN.ts +++ b/web/src/components/Plugin/locales/zh-CN.ts @@ -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':