From 62487998465bf14b21ee93f1f4f433d43008b8d3 Mon Sep 17 00:00:00 2001 From: xiaofeiwang <526086597@qq.com> Date: Thu, 1 Feb 2024 20:45:12 +0800 Subject: [PATCH] dashboard support regex match (#3305) --- .../entity/rule/AbstractRuleEntity.java | 14 ++++++++++++++ .../entity/rule/AuthorityRuleEntity.java | 1 + .../datasource/entity/rule/DegradeRuleEntity.java | 14 ++++++++++++++ .../datasource/entity/rule/FlowRuleEntity.java | 15 +++++++++++++++ .../entity/rule/ParamFlowRuleEntity.java | 1 + .../app/views/dialog/authority-rule-dialog.html | 9 ++++++++- .../app/views/dialog/degrade-rule-dialog.html | 9 ++++++++- .../app/views/dialog/flow-rule-dialog.html | 9 ++++++++- .../app/views/dialog/param-flow-rule-dialog.html | 9 ++++++++- 9 files changed, 77 insertions(+), 4 deletions(-) diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java index 6f60647dc4..c638e9fcdd 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java @@ -34,6 +34,11 @@ public abstract class AbstractRuleEntity implements Rule protected T rule; + /** + * Whether to match resource names according to regular rules + */ + private boolean regex = false; + private Date gmtCreate; private Date gmtModified; @@ -86,6 +91,15 @@ public AbstractRuleEntity setRule(T rule) { return this; } + public boolean isRegex() { + return regex; + } + + public AbstractRuleEntity setRegex(boolean regex) { + this.regex = regex; + return this; + } + @Override public Date getGmtCreate() { return gmtCreate; diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java index a085d898b8..ac29850f40 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java @@ -39,6 +39,7 @@ public static AuthorityRuleEntity fromAuthorityRule(String app, String ip, Integ entity.setApp(app); entity.setIp(ip); entity.setPort(port); + entity.setRegex(rule.isRegex()); return entity; } diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java index 4fd8b719a5..1e1ec99548 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java @@ -38,6 +38,10 @@ public class DegradeRuleEntity implements RuleEntity { private Integer minRequestAmount; private Double slowRatioThreshold; private Integer statIntervalMs; + /** + * Whether to match resource names according to regular rules + */ + private boolean regex = false; private Date gmtCreate; private Date gmtModified; @@ -55,6 +59,7 @@ public static DegradeRuleEntity fromDegradeRule(String app, String ip, Integer p entity.setMinRequestAmount(rule.getMinRequestAmount()); entity.setSlowRatioThreshold(rule.getSlowRatioThreshold()); entity.setStatIntervalMs(rule.getStatIntervalMs()); + entity.setRegex(rule.isRegex()); return entity; } @@ -162,6 +167,14 @@ public DegradeRuleEntity setStatIntervalMs(Integer statIntervalMs) { return this; } + public boolean isRegex() { + return regex; + } + + public void setRegex(boolean regex) { + this.regex = regex; + } + @Override public Date getGmtCreate() { return gmtCreate; @@ -197,6 +210,7 @@ public DegradeRule toRule() { rule.setStatIntervalMs(statIntervalMs); } + rule.setRegex(regex); return rule; } } diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java index a076bd4291..4f9ccd6ba5 100755 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java @@ -57,6 +57,11 @@ public class FlowRuleEntity implements RuleEntity { */ private ClusterFlowConfig clusterConfig; + /** + * Whether to match resource names according to regular rules + */ + private boolean regex = false; + private Date gmtCreate; private Date gmtModified; @@ -76,6 +81,7 @@ public static FlowRuleEntity fromFlowRule(String app, String ip, Integer port, F entity.setMaxQueueingTimeMs(rule.getMaxQueueingTimeMs()); entity.setClusterMode(rule.isClusterMode()); entity.setClusterConfig(rule.getClusterConfig()); + entity.setRegex(rule.isRegex()); return entity; } @@ -206,6 +212,14 @@ public FlowRuleEntity setClusterConfig(ClusterFlowConfig clusterConfig) { return this; } + public boolean isRegex() { + return regex; + } + + public void setRegex(boolean regex) { + this.regex = regex; + } + @Override public Date getGmtCreate() { return gmtCreate; @@ -243,6 +257,7 @@ public FlowRule toRule() { } flowRule.setClusterMode(clusterMode); flowRule.setClusterConfig(clusterConfig); + flowRule.setRegex(regex); return flowRule; } diff --git a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java index b1c10d97bb..e0734ff77a 100644 --- a/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java +++ b/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java @@ -43,6 +43,7 @@ public static ParamFlowRuleEntity fromParamFlowRule(String app, String ip, Integ entity.setApp(app); entity.setIp(ip); entity.setPort(port); + entity.setRegex(rule.isRegex()); return entity; } diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/authority-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/authority-rule-dialog.html index bd69085fa4..aafc8ee714 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/authority-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/authority-rule-dialog.html @@ -6,12 +6,19 @@
-
+
+ +
+ +
diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html index b8fae0c3fd..a013762e9e 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html @@ -6,12 +6,19 @@
-
+
+ +
+ +
diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html index 957d2ce2b0..93e2458ea9 100755 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html @@ -6,12 +6,19 @@
-
+
+ +
+ +
diff --git a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/param-flow-rule-dialog.html b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/param-flow-rule-dialog.html index 02f00b0891..d3c16f9b75 100644 --- a/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/param-flow-rule-dialog.html +++ b/sentinel-dashboard/src/main/webapp/resources/app/views/dialog/param-flow-rule-dialog.html @@ -6,10 +6,17 @@
-
+
+ +
+ +