Skip to content
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 limit-count plugin #1739

Merged
merged 16 commits into from Apr 15, 2021
Merged

Conversation

LiteSun
Copy link
Member

@LiteSun LiteSun commented Apr 10, 2021

Please answer these questions before submitting a pull request, or your PR will get closed.

Why submit this pull request?

  • Bugfix
  • New feature provided
  • Improve performance
  • Backport patches

What changes will this PR take into?

Please update this section with detailed description.
image
image
image

Checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@juzhiyuan
Copy link
Member

Please add your description for this PR

@codecov-io
Copy link

codecov-io commented Apr 11, 2021

Codecov Report

Merging #1739 (4325300) into master (419128d) will increase coverage by 0.21%.
The diff coverage is 84.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1739      +/-   ##
==========================================
+ Coverage   72.57%   72.79%   +0.21%     
==========================================
  Files         113      114       +1     
  Lines        2695     2727      +32     
  Branches      650      655       +5     
==========================================
+ Hits         1956     1985      +29     
- Misses        739      742       +3     
Flag Coverage Δ
frontend-e2e-test 72.79% <84.84%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
web/src/components/Plugin/UI/limit-count.tsx 83.33% <83.33%> (ø)
web/src/components/Plugin/UI/plugin.tsx 69.23% <100.00%> (+5.59%) ⬆️
...ages/Route/components/DebugViews/DebugDrawView.tsx 79.86% <0.00%> (+1.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 419128d...4325300. Read the comment docs.

@netlify
Copy link

netlify bot commented Apr 11, 2021

Deploy preview for apisix-dashboard ready!

Built with commit d896705

https://deploy-preview-1739--apisix-dashboard.netlify.app

@LiteSun LiteSun marked this pull request as ready for review April 11, 2021 10:52
@LiteSun LiteSun requested a review from juzhiyuan April 11, 2021 10:52
Copy link
Member

@juzhiyuan juzhiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update this PR's description

tooltip={formatMessage({ id: 'component.pluginForm.limit-count.policy.tooltip' })}
>
<Select onChange={(e: PolicyProps) => { setPoicy(e) }}>
{["local", "redis", "redis-cluster"].map(item => (<Select.Option value={item}>{item}</Select.Option>))}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key

web/src/components/Plugin/UI/limit-count.tsx Outdated Show resolved Hide resolved
Comment on lines 49 to 53
redis_host: '127.0.0.1',
redis_password: 'redis_password',
redis_cluster_name: 'redis_cluster_name',
redis_cluster_nodes_0: "redis.cluster1",
redis_cluster_nodes_1: "redis.cluster1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these default values?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good default values, will update later

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

// limit-count
'component.pluginForm.limit-count.count.tooltip': '指定时间窗口内的请求数量阈值。',
'component.pluginForm.limit-count.time_window.tooltip': '时间窗口的大小(以秒为单位),超过这个时间就会重置。',
'component.pluginForm.limit-count.key.tooltip': '用来做请求计数的有效值。例如,可以使用主机名(或服务器区域)作为关键字,以便限制每个主机名规定时间内的请求次数。我们也可以使用客户端地址作为关键字,这样我们就可以避免单个客户端规定时间内多次的连接我们的服务。当前接受的 key 有:"remote_addr"(客户端 IP 地址), "server_addr"(服务端 IP 地址), 请求头中的"X-Forwarded-For" 或 "X-Real-IP", "consumer_name"(consumer 的 username), "service_id" 。',
Copy link
Contributor

@liuxiran liuxiran Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask what is the meaning of 服务器区域?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refer infoimage

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use 服务器地址

@liuxiran
Copy link
Contributor

redist Doms lost when edited once again
2021-04-12 15-45-00屏幕截图

test step:
1.
configure the limit-count and submit
2021-04-12 16-05-43屏幕截图

  1. click enable button to edit it again, you will get the trouble

@LiteSun

@LiteSun
Copy link
Member Author

LiteSun commented Apr 12, 2021

redist Doms lost when edited once again

  1. click enable button to edit it again, you will get the trouble

@LiteSun

Tks for your report. I will check it.

@LiteSun
Copy link
Member Author

LiteSun commented Apr 12, 2021

redist Doms lost when edited once again

@liuxiran fixed.


return (<>
<Form.Item
label="redis_host"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emmm would better have i18n for those fields, for users may not know what's it

<Form.Item
label="rejected_code"
name="rejected_code"
tooltip={formatMessage({ id: 'component.pluginForm.limit-count.rejected_code.tooltip' })}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default value is 503

name="redis_port"
tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_port.tooltip' })}
>
<InputNumber min={1} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<InputNumber min={1} />
<InputNumber min={1} max={65535} />

<Form
form={form}
{...FORM_ITEM_LAYOUT}
initialValues={{ key: 'remote_addr', redis_cluster_nodes: ['', ''], policy, redis_port: 6379, redis_database: 0, redis_timeout: 1000 }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you submit data and use local policy, will redis_port be 6379?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it won't.

name="redis_timeout"
tooltip={formatMessage({ id: 'component.pluginForm.limit-count.redis_timeout.tooltip' })}
>
<InputNumber />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min = 1

</>)
}

const RedisClusterForm: React.FC<Props> = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do these Props for?


return (
<>
<Form.Item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing two fields: redis_timeout & redis_password.

https://github.com/apache/apisix/blob/master/apisix/plugins/limit-count.lua#L37

Copy link
Member

@juzhiyuan juzhiyuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to resolve those comments :)

@LiteSun LiteSun merged commit 10cadaa into apache:master Apr 15, 2021
@LiteSun LiteSun deleted the limit-count-plugin-form branch April 15, 2021 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants