From 03f5ab3e84142c657f653e5cf3250cd9af9fbce3 Mon Sep 17 00:00:00 2001 From: wangjx <1609724385@qq.com> Date: Sat, 26 Jun 2021 23:35:14 +0800 Subject: [PATCH] =?UTF-8?q?nacos=E6=8C=81=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/webapp/resources/app/scripts/app.js | 2 +- .../app/scripts/controllers/degrade_v2.js | 2 +- .../scripts/services/degrade_service_v2.js | 97 ++++++++++++++++++ .../resources/app/views/degrade_v2.html | 98 +++++++++++++++++++ 4 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degrade_service_v2.js create mode 100644 sentinel-dashboard/src/main/webapp/resources/app/views/degrade_v2.html diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/app.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/app.js index 518ab235..11f9e302 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/app.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/app.js @@ -263,7 +263,7 @@ angular return $ocLazyLoad.load({ name: 'sentinelDashboardApp', files: [ - 'app/scripts/controllers/degrade.js', + 'app/scripts/controllers/degrade_v2.js', ] }); }] diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade_v2.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade_v2.js index d024d644..77ee3a2c 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade_v2.js +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/degrade_v2.js @@ -1,6 +1,6 @@ var app = angular.module('sentinelDashboardApp'); -app.controller('DegradeControllerV2', ['$scope', '$stateParams', 'DegradeService', 'ngDialog', 'MachineService', +app.controller('DegradeControllerV2', ['$scope', '$stateParams', 'DegradeServiceV2', 'ngDialog', 'MachineService', function ($scope, $stateParams, DegradeService, ngDialog, MachineService) { //初始化 $scope.app = $stateParams.app; diff --git a/sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degrade_service_v2.js b/sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degrade_service_v2.js new file mode 100644 index 00000000..12768988 --- /dev/null +++ b/sentinel-dashboard/src/main/webapp/resources/app/scripts/services/degrade_service_v2.js @@ -0,0 +1,97 @@ +var app = angular.module('sentinelDashboardApp'); + +app.service('DegradeServiceV2', ['$http', function ($http) { + this.queryMachineRules = function (app, ip, port) { + var param = { + app: app, + ip: ip, + port: port + }; + return $http({ + url: '/v2/degrade/rules.json', + params: param, + method: 'GET' + }); + }; + + this.newRule = function (rule) { + return $http({ + url: '/v2/degrade/rule', + data: rule, + method: 'POST' + }); + }; + + this.saveRule = function (rule) { + var param = { + id: rule.id, + resource: rule.resource, + limitApp: rule.limitApp, + grade: rule.grade, + count: rule.count, + timeWindow: rule.timeWindow, + statIntervalMs: rule.statIntervalMs, + minRequestAmount: rule.minRequestAmount, + slowRatioThreshold: rule.slowRatioThreshold, + }; + return $http({ + url: '/v2/degrade/rule/' + rule.id, + data: param, + method: 'PUT' + }); + }; + + this.deleteRule = function (rule) { + return $http({ + url: '/v2/degrade/rule/' + rule.id, + method: 'DELETE' + }); + }; + + this.checkRuleValid = function (rule) { + if (rule.resource === undefined || rule.resource === '') { + alert('资源名称不能为空'); + return false; + } + if (rule.grade === undefined || rule.grade < 0) { + alert('未知的降级策略'); + return false; + } + if (rule.count === undefined || rule.count === '' || rule.count < 0) { + alert('降级阈值不能为空或小于 0'); + return false; + } + 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; + } + // 异常比率类型. + if (rule.grade == 1 && rule.count > 1) { + 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/sentinel-dashboard/src/main/webapp/resources/app/views/degrade_v2.html b/sentinel-dashboard/src/main/webapp/resources/app/views/degrade_v2.html new file mode 100644 index 00000000..c2b67528 --- /dev/null +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/degrade_v2.html @@ -0,0 +1,98 @@ +
+
+ {{app}} +
+
+ +
+
+ +
+ +
+
+
+
+
+ 降级规则 + + + +
+ +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + +
+ 资源名 + + 降级策略 + + 阈值 + + 熔断时长(s) + + 操作 +
{{rule.resource}} + 慢调用比例 + 异常比例 + 异常数 + + {{rule.count}} + + {{rule.timeWindow}}s + + + +
+
+ + + +
+ +
+ +
+ +
+