未验证 提交 6e4b2e69 编写于 作者: 旺阳 提交者: GitHub

[Fix]Recovery Traffic Control Config (#10505)

* recovery traffic config

* run ci

* update
上级 64cee03f
...@@ -228,6 +228,11 @@ security.authentication.ldap.password|password|LDAP password ...@@ -228,6 +228,11 @@ security.authentication.ldap.password|password|LDAP password
security.authentication.ldap.user.identity-attribute|uid|LDAP user identity attribute security.authentication.ldap.user.identity-attribute|uid|LDAP user identity attribute
security.authentication.ldap.user.email-attribute|mail|LDAP user email attribute security.authentication.ldap.user.email-attribute|mail|LDAP user email attribute
security.authentication.ldap.user.not-exist-action|CREATE|action when LDAP user is not exist. Default CREATE: automatically create user when user not exist, DENY: deny log-in when user not exist security.authentication.ldap.user.not-exist-action|CREATE|action when LDAP user is not exist. Default CREATE: automatically create user when user not exist, DENY: deny log-in when user not exist
traffic.control.global.switch|false|traffic control global switch
traffic.control.max-global-qps-rate|300|global max request number per second
traffic.control.tenant-switch|false|traffic control tenant switch
traffic.control.default-tenant-qps-rate|10|default tenant max request number per second
traffic.control.customize-tenant-qps-rate||customize tenant max request number per second
### master.properties [master-service log config] ### master.properties [master-service log config]
......
...@@ -219,6 +219,11 @@ security.authentication.ldap.password|password|LDAP密码 ...@@ -219,6 +219,11 @@ security.authentication.ldap.password|password|LDAP密码
security.authentication.ldap.user.identity-attribute|uid|LDAP用户身份标识字段名 security.authentication.ldap.user.identity-attribute|uid|LDAP用户身份标识字段名
security.authentication.ldap.user.email-attribute|mail|LDAP邮箱字段名 security.authentication.ldap.user.email-attribute|mail|LDAP邮箱字段名
security.authentication.ldap.user.not-exist-action|CREATE|当LDAP用户不存在时执行的操作。CREATE:当用户不存在时自动新建用户, DENY:当用户不存在时拒绝登陆 security.authentication.ldap.user.not-exist-action|CREATE|当LDAP用户不存在时执行的操作。CREATE:当用户不存在时自动新建用户, DENY:当用户不存在时拒绝登陆
traffic.control.global.switch|false|流量控制全局开关
traffic.control.max-global-qps-rate|300|全局最大请求数/秒
traffic.control.tenant-switch|false|流量控制租户开关
traffic.control.default-tenant-qps-rate|10|默认租户最大请求数/秒限制
traffic.control.customize-tenant-qps-rate||自定义租户最大请求数/秒限制
## 6.master.properties [Master服务配置] ## 6.master.properties [Master服务配置]
|参数 |默认值| 描述| |参数 |默认值| 描述|
......
...@@ -95,7 +95,7 @@ public class AppConfiguration implements WebMvcConfigurer { ...@@ -95,7 +95,7 @@ public class AppConfiguration implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) { public void addInterceptors(InterceptorRegistry registry) {
// i18n // i18n
registry.addInterceptor(localeChangeInterceptor()); registry.addInterceptor(localeChangeInterceptor());
if (trafficConfiguration.isTrafficGlobalControlSwitch() || trafficConfiguration.isTrafficTenantControlSwitch()) { if (trafficConfiguration.isGlobalSwitch() || trafficConfiguration.isTenantSwitch()) {
registry.addInterceptor(createRateLimitInterceptor()); registry.addInterceptor(createRateLimitInterceptor());
} }
registry.addInterceptor(loginInterceptor()) registry.addInterceptor(loginInterceptor())
......
...@@ -17,62 +17,22 @@ ...@@ -17,62 +17,22 @@
package org.apache.dolphinscheduler.api.configuration; package org.apache.dolphinscheduler.api.configuration;
import lombok.Data;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@Data
@Configuration @Configuration
@ConfigurationProperties(prefix = "traffic.control")
public class TrafficConfiguration { public class TrafficConfiguration {
@Value("${traffic.control.global.switch:false}") private boolean globalSwitch;
private boolean trafficGlobalControlSwitch; private Integer maxGlobalQpsRate = 300;
@Value("${traffic.control.max.global.qps.rate:300}") private boolean tenantSwitch;
private Integer maxGlobalQpsRate; private Integer defaultTenantQpsRate = 10;
@Value("${traffic.control.tenant.switch:false}") private Map<String, Integer> customizeTenantQpsRate = new HashMap<>();
private boolean trafficTenantControlSwitch;
@Value("${traffic.control.default.tenant.qps.rate:10}")
private Integer defaultTenantQpsRate;
@Value("#{'${traffic.control.customize.tenant.qps.rate:}'.empty?null:'${traffic.control.customize.tenant.qps.rate:}'}")
private Map<String, Integer> customizeTenantQpsRate;
public boolean isTrafficGlobalControlSwitch() {
return trafficGlobalControlSwitch;
}
public void setTrafficGlobalControlSwitch(boolean trafficGlobalControlSwitch) {
this.trafficGlobalControlSwitch = trafficGlobalControlSwitch;
}
public Integer getMaxGlobalQpsRate() {
return maxGlobalQpsRate;
}
public void setMaxGlobalQpsRate(Integer maxGlobalQpsRate) {
this.maxGlobalQpsRate = maxGlobalQpsRate;
}
public boolean isTrafficTenantControlSwitch() {
return trafficTenantControlSwitch;
}
public void setTrafficTenantControlSwitch(boolean trafficTenantControlSwitch) {
this.trafficTenantControlSwitch = trafficTenantControlSwitch;
}
public Integer getDefaultTenantQpsRate() {
return defaultTenantQpsRate;
}
public void setDefaultTenantQpsRate(Integer defaultTenantQpsRate) {
this.defaultTenantQpsRate = defaultTenantQpsRate;
}
public Map<String, Integer> getCustomizeTenantQpsRate() {
return customizeTenantQpsRate;
}
public void setCustomizeTenantQpsRate(Map<String, Integer> customizeTenantQpsRate) {
this.customizeTenantQpsRate = customizeTenantQpsRate;
}
} }
...@@ -72,7 +72,7 @@ public class RateLimitInterceptor implements HandlerInterceptor { ...@@ -72,7 +72,7 @@ public class RateLimitInterceptor implements HandlerInterceptor {
@Override @Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ExecutionException { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ExecutionException {
// tenant-level rate limit // tenant-level rate limit
if (trafficConfiguration.isTrafficTenantControlSwitch()) { if (trafficConfiguration.isTenantSwitch()) {
String token = request.getHeader("token"); String token = request.getHeader("token");
if (!StringUtils.isEmpty(token)) { if (!StringUtils.isEmpty(token)) {
RateLimiter tenantRateLimiter = tenantRateLimiterCache.get(token); RateLimiter tenantRateLimiter = tenantRateLimiterCache.get(token);
...@@ -84,7 +84,7 @@ public class RateLimitInterceptor implements HandlerInterceptor { ...@@ -84,7 +84,7 @@ public class RateLimitInterceptor implements HandlerInterceptor {
} }
} }
// global rate limit // global rate limit
if (trafficConfiguration.isTrafficGlobalControlSwitch()) { if (trafficConfiguration.isGlobalSwitch()) {
if (!globalRateLimiter.tryAcquire()) { if (!globalRateLimiter.tryAcquire()) {
response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value()); response.setStatus(HttpStatus.TOO_MANY_REQUESTS.value());
logger.warn("Too many request, reach global rate limit, current qps is {}", globalRateLimiter.getRate()); logger.warn("Too many request, reach global rate limit, current qps is {}", globalRateLimiter.getRate());
...@@ -96,7 +96,7 @@ public class RateLimitInterceptor implements HandlerInterceptor { ...@@ -96,7 +96,7 @@ public class RateLimitInterceptor implements HandlerInterceptor {
public RateLimitInterceptor(TrafficConfiguration trafficConfiguration) { public RateLimitInterceptor(TrafficConfiguration trafficConfiguration) {
this.trafficConfiguration = trafficConfiguration; this.trafficConfiguration = trafficConfiguration;
if (trafficConfiguration.isTrafficGlobalControlSwitch()) { if (trafficConfiguration.isGlobalSwitch()) {
this.globalRateLimiter = RateLimiter.create(trafficConfiguration.getMaxGlobalQpsRate(), 1, TimeUnit.SECONDS); this.globalRateLimiter = RateLimiter.create(trafficConfiguration.getMaxGlobalQpsRate(), 1, TimeUnit.SECONDS);
} }
} }
......
...@@ -147,6 +147,21 @@ security: ...@@ -147,6 +147,21 @@ security:
# action when ldap user is not exist (supported types: CREATE,DENY) # action when ldap user is not exist (supported types: CREATE,DENY)
not-exist-action: CREATE not-exist-action: CREATE
# Traffic control, if you turn on this config, the maximum number of request/s will be limited.
# global max request number per second
# default tenant-level max request number
traffic:
control:
global-switch: false
max-global-qps-rate: 300
tenant-switch: false
default-tenant-qps-rate: 10
#customize-tenant-qps-rate:
# eg.
#tenant1: 11
#tenant2: 20
# Override by profile # Override by profile
--- ---
......
...@@ -32,7 +32,7 @@ public class TrafficConfigurationTest extends AbstractControllerTest { ...@@ -32,7 +32,7 @@ public class TrafficConfigurationTest extends AbstractControllerTest {
@Test @Test
public void isTrafficGlobalControlSwitch() { public void isTrafficGlobalControlSwitch() {
Assert.assertFalse(trafficConfiguration.isTrafficGlobalControlSwitch()); Assert.assertFalse(trafficConfiguration.isGlobalSwitch());
} }
@Test @Test
...@@ -42,7 +42,7 @@ public class TrafficConfigurationTest extends AbstractControllerTest { ...@@ -42,7 +42,7 @@ public class TrafficConfigurationTest extends AbstractControllerTest {
@Test @Test
public void isTrafficTenantControlSwitch() { public void isTrafficTenantControlSwitch() {
Assert.assertFalse(trafficConfiguration.isTrafficTenantControlSwitch()); Assert.assertFalse(trafficConfiguration.isTenantSwitch());
} }
@Test @Test
...@@ -54,4 +54,4 @@ public class TrafficConfigurationTest extends AbstractControllerTest { ...@@ -54,4 +54,4 @@ public class TrafficConfigurationTest extends AbstractControllerTest {
public void getCustomizeTenantQpsRate() { public void getCustomizeTenantQpsRate() {
Assert.assertTrue(MapUtils.isEmpty(trafficConfiguration.getCustomizeTenantQpsRate())); Assert.assertTrue(MapUtils.isEmpty(trafficConfiguration.getCustomizeTenantQpsRate()));
} }
} }
\ No newline at end of file
...@@ -48,7 +48,7 @@ public class RateLimitInterceptorTest { ...@@ -48,7 +48,7 @@ public class RateLimitInterceptorTest {
@Test @Test
public void testPreHandleWithTenantLevenControl() throws ExecutionException { public void testPreHandleWithTenantLevenControl() throws ExecutionException {
TrafficConfiguration trafficConfiguration = new TrafficConfiguration(); TrafficConfiguration trafficConfiguration = new TrafficConfiguration();
trafficConfiguration.setTrafficTenantControlSwitch(true); trafficConfiguration.setTenantSwitch(true);
Map<String, Integer> map = new HashMap<>(); Map<String, Integer> map = new HashMap<>();
map.put("tenant1", 2); map.put("tenant1", 2);
map.put("tenant2", 2); map.put("tenant2", 2);
...@@ -72,8 +72,8 @@ public class RateLimitInterceptorTest { ...@@ -72,8 +72,8 @@ public class RateLimitInterceptorTest {
@Test @Test
public void testPreHandleWithGlobalControl() throws ExecutionException { public void testPreHandleWithGlobalControl() throws ExecutionException {
TrafficConfiguration trafficConfiguration = new TrafficConfiguration(); TrafficConfiguration trafficConfiguration = new TrafficConfiguration();
trafficConfiguration.setTrafficTenantControlSwitch(true); trafficConfiguration.setTenantSwitch(true);
trafficConfiguration.setTrafficGlobalControlSwitch(true); trafficConfiguration.setGlobalSwitch(true);
trafficConfiguration.setMaxGlobalQpsRate(3); trafficConfiguration.setMaxGlobalQpsRate(3);
RateLimitInterceptor rateLimitInterceptor = new RateLimitInterceptor(trafficConfiguration); RateLimitInterceptor rateLimitInterceptor = new RateLimitInterceptor(trafficConfiguration);
...@@ -86,4 +86,4 @@ public class RateLimitInterceptorTest { ...@@ -86,4 +86,4 @@ public class RateLimitInterceptorTest {
Assert.assertFalse(rateLimitInterceptor.preHandle(request, response, null)); Assert.assertFalse(rateLimitInterceptor.preHandle(request, response, null));
} }
} }
\ No newline at end of file
...@@ -105,6 +105,20 @@ security: ...@@ -105,6 +105,20 @@ security:
# action when ldap user is not exist (supported types: CREATE,DENY) # action when ldap user is not exist (supported types: CREATE,DENY)
not-exist-action: CREATE not-exist-action: CREATE
# Traffic control, if you turn on this config, the maximum number of request/s will be limited.
# global max request number per second
# default tenant-level max request number
traffic:
control:
global-switch: false
max-global-qps-rate: 300
tenant-switch: false
default-tenant-qps-rate: 10
#customize-tenant-qps-rate:
# eg.
#tenant1: 11
#tenant2: 20
master: master:
listen-port: 5678 listen-port: 5678
# master fetch command num # master fetch command num
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册