Skip to content

Commit 07badb1

Browse files
authored
​Build: Implement rate limiting and circuit breaker for API and RPC services.​​ (#3572)
* feat: implement ratelimit and circuitbreaker in middleware. * ​Build: Implement rate limiting and circuit breaker for API and RPC services.​​ * revert change. * update ratelimiter and circuitbreaker config. * update tools to openimsdk tools
1 parent 3a1c8df commit 07badb1

31 files changed

+574
-24
lines changed

config/openim-api.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ prometheus:
1717
ports:
1818
# This address can be accessed via a browser
1919
grafanaURL:
20+
21+
ratelimiter:
22+
# Whether to enable rate limiting
23+
enable: false
24+
# WindowSize defines time duration per window
25+
window: 20s
26+
# BucketNum defines bucket number for each window
27+
bucket: 500
28+
# CPU threshold; valid range 0–1000 (1000 = 100%)
29+
cpuThreshold: 850

config/openim-msggateway.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,20 @@ longConnSvr:
2626
websocketMaxMsgLen: 4096
2727
# WebSocket connection handshake timeout in seconds
2828
websocketTimeout: 10
29+
30+
ratelimiter:
31+
# Whether to enable rate limiting
32+
enable: false
33+
# WindowSize defines time duration per window
34+
window: 20s
35+
# BucketNum defines bucket number for each window
36+
bucket: 500
37+
# CPU threshold; valid range 0–1000 (1000 = 100%)
38+
cpuThreshold: 850
39+
40+
circuitBreaker:
41+
enable: false
42+
window: 5s # Time window size (seconds)
43+
bucket: 100 # Number of buckets
44+
success: 0.6 # Success rate threshold (0.6 means 60%)
45+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached

config/openim-msgtransfer.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,20 @@ prometheus:
66
# List of ports that Prometheus listens on; each port corresponds to an instance of monitoring. Ensure these are managed accordingly
77
# It will only take effect when autoSetPorts is set to false.
88
ports:
9+
10+
ratelimiter:
11+
# Whether to enable rate limiting
12+
enable: false
13+
# WindowSize defines time duration per window
14+
window: 20s
15+
# BucketNum defines bucket number for each window
16+
bucket: 500
17+
# CPU threshold; valid range 0–1000 (1000 = 100%)
18+
cpuThreshold: 850
19+
20+
circuitBreaker:
21+
enable: false
22+
window: 5s # Time window size (seconds)
23+
bucket: 100 # Number of buckets
24+
success: 0.6 # Success rate threshold (0.6 means 60%)
25+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached

config/openim-push.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,26 @@ rpc:
1010
# It will only take effect when autoSetPorts is set to false.
1111
ports:
1212

13+
ratelimiter:
14+
# Whether to enable rate limiting
15+
enable: false
16+
# WindowSize defines time duration per window
17+
window: 20s
18+
# BucketNum defines bucket number for each window
19+
bucket: 500
20+
# CPU threshold; valid range 0–1000 (1000 = 100%)
21+
cpuThreshold: 850
22+
23+
circuitBreaker:
24+
enable: false
25+
window: 5s # Time window size (seconds)
26+
bucket: 100 # Number of buckets
27+
success: 0.6 # Success rate threshold (0.6 means 60%)
28+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached
1329

1430
prometheus:
1531
# Enable or disable Prometheus monitoring
16-
enable: true
32+
enable: false
1733
# List of ports that Prometheus listens on; these must match the number of rpc.ports to ensure correct monitoring setup
1834
# It will only take effect when autoSetPorts is set to false.
1935
ports:

config/openim-rpc-auth.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ prometheus:
2020
tokenPolicy:
2121
# Token validity period, in days
2222
expire: 90
23+
24+
ratelimiter:
25+
# Whether to enable rate limiting
26+
enable: false
27+
# WindowSize defines time duration per window
28+
window: 20s
29+
# BucketNum defines bucket number for each window
30+
bucket: 500
31+
# CPU threshold; valid range 0–1000 (1000 = 100%)
32+
cpuThreshold: 850
33+
34+
circuitBreaker:
35+
enable: false
36+
window: 5s # Time window size (seconds)
37+
bucket: 100 # Number of buckets
38+
success: 0.6 # Success rate threshold (0.6 means 60%)
39+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached

config/openim-rpc-conversation.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,20 @@ prometheus:
1616
# List of ports that Prometheus listens on; these must match the number of rpc.ports to ensure correct monitoring setup
1717
# It will only take effect when autoSetPorts is set to false.
1818
ports:
19+
20+
ratelimiter:
21+
# Whether to enable rate limiting
22+
enable: false
23+
# WindowSize defines time duration per window
24+
window: 20s
25+
# BucketNum defines bucket number for each window
26+
bucket: 500
27+
# CPU threshold; valid range 0–1000 (1000 = 100%)
28+
cpuThreshold: 850
29+
30+
circuitBreaker:
31+
enable: false
32+
window: 5s # Time window size (seconds)
33+
bucket: 100 # Number of buckets
34+
success: 0.6 # Success rate threshold (0.6 means 60%)
35+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached

config/openim-rpc-friend.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,20 @@ prometheus:
1616
# List of ports that Prometheus listens on; these must match the number of rpc.ports to ensure correct monitoring setup
1717
# It will only take effect when autoSetPorts is set to false.
1818
ports:
19+
20+
ratelimiter:
21+
# Whether to enable rate limiting
22+
enable: false
23+
# WindowSize defines time duration per window
24+
window: 20s
25+
# BucketNum defines bucket number for each window
26+
bucket: 500
27+
# CPU threshold; valid range 0–1000 (1000 = 100%)
28+
cpuThreshold: 850
29+
30+
circuitBreaker:
31+
enable: false
32+
window: 5s # Time window size (seconds)
33+
bucket: 100 # Number of buckets
34+
success: 0.6 # Success rate threshold (0.6 means 60%)
35+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached

config/openim-rpc-group.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,20 @@ prometheus:
1919

2020

2121
enableHistoryForNewMembers: true
22+
23+
ratelimiter:
24+
# Whether to enable rate limiting
25+
enable: false
26+
# WindowSize defines time duration per window
27+
window: 20s
28+
# BucketNum defines bucket number for each window
29+
bucket: 500
30+
# CPU threshold; valid range 0–1000 (1000 = 100%)
31+
cpuThreshold: 850
32+
33+
circuitBreaker:
34+
enable: false
35+
window: 5s # Time window size (seconds)
36+
bucket: 100 # Number of buckets
37+
success: 0.6 # Success rate threshold (0.6 means 60%)
38+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached

config/openim-rpc-msg.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,20 @@ prometheus:
2020

2121
# Does sending messages require friend verification
2222
friendVerify: false
23+
24+
ratelimiter:
25+
# Whether to enable rate limiting
26+
enable: false
27+
# WindowSize defines time duration per window
28+
window: 20s
29+
# BucketNum defines bucket number for each window
30+
bucket: 500
31+
# CPU threshold; valid range 0–1000 (1000 = 100%)
32+
cpuThreshold: 850
33+
34+
circuitBreaker:
35+
enable: false
36+
window: 5s # Time window size (seconds)
37+
bucket: 100 # Number of buckets
38+
success: 0.6 # Success rate threshold (0.6 means 60%)
39+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached

config/openim-rpc-third.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ prometheus:
1717
# It will only take effect when autoSetPorts is set to false.
1818
ports:
1919

20+
ratelimiter:
21+
# Whether to enable rate limiting
22+
enable: false
23+
# WindowSize defines time duration per window
24+
window: 20s
25+
# BucketNum defines bucket number for each window
26+
bucket: 500
27+
# CPU threshold; valid range 0–1000 (1000 = 100%)
28+
cpuThreshold: 850
29+
30+
circuitBreaker:
31+
enable: false
32+
window: 5s # Time window size (seconds)
33+
bucket: 100 # Number of buckets
34+
success: 0.6 # Success rate threshold (0.6 means 60%)
35+
request: 500 # Request threshold; circuit breaker evaluation occurs when reached
2036

2137
object:
2238
# Use MinIO as object storage, or set to "cos", "oss", "kodo", "aws", while also configuring the corresponding settings

0 commit comments

Comments
 (0)