diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRoleController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRoleController.java index f5cbe5fbe..e5225e1e3 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRoleController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysRoleController.java @@ -55,7 +55,6 @@ public class SysRoleController { /** * 通过ID查询角色信息 - * * @param id ID * @return 角色信息 */ @@ -66,7 +65,6 @@ public class SysRoleController { /** * 添加角色 - * * @param sysRole 角色信息 * @return success、false */ @@ -80,7 +78,6 @@ public class SysRoleController { /** * 修改角色 - * * @param sysRole 角色信息 * @return success/false */ @@ -94,7 +91,6 @@ public class SysRoleController { /** * 删除角色 - * * @param id * @return */ @@ -108,7 +104,6 @@ public class SysRoleController { /** * 获取角色列表 - * * @return 角色列表 */ @GetMapping("/list") @@ -118,7 +113,6 @@ public class SysRoleController { /** * 分页查询角色信息 - * * @param page 分页对象 * @return 分页对象 */ @@ -129,7 +123,6 @@ public class SysRoleController { /** * 更新角色菜单 - * * @param roleVo 角色对象 * @return success、false */ @@ -142,7 +135,6 @@ public class SysRoleController { /** * 通过角色ID 查询角色列表 - * * @param roleIdList 角色ID * @return */ diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java index f7e5e63bc..82b40202e 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysRoleService.java @@ -37,7 +37,6 @@ public interface SysRoleService extends IService { /** * 通过用户ID,查询角色信息 - * * @param userId * @return */ @@ -45,16 +44,14 @@ public interface SysRoleService extends IService { /** * 根据角色ID 查询角色列表 - * * @param roleIdList 角色ID列表 - * @param key 缓存key + * @param key 缓存key * @return */ List findRolesByRoleIds(List roleIdList, String key); /** * 通过角色ID,删除角色 - * * @param id * @return */ @@ -62,9 +59,9 @@ public interface SysRoleService extends IService { /** * 根据角色菜单列表 - * * @param roleVo 角色&菜单列表 * @return */ Boolean updateRoleMenus(RoleVO roleVo); + } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java index 29e6d6c85..a2d2ef1da 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysRoleServiceImpl.java @@ -51,7 +51,6 @@ public class SysRoleServiceImpl extends ServiceImpl impl /** * 通过用户ID,查询角色信息 - * * @param userId * @return */ @@ -62,9 +61,8 @@ public class SysRoleServiceImpl extends ServiceImpl impl /** * 根据角色ID 查询角色列表,注意缓存删除 - * * @param roleIdList 角色ID列表 - * @param key 缓存key + * @param key 缓存key * @return */ @Override @@ -75,7 +73,6 @@ public class SysRoleServiceImpl extends ServiceImpl impl /** * 通过角色ID,删除角色,并清空角色菜单缓存 - * * @param id * @return */ @@ -88,7 +85,6 @@ public class SysRoleServiceImpl extends ServiceImpl impl /** * 根据角色菜单列表 - * * @param roleVo 角色&菜单列表 * @return */ @@ -97,4 +93,5 @@ public class SysRoleServiceImpl extends ServiceImpl impl SysRole sysRole = baseMapper.selectById(roleVo.getRoleId()); return roleMenuService.saveRoleMenus(sysRole.getRoleCode(), roleVo.getRoleId(), roleVo.getMenuIds()); } + } diff --git a/pigx-visual/pigx-pay-platform/src/main/java/com/pig4cloud/pigx/pay/controller/PayGoodsOrderController.java b/pigx-visual/pigx-pay-platform/src/main/java/com/pig4cloud/pigx/pay/controller/PayGoodsOrderController.java index 38e05453f..20cfac8db 100755 --- a/pigx-visual/pigx-pay-platform/src/main/java/com/pig4cloud/pigx/pay/controller/PayGoodsOrderController.java +++ b/pigx-visual/pigx-pay-platform/src/main/java/com/pig4cloud/pigx/pay/controller/PayGoodsOrderController.java @@ -58,8 +58,7 @@ public class PayGoodsOrderController { /** * 商品订单 - * - * @param goods 商品 + * @param goods 商品 * @param response * @return R */ @@ -86,10 +85,9 @@ public class PayGoodsOrderController { /** * oauth - * - * @param goods 商品信息 - * @param state appid - * @param code 回调code + * @param goods 商品信息 + * @param state appid + * @param code 回调code * @param modelAndView * @return * @throws WxErrorException @@ -109,8 +107,7 @@ public class PayGoodsOrderController { /** * 分页查询 - * - * @param page 分页对象 + * @param page 分页对象 * @param payGoodsOrder 商品订单表 * @return */ @@ -122,7 +119,6 @@ public class PayGoodsOrderController { /** * 通过id查询商品订单表 - * * @param goodsOrderId id * @return R */ @@ -134,7 +130,6 @@ public class PayGoodsOrderController { /** * 新增商品订单表 - * * @param payGoodsOrder 商品订单表 * @return R */ @@ -148,7 +143,6 @@ public class PayGoodsOrderController { /** * 修改商品订单表 - * * @param payGoodsOrder 商品订单表 * @return R */ @@ -162,7 +156,6 @@ public class PayGoodsOrderController { /** * 通过id删除商品订单表 - * * @param goodsOrderId id * @return R */ diff --git a/pigx-visual/pigx-sentinel-dashboard/pom.xml b/pigx-visual/pigx-sentinel-dashboard/pom.xml index 44d853f6c..adaae2a38 100755 --- a/pigx-visual/pigx-sentinel-dashboard/pom.xml +++ b/pigx-visual/pigx-sentinel-dashboard/pom.xml @@ -42,16 +42,6 @@ org.springframework.boot spring-boot-starter-undertow - - org.springframework.boot - spring-boot-starter-logging - - - - log4j - log4j - 1.2.14 - commons-lang @@ -86,8 +76,8 @@ src/main/resources + true - src/main/webapp/ diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/PigxSentinelApplication.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/PigxSentinelApplication.java index e8c67fe19..c406793f8 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/PigxSentinelApplication.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/PigxSentinelApplication.java @@ -21,9 +21,9 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** - * @author nacos - *

- * sentinel console 源码运行,方便开发 生产建议从官网下载最新版配置运行 + * Sentinel dashboard application. + * + * @author Carpenter Lee */ @SpringBootApplication public class PigxSentinelApplication { @@ -34,7 +34,7 @@ public class PigxSentinelApplication { } private static void triggerSentinelInit() { - new Thread(InitExecutor::doInit).start(); + new Thread(() -> InitExecutor.doInit()).start(); } } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthAction.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthAction.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthService.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthService.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthorizationInterceptor.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/AuthorizationInterceptor.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/FakeAuthServiceImpl.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/FakeAuthServiceImpl.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/LoginAuthenticationFilter.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/LoginAuthenticationFilter.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/SimpleWebAuthServiceImpl.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/auth/SimpleWebAuthServiceImpl.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandFailedException.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandFailedException.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandNotFoundException.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/CommandNotFoundException.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java index 2fe43ef27..60bb6624f 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/client/SentinelApiClient.java @@ -69,6 +69,7 @@ import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.concurrent.FutureCallback; import org.apache.http.entity.ContentType; import org.apache.http.impl.client.DefaultRedirectStrategy; @@ -95,6 +96,11 @@ public class SentinelApiClient { private static final Charset DEFAULT_CHARSET = Charset.forName(SentinelConfig.charset()); + private static final String HTTP_HEADER_CONTENT_TYPE = "Content-Type"; + + private static final String HTTP_HEADER_CONTENT_TYPE_URLENCODED = ContentType.create(URLEncodedUtils.CONTENT_TYPE) + .toString(); + private static final String RESOURCE_URL_PATH = "jsonTree"; private static final String CLUSTER_NODE_PATH = "clusterNode"; @@ -115,8 +121,6 @@ public class SentinelApiClient { private static final String MODIFY_CLUSTER_CLIENT_CONFIG_PATH = "cluster/client/modifyConfig"; - private static final String FETCH_CLUSTER_SERVER_ALL_CONFIG_PATH = "cluster/server/fetchConfig"; - private static final String FETCH_CLUSTER_SERVER_BASIC_INFO_PATH = "cluster/server/info"; private static final String MODIFY_CLUSTER_SERVER_TRANSPORT_CONFIG_PATH = "cluster/server/modifyTransportConfig"; @@ -145,6 +149,8 @@ public class SentinelApiClient { private static final SentinelVersion version160 = new SentinelVersion(1, 6, 0); + private static final SentinelVersion version171 = new SentinelVersion(1, 7, 1); + @Autowired private AppManagement appManagement; @@ -169,6 +175,27 @@ public class SentinelApiClient { && body.contains(CommandConstants.MSG_UNKNOWN_COMMAND_PREFIX); } + protected boolean isSupportPost(String app, String ip, int port) { + return StringUtil.isNotEmpty(app) + && Optional.ofNullable(appManagement.getDetailApp(app)).flatMap(e -> e.getMachine(ip, port)) + .flatMap(m -> VersionUtils.parseVersion(m.getVersion()).map(v -> v.greaterOrEqual(version160))) + .orElse(false); + } + + /** + * Check wheter target instance (identified by tuple of app-ip:port) supports the form + * of "xxxxx; xx=xx" in "Content-Type" header. + * @param app target app name + * @param ip target node's address + * @param port target node's port + */ + protected boolean isSupportEnhancedContentType(String app, String ip, int port) { + return StringUtil.isNotEmpty(app) + && Optional.ofNullable(appManagement.getDetailApp(app)).flatMap(e -> e.getMachine(ip, port)) + .flatMap(m -> VersionUtils.parseVersion(m.getVersion()).map(v -> v.greaterOrEqual(version171))) + .orElse(false); + } + private StringBuilder queryString(Map params) { StringBuilder queryStringBuilder = new StringBuilder(); for (Entry entry : params.entrySet()) { @@ -187,7 +214,16 @@ public class SentinelApiClient { return queryStringBuilder; } - private HttpUriRequest postRequest(String url, Map params) { + /** + * Build an `HttpUriRequest` in POST way. + * @param url + * @param params + * @param supportEnhancedContentType see + * {@link #isSupportEnhancedContentType(String, String, int)} + * @return + */ + protected static HttpUriRequest postRequest(String url, Map params, + boolean supportEnhancedContentType) { HttpPost httpPost = new HttpPost(url); if (params != null && params.size() > 0) { List list = new ArrayList<>(params.size()); @@ -195,6 +231,9 @@ public class SentinelApiClient { list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } httpPost.setEntity(new UrlEncodedFormEntity(list, Consts.UTF_8)); + if (!supportEnhancedContentType) { + httpPost.setHeader(HTTP_HEADER_CONTENT_TYPE, HTTP_HEADER_CONTENT_TYPE_URLENCODED); + } } return httpPost; } @@ -212,7 +251,7 @@ public class SentinelApiClient { private String getBody(HttpResponse response) throws Exception { Charset charset = null; try { - String contentTypeStr = response.getFirstHeader("Content-type").getValue(); + String contentTypeStr = response.getFirstHeader(HTTP_HEADER_CONTENT_TYPE).getValue(); if (StringUtil.isNotEmpty(contentTypeStr)) { ContentType contentType = ContentType.parse(contentTypeStr); charset = contentType.getCharset(); @@ -269,11 +308,7 @@ public class SentinelApiClient { if (params == null) { params = Collections.emptyMap(); } - boolean supportPost = StringUtil.isNotEmpty(app) - && Optional.ofNullable(appManagement.getDetailApp(app)).flatMap(e -> e.getMachine(ip, port)) - .flatMap(m -> VersionUtils.parseVersion(m.getVersion()).map(v -> v.greaterOrEqual(version160))) - .orElse(false); - if (!useHttpPost || !supportPost) { + if (!useHttpPost || !isSupportPost(app, ip, port)) { // Using GET in older versions, append parameters after url if (!params.isEmpty()) { if (urlBuilder.indexOf("?") == -1) { @@ -288,7 +323,8 @@ public class SentinelApiClient { } else { // Using POST - return executeCommand(postRequest(urlBuilder.toString(), params)); + return executeCommand( + postRequest(urlBuilder.toString(), params, isSupportEnhancedContentType(app, ip, port))); } } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/DashboardConfig.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/DashboardConfig.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthController.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/AuthorityRuleController.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java index 0eea1aca7..6a23ea933 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DegradeController.java @@ -22,41 +22,47 @@ import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType; +import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository; import com.alibaba.csp.sentinel.slots.block.RuleConstant; +import com.alibaba.csp.sentinel.slots.block.degrade.circuitbreaker.CircuitBreakerStrategy; import com.alibaba.csp.sentinel.util.StringUtil; import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.DegradeRuleEntity; import com.alibaba.csp.sentinel.dashboard.domain.Result; -import com.alibaba.csp.sentinel.dashboard.repository.rule.InMemDegradeRuleStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; /** - * @author leyou + * Controller regarding APIs of degrade rules. Refactored since 1.8.0. + * + * @author Carpenter Lee + * @author Eric Zhao */ -@Controller -@RequestMapping(value = "/degrade", produces = MediaType.APPLICATION_JSON_VALUE) +@RestController +@RequestMapping("/degrade") public class DegradeController { private final Logger logger = LoggerFactory.getLogger(DegradeController.class); @Autowired - private InMemDegradeRuleStore repository; + private RuleRepository repository; @Autowired private SentinelApiClient sentinelApiClient; - @ResponseBody - @RequestMapping("/rules.json") + @GetMapping("/rules.json") @AuthAction(PrivilegeType.READ_RULE) - public Result> queryMachineRules(String app, String ip, Integer port) { - + public Result> apiQueryMachineRules(String app, String ip, Integer port) { if (StringUtil.isEmpty(app)) { return Result.ofFail(-1, "app can't be null or empty"); } @@ -77,119 +83,66 @@ public class DegradeController { } } - @ResponseBody - @RequestMapping("/new.json") + @PostMapping("/rule") @AuthAction(PrivilegeType.WRITE_RULE) - public Result add(String app, String ip, Integer port, String limitApp, String resource, - Double count, Integer timeWindow, Integer grade) { - if (StringUtil.isBlank(app)) { - return Result.ofFail(-1, "app can't be null or empty"); + public Result apiAddRule(@RequestBody DegradeRuleEntity entity) { + Result checkResult = checkEntityInternal(entity); + if (checkResult != null) { + return checkResult; } - if (StringUtil.isBlank(ip)) { - return Result.ofFail(-1, "ip can't be null or empty"); - } - if (port == null) { - return Result.ofFail(-1, "port can't be null"); - } - if (StringUtil.isBlank(limitApp)) { - return Result.ofFail(-1, "limitApp can't be null or empty"); - } - if (StringUtil.isBlank(resource)) { - return Result.ofFail(-1, "resource can't be null or empty"); - } - if (count == null) { - return Result.ofFail(-1, "count can't be null"); - } - if (timeWindow == null) { - return Result.ofFail(-1, "timeWindow can't be null"); - } - if (grade == null) { - return Result.ofFail(-1, "grade can't be null"); - } - if (grade < RuleConstant.DEGRADE_GRADE_RT || grade > RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) { - return Result.ofFail(-1, "Invalid grade: " + grade); - } - DegradeRuleEntity entity = new DegradeRuleEntity(); - entity.setApp(app.trim()); - entity.setIp(ip.trim()); - entity.setPort(port); - entity.setLimitApp(limitApp.trim()); - entity.setResource(resource.trim()); - entity.setCount(count); - entity.setTimeWindow(timeWindow); - entity.setGrade(grade); Date date = new Date(); entity.setGmtCreate(date); entity.setGmtModified(date); try { entity = repository.save(entity); } - catch (Throwable throwable) { - logger.error("add error:", throwable); - return Result.ofThrowable(-1, throwable); + catch (Throwable t) { + logger.error("Failed to add new degrade rule, app={}, ip={}", entity.getApp(), entity.getIp(), t); + return Result.ofThrowable(-1, t); } - if (!publishRules(app, ip, port)) { - logger.info("publish degrade rules fail after rule add"); + if (!publishRules(entity.getApp(), entity.getIp(), entity.getPort())) { + logger.warn("Publish degrade rules failed, app={}", entity.getApp()); } return Result.ofSuccess(entity); } - @ResponseBody - @RequestMapping("/save.json") + @PutMapping("/rule/{id}") @AuthAction(PrivilegeType.WRITE_RULE) - public Result updateIfNotNull(Long id, String app, String limitApp, String resource, - Double count, Integer timeWindow, Integer grade) { - if (id == null) { - return Result.ofFail(-1, "id can't be null"); + public Result apiUpdateRule(@PathVariable("id") Long id, @RequestBody DegradeRuleEntity entity) { + if (id == null || id <= 0) { + return Result.ofFail(-1, "id can't be null or negative"); } - if (grade != null) { - if (grade < RuleConstant.DEGRADE_GRADE_RT || grade > RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) { - return Result.ofFail(-1, "Invalid grade: " + grade); - } + DegradeRuleEntity oldEntity = repository.findById(id); + if (oldEntity == null) { + return Result.ofFail(-1, "Degrade rule does not exist, id=" + id); } - DegradeRuleEntity entity = repository.findById(id); - if (entity == null) { - return Result.ofFail(-1, "id " + id + " dose not exist"); + entity.setApp(oldEntity.getApp()); + entity.setIp(oldEntity.getIp()); + entity.setPort(oldEntity.getPort()); + entity.setId(oldEntity.getId()); + Result checkResult = checkEntityInternal(entity); + if (checkResult != null) { + return checkResult; } - if (StringUtil.isNotBlank(app)) { - entity.setApp(app.trim()); - } - - if (StringUtil.isNotBlank(limitApp)) { - entity.setLimitApp(limitApp.trim()); - } - if (StringUtil.isNotBlank(resource)) { - entity.setResource(resource.trim()); - } - if (count != null) { - entity.setCount(count); - } - if (timeWindow != null) { - entity.setTimeWindow(timeWindow); - } - if (grade != null) { - entity.setGrade(grade); - } - Date date = new Date(); - entity.setGmtModified(date); + entity.setGmtCreate(oldEntity.getGmtCreate()); + entity.setGmtModified(new Date()); try { entity = repository.save(entity); } - catch (Throwable throwable) { - logger.error("save error:", throwable); - return Result.ofThrowable(-1, throwable); + catch (Throwable t) { + logger.error("Failed to save degrade rule, id={}, rule={}", id, entity, t); + return Result.ofThrowable(-1, t); } if (!publishRules(entity.getApp(), entity.getIp(), entity.getPort())) { - logger.info("publish degrade rules fail after rule update"); + logger.warn("Publish degrade rules failed, app={}", entity.getApp()); } return Result.ofSuccess(entity); } - @ResponseBody - @RequestMapping("/delete.json") + @DeleteMapping("/rule/{id}") @AuthAction(PrivilegeType.DELETE_RULE) - public Result delete(Long id) { + public Result delete(@PathVariable("id") Long id) { if (id == null) { return Result.ofFail(-1, "id can't be null"); } @@ -203,11 +156,11 @@ public class DegradeController { repository.delete(id); } catch (Throwable throwable) { - logger.error("delete error:", throwable); + logger.error("Failed to delete degrade rule, id={}", id, throwable); return Result.ofThrowable(-1, throwable); } if (!publishRules(oldEntity.getApp(), oldEntity.getIp(), oldEntity.getPort())) { - logger.info("publish degrade rules fail after rule delete"); + logger.warn("Publish degrade rules failed, app={}", oldEntity.getApp()); } return Result.ofSuccess(id); } @@ -217,4 +170,59 @@ public class DegradeController { return sentinelApiClient.setDegradeRuleOfMachine(app, ip, port, rules); } + private Result checkEntityInternal(DegradeRuleEntity entity) { + if (StringUtil.isBlank(entity.getApp())) { + return Result.ofFail(-1, "app can't be blank"); + } + if (StringUtil.isBlank(entity.getIp())) { + return Result.ofFail(-1, "ip can't be null or empty"); + } + if (entity.getPort() == null || entity.getPort() <= 0) { + return Result.ofFail(-1, "invalid port: " + entity.getPort()); + } + if (StringUtil.isBlank(entity.getLimitApp())) { + return Result.ofFail(-1, "limitApp can't be null or empty"); + } + if (StringUtil.isBlank(entity.getResource())) { + return Result.ofFail(-1, "resource can't be null or empty"); + } + Double threshold = entity.getCount(); + if (threshold == null || threshold < 0) { + return Result.ofFail(-1, "invalid threshold: " + threshold); + } + Integer recoveryTimeoutSec = entity.getTimeWindow(); + if (recoveryTimeoutSec == null || recoveryTimeoutSec <= 0) { + return Result.ofFail(-1, "recoveryTimeout should be positive"); + } + Integer strategy = entity.getGrade(); + if (strategy == null) { + return Result.ofFail(-1, "circuit breaker strategy cannot be null"); + } + if (strategy < CircuitBreakerStrategy.SLOW_REQUEST_RATIO.getType() + || strategy > RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT) { + return Result.ofFail(-1, "Invalid circuit breaker strategy: " + strategy); + } + if (entity.getMinRequestAmount() == null || entity.getMinRequestAmount() <= 0) { + return Result.ofFail(-1, "Invalid minRequestAmount"); + } + if (entity.getStatIntervalMs() == null || entity.getStatIntervalMs() <= 0) { + return Result.ofFail(-1, "Invalid statInterval"); + } + if (strategy == RuleConstant.DEGRADE_GRADE_RT) { + Double slowRatio = entity.getSlowRatioThreshold(); + if (slowRatio == null) { + return Result.ofFail(-1, "SlowRatioThreshold is required for slow request ratio strategy"); + } + else if (slowRatio < 0 || slowRatio > 1) { + return Result.ofFail(-1, "SlowRatioThreshold should be in range: [0.0, 1.0]"); + } + } + else if (strategy == RuleConstant.DEGRADE_GRADE_EXCEPTION_RATIO) { + if (threshold > 1) { + return Result.ofFail(-1, "Ratio threshold should be in range: [0.0, 1.0]"); + } + } + return null; + } + } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DemoController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DemoController.java index 9c77b7697..ae61723ef 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DemoController.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/DemoController.java @@ -15,11 +15,9 @@ */ package com.alibaba.csp.sentinel.dashboard.controller; -import com.alibaba.csp.sentinel.Entry; -import com.alibaba.csp.sentinel.EntryType; -import com.alibaba.csp.sentinel.SphU; -import com.alibaba.csp.sentinel.context.ContextUtil; -import com.alibaba.csp.sentinel.slots.block.BlockException; +import java.util.Random; +import java.util.concurrent.TimeUnit; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.MediaType; @@ -27,8 +25,11 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; -import java.util.Random; -import java.util.concurrent.TimeUnit; +import com.alibaba.csp.sentinel.Entry; +import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.SphU; +import com.alibaba.csp.sentinel.context.ContextUtil; +import com.alibaba.csp.sentinel.slots.block.BlockException; @Controller @RequestMapping(value = "/demo", produces = MediaType.APPLICATION_JSON_VALUE) @@ -111,7 +112,7 @@ public class DemoController { try { e1 = SphU.entry(name); - if (slow == true) { + if (slow) { TimeUnit.MILLISECONDS.sleep(3000); } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java old mode 100755 new mode 100644 index f81d64cd9..e960bd347 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/ParamFlowRuleController.java @@ -15,30 +15,40 @@ */ package com.alibaba.csp.sentinel.dashboard.controller; -import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; -import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType; -import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException; -import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; -import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion; -import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; -import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; -import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; -import com.alibaba.csp.sentinel.dashboard.domain.Result; -import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository; -import com.alibaba.csp.sentinel.dashboard.util.VersionUtils; -import com.alibaba.csp.sentinel.slots.block.RuleConstant; -import com.alibaba.csp.sentinel.util.StringUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - import java.util.Date; import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import com.alibaba.csp.sentinel.dashboard.auth.AuthAction; +import com.alibaba.csp.sentinel.dashboard.client.CommandNotFoundException; +import com.alibaba.csp.sentinel.dashboard.client.SentinelApiClient; +import com.alibaba.csp.sentinel.dashboard.discovery.AppManagement; +import com.alibaba.csp.sentinel.dashboard.discovery.MachineInfo; +import com.alibaba.csp.sentinel.dashboard.auth.AuthService; +import com.alibaba.csp.sentinel.dashboard.auth.AuthService.PrivilegeType; +import com.alibaba.csp.sentinel.slots.block.RuleConstant; +import com.alibaba.csp.sentinel.util.StringUtil; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.SentinelVersion; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.ParamFlowRuleEntity; +import com.alibaba.csp.sentinel.dashboard.domain.Result; +import com.alibaba.csp.sentinel.dashboard.repository.rule.RuleRepository; +import com.alibaba.csp.sentinel.dashboard.util.VersionUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + /** * @author Eric Zhao * @since 0.2.1 @@ -110,7 +120,7 @@ public class ParamFlowRuleController { } @PostMapping("/rule") - @AuthAction(PrivilegeType.WRITE_RULE) + @AuthAction(AuthService.PrivilegeType.WRITE_RULE) public Result apiAddParamFlowRule(@RequestBody ParamFlowRuleEntity entity) { Result checkResult = checkEntityInternal(entity); if (checkResult != null) { @@ -182,7 +192,7 @@ public class ParamFlowRuleController { } @PutMapping("/rule/{id}") - @AuthAction(PrivilegeType.WRITE_RULE) + @AuthAction(AuthService.PrivilegeType.WRITE_RULE) public Result apiUpdateParamFlowRule(@PathVariable("id") Long id, @RequestBody ParamFlowRuleEntity entity) { if (id == null || id <= 0) { diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/VersionController.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterAssignController.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/cluster/ClusterConfigController.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayApiController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayApiController.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java old mode 100755 new mode 100644 index 697dcd1b0..0638982cd --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/gateway/GatewayFlowRuleController.java @@ -147,19 +147,19 @@ public class GatewayFlowRuleController { return Result.ofFail(-1, "fieldName can't be null or empty"); } itemEntity.setFieldName(paramItem.getFieldName()); + } - String pattern = paramItem.getPattern(); - // 如果匹配串不为空,验证匹配模式 - if (StringUtil.isNotEmpty(pattern)) { - itemEntity.setPattern(pattern); - - Integer matchStrategy = paramItem.getMatchStrategy(); - if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, - PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { - return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); - } - itemEntity.setMatchStrategy(matchStrategy); + String pattern = paramItem.getPattern(); + // 如果匹配串不为空,验证匹配模式 + if (StringUtil.isNotEmpty(pattern)) { + itemEntity.setPattern(pattern); + Integer matchStrategy = paramItem.getMatchStrategy(); + if (!Arrays + .asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX) + .contains(matchStrategy)) { + return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); } + itemEntity.setMatchStrategy(matchStrategy); } } @@ -298,19 +298,19 @@ public class GatewayFlowRuleController { return Result.ofFail(-1, "fieldName can't be null or empty"); } itemEntity.setFieldName(paramItem.getFieldName()); + } - String pattern = paramItem.getPattern(); - // 如果匹配串不为空,验证匹配模式 - if (StringUtil.isNotEmpty(pattern)) { - itemEntity.setPattern(pattern); - - Integer matchStrategy = paramItem.getMatchStrategy(); - if (!Arrays.asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, - PARAM_MATCH_STRATEGY_REGEX).contains(matchStrategy)) { - return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); - } - itemEntity.setMatchStrategy(matchStrategy); + String pattern = paramItem.getPattern(); + // 如果匹配串不为空,验证匹配模式 + if (StringUtil.isNotEmpty(pattern)) { + itemEntity.setPattern(pattern); + Integer matchStrategy = paramItem.getMatchStrategy(); + if (!Arrays + .asList(PARAM_MATCH_STRATEGY_EXACT, PARAM_MATCH_STRATEGY_CONTAINS, PARAM_MATCH_STRATEGY_REGEX) + .contains(matchStrategy)) { + return Result.ofFail(-1, "invalid matchStrategy: " + matchStrategy); } + itemEntity.setMatchStrategy(matchStrategy); } } else { diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java index 6df626022..e243132c0 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/v2/FlowControllerV2.java @@ -137,7 +137,7 @@ public class FlowControllerV2 { } @PostMapping("/rule") - @AuthAction(value = PrivilegeType.WRITE_RULE) + @AuthAction(value = AuthService.PrivilegeType.WRITE_RULE) public Result apiAddFlowRule(@RequestBody FlowRuleEntity entity) { Result checkResult = checkEntityInternal(entity); @@ -162,7 +162,7 @@ public class FlowControllerV2 { } @PutMapping("/rule/{id}") - @AuthAction(PrivilegeType.WRITE_RULE) + @AuthAction(AuthService.PrivilegeType.WRITE_RULE) public Result apiUpdateFlowRule(@PathVariable("id") Long id, @RequestBody FlowRuleEntity entity) { if (id == null || id <= 0) { diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricEntity.java index 4e89b454f..0f90f9458 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricEntity.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/MetricEntity.java @@ -71,7 +71,6 @@ public class MetricEntity { entity.setExceptionQps(oldEntity.getExceptionQps()); entity.setRt(oldEntity.getRt()); entity.setCount(oldEntity.getCount()); - entity.setResource(oldEntity.getResource()); return entity; } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/SentinelVersion.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/ApiDefinitionEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/ApiDefinitionEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/ApiPredicateItemEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/ApiPredicateItemEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/GatewayFlowRuleEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/GatewayFlowRuleEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/GatewayParamFlowItemEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/GatewayParamFlowItemEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java index 1aa2fc299..1be3746d7 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java @@ -40,11 +40,14 @@ public class DegradeRuleEntity implements RuleEntity { private Integer timeWindow; - /** - * 0 rt 限流; 1为异常; - */ private Integer grade; + private Integer minRequestAmount; + + private Double slowRatioThreshold; + + private Integer statIntervalMs; + private Date gmtCreate; private Date gmtModified; @@ -59,6 +62,9 @@ public class DegradeRuleEntity implements RuleEntity { entity.setCount(rule.getCount()); entity.setTimeWindow(rule.getTimeWindow()); entity.setGrade(rule.getGrade()); + entity.setMinRequestAmount(rule.getMinRequestAmount()); + entity.setSlowRatioThreshold(rule.getSlowRatioThreshold()); + entity.setStatIntervalMs(rule.getStatIntervalMs()); return entity; } @@ -139,6 +145,33 @@ public class DegradeRuleEntity implements RuleEntity { this.grade = grade; } + public Integer getMinRequestAmount() { + return minRequestAmount; + } + + public DegradeRuleEntity setMinRequestAmount(Integer minRequestAmount) { + this.minRequestAmount = minRequestAmount; + return this; + } + + public Double getSlowRatioThreshold() { + return slowRatioThreshold; + } + + public DegradeRuleEntity setSlowRatioThreshold(Double slowRatioThreshold) { + this.slowRatioThreshold = slowRatioThreshold; + return this; + } + + public Integer getStatIntervalMs() { + return statIntervalMs; + } + + public DegradeRuleEntity setStatIntervalMs(Integer statIntervalMs) { + this.statIntervalMs = statIntervalMs; + return this; + } + @Override public Date getGmtCreate() { return gmtCreate; @@ -164,6 +197,16 @@ public class DegradeRuleEntity implements RuleEntity { rule.setCount(count); rule.setTimeWindow(timeWindow); rule.setGrade(grade); + if (minRequestAmount != null) { + rule.setMinRequestAmount(minRequestAmount); + } + if (slowRatioThreshold != null) { + rule.setSlowRatioThreshold(slowRatioThreshold); + } + if (statIntervalMs != null) { + rule.setStatIntervalMs(statIntervalMs); + } + return rule; } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppAssignResultVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppFullAssignRequest.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterAppSingleServerAssignRequest.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterClientInfoVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterGroupEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ClusterStateSingleVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionDescriptorVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/ConnectionGroupVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ClusterClientConfig.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerFlowConfig.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/config/ServerTransportConfig.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterAppAssignMap.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterClientModifyRequest.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterModifyRequest.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/request/ClusterServerModifyRequest.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterClientStateWrapVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/AppClusterServerStateWrapVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterClientStateVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterRequestLimitVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterServerStateVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterStateSimpleEntity.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStatePairVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/cluster/state/ClusterUniversalStateVO.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/api/AddApiReqVo.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/api/AddApiReqVo.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/api/ApiPredicateItemVo.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/api/ApiPredicateItemVo.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/api/UpdateApiReqVo.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/api/UpdateApiReqVo.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/rule/AddFlowRuleReqVo.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/rule/AddFlowRuleReqVo.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/rule/GatewayParamFlowItemVo.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/rule/GatewayParamFlowItemVo.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/rule/UpdateFlowRuleReqVo.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/domain/vo/gateway/rule/UpdateFlowRuleReqVo.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/gateway/InMemApiDefinitionStore.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/gateway/InMemApiDefinitionStore.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/gateway/InMemGatewayFlowRuleStore.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/gateway/InMemGatewayFlowRuleStore.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java old mode 100755 new mode 100644 index 97409b748..c6eb22fd7 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/InMemoryMetricsRepository.java @@ -15,6 +15,11 @@ */ package com.alibaba.csp.sentinel.dashboard.repository.metric; +import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; +import com.alibaba.csp.sentinel.util.StringUtil; +import com.alibaba.csp.sentinel.util.TimeUtil; +import org.springframework.stereotype.Component; + import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -22,14 +27,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.stream.Collectors; -import com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity; -import com.alibaba.csp.sentinel.util.StringUtil; - -import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; -import org.springframework.stereotype.Component; - /** * Caches metrics data in a period of time in memory. * @@ -44,56 +44,73 @@ public class InMemoryMetricsRepository implements MetricsRepository resource -> timestamp -> metric} */ - private Map>> allMetrics = new ConcurrentHashMap<>(); + private Map>> allMetrics = new ConcurrentHashMap<>(); + + private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock(); @Override - public synchronized void save(MetricEntity entity) { + public void save(MetricEntity entity) { if (entity == null || StringUtil.isBlank(entity.getApp())) { return; } - allMetrics.computeIfAbsent(entity.getApp(), e -> new ConcurrentHashMap<>(16)) - .computeIfAbsent(entity.getResource(), - e -> new ConcurrentLinkedHashMap.Builder() - .maximumWeightedCapacity(MAX_METRIC_LIVE_TIME_MS).weigher((key, value) -> { - // Metric older than {@link #MAX_METRIC_LIVE_TIME_MS} - // will be removed. - int weight = (int) (System.currentTimeMillis() - key); - // weight must be a number greater than or equal to - // one - return Math.max(weight, 1); - }).build()) - .put(entity.getTimestamp().getTime(), entity); + readWriteLock.writeLock().lock(); + try { + allMetrics.computeIfAbsent(entity.getApp(), e -> new HashMap<>(16)) + .computeIfAbsent(entity.getResource(), e -> new LinkedHashMap() { + @Override + protected boolean removeEldestEntry(Entry eldest) { + // Metric older than {@link #MAX_METRIC_LIVE_TIME_MS} will be + // removed. + return eldest.getKey() < TimeUtil.currentTimeMillis() - MAX_METRIC_LIVE_TIME_MS; + } + }).put(entity.getTimestamp().getTime(), entity); + } + finally { + readWriteLock.writeLock().unlock(); + } + } @Override - public synchronized void saveAll(Iterable metrics) { + public void saveAll(Iterable metrics) { if (metrics == null) { return; } - metrics.forEach(this::save); + readWriteLock.writeLock().lock(); + try { + metrics.forEach(this::save); + } + finally { + readWriteLock.writeLock().unlock(); + } } @Override - public synchronized List queryByAppAndResourceBetween(String app, String resource, long startTime, - long endTime) { + public List queryByAppAndResourceBetween(String app, String resource, long startTime, long endTime) { List results = new ArrayList<>(); if (StringUtil.isBlank(app)) { return results; } - Map> resourceMap = allMetrics.get(app); + Map> resourceMap = allMetrics.get(app); if (resourceMap == null) { return results; } - ConcurrentLinkedHashMap metricsMap = resourceMap.get(resource); + LinkedHashMap metricsMap = resourceMap.get(resource); if (metricsMap == null) { return results; } - for (Entry entry : metricsMap.entrySet()) { - if (entry.getKey() >= startTime && entry.getKey() <= endTime) { - results.add(entry.getValue()); + readWriteLock.readLock().lock(); + try { + for (Entry entry : metricsMap.entrySet()) { + if (entry.getKey() >= startTime && entry.getKey() <= endTime) { + results.add(entry.getValue()); + } } + return results; + } + finally { + readWriteLock.readLock().unlock(); } - return results; } @Override @@ -103,42 +120,48 @@ public class InMemoryMetricsRepository implements MetricsRepository timestamp -> metric - Map> resourceMap = allMetrics.get(app); + Map> resourceMap = allMetrics.get(app); if (resourceMap == null) { return results; } final long minTimeMs = System.currentTimeMillis() - 1000 * 60; Map resourceCount = new ConcurrentHashMap<>(32); - for (Entry> resourceMetrics : resourceMap.entrySet()) { - for (Entry metrics : resourceMetrics.getValue().entrySet()) { - if (metrics.getKey() < minTimeMs) { - continue; - } - MetricEntity newEntity = metrics.getValue(); - if (resourceCount.containsKey(resourceMetrics.getKey())) { - MetricEntity oldEntity = resourceCount.get(resourceMetrics.getKey()); - oldEntity.addPassQps(newEntity.getPassQps()); - oldEntity.addRtAndSuccessQps(newEntity.getRt(), newEntity.getSuccessQps()); - oldEntity.addBlockQps(newEntity.getBlockQps()); - oldEntity.addExceptionQps(newEntity.getExceptionQps()); - oldEntity.addCount(1); - } - else { - resourceCount.put(resourceMetrics.getKey(), MetricEntity.copyOf(newEntity)); + readWriteLock.readLock().lock(); + try { + for (Entry> resourceMetrics : resourceMap.entrySet()) { + for (Entry metrics : resourceMetrics.getValue().entrySet()) { + if (metrics.getKey() < minTimeMs) { + continue; + } + MetricEntity newEntity = metrics.getValue(); + if (resourceCount.containsKey(resourceMetrics.getKey())) { + MetricEntity oldEntity = resourceCount.get(resourceMetrics.getKey()); + oldEntity.addPassQps(newEntity.getPassQps()); + oldEntity.addRtAndSuccessQps(newEntity.getRt(), newEntity.getSuccessQps()); + oldEntity.addBlockQps(newEntity.getBlockQps()); + oldEntity.addExceptionQps(newEntity.getExceptionQps()); + oldEntity.addCount(1); + } + else { + resourceCount.put(resourceMetrics.getKey(), MetricEntity.copyOf(newEntity)); + } } } + // Order by last minute b_qps DESC. + return resourceCount.entrySet().stream().sorted((o1, o2) -> { + MetricEntity e1 = o1.getValue(); + MetricEntity e2 = o2.getValue(); + int t = e2.getBlockQps().compareTo(e1.getBlockQps()); + if (t != 0) { + return t; + } + return e2.getPassQps().compareTo(e1.getPassQps()); + }).map(Entry::getKey).collect(Collectors.toList()); + } + finally { + readWriteLock.readLock().unlock(); } - // Order by last minute b_qps DESC. - return resourceCount.entrySet().stream().sorted((o1, o2) -> { - MetricEntity e1 = o1.getValue(); - MetricEntity e2 = o2.getValue(); - int t = e2.getBlockQps().compareTo(e1.getBlockQps()); - if (t != 0) { - return t; - } - return e2.getPassQps().compareTo(e1.getPassQps()); - }).map(Entry::getKey).collect(Collectors.toList()); } } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/MetricsRepository.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/metric/MetricsRepository.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemAuthorityRuleStore.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/repository/rule/InMemParamFlowRuleStore.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRuleProvider.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRuleProvider.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRulePublisher.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/DynamicRulePublisher.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiProvider.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleApiPublisher.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignService.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignService.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterAssignServiceImpl.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterConfigService.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/service/ClusterConfigService.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/AsyncUtils.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/AsyncUtils.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/ClusterEntityUtils.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/ClusterEntityUtils.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/MachineUtils.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/MachineUtils.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/VersionUtils.java b/pigx-visual/pigx-sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/util/VersionUtils.java old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml b/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml index bace37e18..d85b338e5 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/resources/application.yml @@ -24,4 +24,4 @@ auth: sentinel: dashboard: - version: 1.7.1 \ No newline at end of file + version: @project.version@ \ No newline at end of file diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/README.md b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/README.md new file mode 100755 index 000000000..c88ea68c6 --- /dev/null +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/README.md @@ -0,0 +1,32 @@ +# Sentinel Dashboard Frontend + +## Env Requirement + +- Node.js > 6.x + +## Code Guide + +- [Code Style Guide for HTML/CSS](https://codeguide.bootcss.com/) +- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript/tree/es5-deprecated/es5) + +## Install Packages + +``` +npm install +``` + +## Start Development + +``` +npm start +``` + +## Build for production + +``` +npm run build +``` + +## Credit + +- [sb-admin-angular](https://github.com/start-angular/sb-admin-angular) \ No newline at end of file diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/README_zh.md b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/README_zh.md new file mode 100644 index 000000000..5daf33efb --- /dev/null +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/README_zh.md @@ -0,0 +1,32 @@ +# Sentinel Dashboard Frontend + +## 环境要求 + +- Node.js > 6.x + +## 编码规范 + +- HTML/CSS 遵循 [Bootstrap 编码规范](https://codeguide.bootcss.com/) +- JavaScript 遵循 [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript/tree/es5-deprecated/es5) 以及最新的 ES 6 标准 + +## 安装依赖 + +``` +npm i +``` + +## 开始本地开发 + +``` +npm start +``` + +## 构建前端资源 + +``` +npm run build +``` + +## Credit + +- [sb-admin-angular](https://github.com/start-angular/sb-admin-angular) \ No newline at end of file diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/authority.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/authority.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_assign_manage.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_assign_manage.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_server_list.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_server_list.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_server_manage.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_server_manage.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_server_monitor.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_server_monitor.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_token_client_list.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_app_token_client_list.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_single.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/cluster_single.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js index 8a05323e4..d2eac6da4 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade.js @@ -66,7 +66,9 @@ app.controller('DegradeCtl', ['$scope', '$stateParams', 'DegradeService', 'ngDia app: $scope.app, ip: mac[0], port: mac[1], - limitApp: 'default' + limitApp: 'default', + minRequestAmount: 5, + statIntervalMs: 1000, }; $scope.degradeRuleDialog = { title: '新增降级规则', @@ -95,7 +97,7 @@ app.controller('DegradeCtl', ['$scope', '$stateParams', 'DegradeService', 'ngDia function parseDegradeMode(grade) { switch (grade) { case 0: - return 'RT'; + return '慢调用比例'; case 1: return '异常比例'; case 2: @@ -137,7 +139,7 @@ app.controller('DegradeCtl', ['$scope', '$stateParams', 'DegradeService', 'ngDia getMachineRules(); confirmDialog.close(); } else { - alert('失败!'); + alert('失败:' + data.msg); } }); }; @@ -148,7 +150,7 @@ app.controller('DegradeCtl', ['$scope', '$stateParams', 'DegradeService', 'ngDia getMachineRules(); degradeRuleDialog.close(); } else { - alert('失败!'); + alert('失败:' + data.msg); } }); }; @@ -163,7 +165,7 @@ app.controller('DegradeCtl', ['$scope', '$stateParams', 'DegradeService', 'ngDia confirmDialog.close(); } } else { - alert('失败!'); + alert('失败:' + data.msg); } }); } diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/gateway/api.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/gateway/api.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/gateway/flow.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/gateway/flow.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/gateway/identity.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/gateway/identity.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/identity.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/identity.js index f8116be78..2a14eb1e9 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/identity.js +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/identity.js @@ -132,6 +132,8 @@ app.controller('IdentityCtl', ['$scope', '$stateParams', 'IdentityService', strategy: 0, resource: resource, limitApp: 'default', + minRequestAmount: 5, + statIntervalMs: 1000, app: $scope.app, ip: mac[0], port: mac[1] diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/login.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/login.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/param_flow.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/header/header.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/header/header.js index b10c672d2..4e6c8f2cf 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/header/header.js +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/directives/header/header.js @@ -27,7 +27,15 @@ angular.module('sentinelDashboardApp') } }); } else { - handleLogout($scope, JSON.parse($window.localStorage.getItem("session_sentinel_admin")).id) + try { + var id = JSON.parse($window.localStorage.getItem("session_sentinel_admin")).id; + handleLogout($scope, id); + } catch (e) { + // Historical version compatibility processing, fixes issue-1449 + // If error happens while parsing, remove item in localStorage and redirect to login page. + $window.localStorage.removeItem("session_sentinel_admin"); + $state.go('login'); + } } function handleLogout($scope, id) { diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/auth_service.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/auth_service.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/authority_service.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/authority_service.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/cluster_state_service.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/cluster_state_service.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degradeservice.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degrade_service.js similarity index 50% rename from pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degradeservice.js rename to pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degrade_service.js index 146d841d7..a242b22a4 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degradeservice.js +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degrade_service.js @@ -15,21 +15,10 @@ app.service('DegradeService', ['$http', function ($http) { }; this.newRule = function (rule) { - var param = { - id: rule.id, - resource: rule.resource, - limitApp: rule.limitApp, - count: rule.count, - timeWindow: rule.timeWindow, - grade: rule.grade, - app: rule.app, - ip: rule.ip, - port: rule.port - }; return $http({ - url: '/degrade/new.json', - params: param, - method: 'GET' + url: '/degrade/rule', + data: rule, + method: 'POST' }); }; @@ -41,24 +30,22 @@ app.service('DegradeService', ['$http', function ($http) { grade: rule.grade, count: rule.count, timeWindow: rule.timeWindow, + statIntervalMs: rule.statIntervalMs, + minRequestAmount: rule.minRequestAmount, + slowRatioThreshold: rule.slowRatioThreshold, }; return $http({ - url: '/degrade/save.json', - params: param, - method: 'GET' + url: '/degrade/rule/' + rule.id, + data: param, + method: 'PUT' }); }; this.deleteRule = function (rule) { - var param = { - id: rule.id, - app: rule.app - }; - return $http({ - url: '/degrade/delete.json', - params: param, - method: 'GET' - }); + return $http({ + url: '/degrade/rule/' + rule.id, + method: 'DELETE' + }); }; this.checkRuleValid = function (rule) { @@ -74,8 +61,20 @@ app.service('DegradeService', ['$http', function ($http) { alert('降级阈值不能为空或小于 0'); return false; } - if (rule.timeWindow === undefined || rule.timeWindow === '' || rule.timeWindow <= 0) { - alert('降级时间窗口必须大于 0'); + if (rule.timeWindow == undefined || rule.timeWindow === '' || rule.timeWindow <= 0) { + alert('熔断时长必须大于 0s'); + return false; + } + if (rule.minRequestAmount == undefined || rule.minRequestAmount <= 0) { + alert('最小请求数目需大于 0'); + return false; + } + if (rule.statIntervalMs == undefined || rule.statIntervalMs <= 0) { + alert('统计窗口时长需大于 0s'); + return false; + } + if (rule.statIntervalMs !== undefined && rule.statIntervalMs > 60 * 1000 * 2) { + alert('统计窗口时长不能超过 120 分钟'); return false; } // 异常比率类型. @@ -83,6 +82,16 @@ app.service('DegradeService', ['$http', function ($http) { alert('异常比率超出范围:[0.0 - 1.0]'); return false; } + if (rule.grade == 0) { + if (rule.slowRatioThreshold == undefined) { + alert('慢调用比率不能为空'); + return false; + } + if (rule.slowRatioThreshold < 0 || rule.slowRatioThreshold > 1) { + alert('慢调用比率超出范围:[0.0 - 1.0]'); + return false; + } + } return true; }; }]); diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/gateway/api_service.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/gateway/api_service.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/gateway/flow_service.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/gateway/flow_service.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/param_flow_service.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/param_flow_service.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/version_service.js b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/scripts/services/version_service.js old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/authority.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/authority.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster/client.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster/client.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster/server.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster/server.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_assign_manage.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_assign_manage.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_client_list.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_client_list.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_list.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_list.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_overview.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/cluster_app_server_overview.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/degrade.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/degrade.html index 1ed7458f6..c2b67528a 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/degrade.html +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/degrade.html @@ -33,21 +33,15 @@ 资源名 - - - - 降级模式 + 降级策略 阈值 - 时间窗口(s) + 熔断时长(s) - - - 操作 @@ -59,9 +53,9 @@ {{rule.resource}} - RT - 异常比例 - 异常数 + 慢调用比例 + 异常比例 + 异常数 {{rule.count}} diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/authority-rule-dialog.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/authority-rule-dialog.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/cluster/cluster-server-assign-dialog.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/cluster/cluster-server-assign-dialog.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/cluster/cluster-server-connection-detail-dialog.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/cluster/cluster-server-connection-detail-dialog.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html index 7dddbbb82..df241ec1b 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html @@ -22,30 +22,53 @@

- +
-  RT   -  异常比例   -  异常数 +  慢调用比例   +  异常比例   +  异常数
- - + + -
- - +
+ +
- -
- +
+ +
+ +
+ +
+ +
+
+ + s +
+
+ + +
+ +
+
+ +
diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html index f832ce3ec..e68fb6b4a 100755 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html @@ -78,7 +78,7 @@
-
+
@@ -103,7 +103,7 @@
-
+
@@ -130,7 +130,7 @@
-
+ diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/api-dialog.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/api-dialog.html old mode 100755 new mode 100644 diff --git a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html old mode 100755 new mode 100644 index 7dca16d71..ea744a711 --- a/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html +++ b/pigx-visual/pigx-sentinel-dashboard/src/main/webapp/resources/app/views/dialog/gateway/flow-rule-dialog.html @@ -70,7 +70,7 @@
-
+