Skip to content

Commit 6248799

Browse files
authored
dashboard support regex match (#3305)
1 parent a524ab3 commit 6248799

File tree

9 files changed

+77
-4
lines changed

9 files changed

+77
-4
lines changed

sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AbstractRuleEntity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public abstract class AbstractRuleEntity<T extends AbstractRule> implements Rule
3434

3535
protected T rule;
3636

37+
/**
38+
* Whether to match resource names according to regular rules
39+
*/
40+
private boolean regex = false;
41+
3742
private Date gmtCreate;
3843
private Date gmtModified;
3944

@@ -86,6 +91,15 @@ public AbstractRuleEntity<T> setRule(T rule) {
8691
return this;
8792
}
8893

94+
public boolean isRegex() {
95+
return regex;
96+
}
97+
98+
public AbstractRuleEntity<T> setRegex(boolean regex) {
99+
this.regex = regex;
100+
return this;
101+
}
102+
89103
@Override
90104
public Date getGmtCreate() {
91105
return gmtCreate;

sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/AuthorityRuleEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public static AuthorityRuleEntity fromAuthorityRule(String app, String ip, Integ
3939
entity.setApp(app);
4040
entity.setIp(ip);
4141
entity.setPort(port);
42+
entity.setRegex(rule.isRegex());
4243
return entity;
4344
}
4445

sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/DegradeRuleEntity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public class DegradeRuleEntity implements RuleEntity {
3838
private Integer minRequestAmount;
3939
private Double slowRatioThreshold;
4040
private Integer statIntervalMs;
41+
/**
42+
* Whether to match resource names according to regular rules
43+
*/
44+
private boolean regex = false;
4145

4246
private Date gmtCreate;
4347
private Date gmtModified;
@@ -55,6 +59,7 @@ public static DegradeRuleEntity fromDegradeRule(String app, String ip, Integer p
5559
entity.setMinRequestAmount(rule.getMinRequestAmount());
5660
entity.setSlowRatioThreshold(rule.getSlowRatioThreshold());
5761
entity.setStatIntervalMs(rule.getStatIntervalMs());
62+
entity.setRegex(rule.isRegex());
5863
return entity;
5964
}
6065

@@ -162,6 +167,14 @@ public DegradeRuleEntity setStatIntervalMs(Integer statIntervalMs) {
162167
return this;
163168
}
164169

170+
public boolean isRegex() {
171+
return regex;
172+
}
173+
174+
public void setRegex(boolean regex) {
175+
this.regex = regex;
176+
}
177+
165178
@Override
166179
public Date getGmtCreate() {
167180
return gmtCreate;
@@ -197,6 +210,7 @@ public DegradeRule toRule() {
197210
rule.setStatIntervalMs(statIntervalMs);
198211
}
199212

213+
rule.setRegex(regex);
200214
return rule;
201215
}
202216
}

sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/FlowRuleEntity.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public class FlowRuleEntity implements RuleEntity {
5757
*/
5858
private ClusterFlowConfig clusterConfig;
5959

60+
/**
61+
* Whether to match resource names according to regular rules
62+
*/
63+
private boolean regex = false;
64+
6065
private Date gmtCreate;
6166
private Date gmtModified;
6267

@@ -76,6 +81,7 @@ public static FlowRuleEntity fromFlowRule(String app, String ip, Integer port, F
7681
entity.setMaxQueueingTimeMs(rule.getMaxQueueingTimeMs());
7782
entity.setClusterMode(rule.isClusterMode());
7883
entity.setClusterConfig(rule.getClusterConfig());
84+
entity.setRegex(rule.isRegex());
7985
return entity;
8086
}
8187

@@ -206,6 +212,14 @@ public FlowRuleEntity setClusterConfig(ClusterFlowConfig clusterConfig) {
206212
return this;
207213
}
208214

215+
public boolean isRegex() {
216+
return regex;
217+
}
218+
219+
public void setRegex(boolean regex) {
220+
this.regex = regex;
221+
}
222+
209223
@Override
210224
public Date getGmtCreate() {
211225
return gmtCreate;
@@ -243,6 +257,7 @@ public FlowRule toRule() {
243257
}
244258
flowRule.setClusterMode(clusterMode);
245259
flowRule.setClusterConfig(clusterConfig);
260+
flowRule.setRegex(regex);
246261
return flowRule;
247262
}
248263

sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/ParamFlowRuleEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static ParamFlowRuleEntity fromParamFlowRule(String app, String ip, Integ
4343
entity.setApp(app);
4444
entity.setIp(ip);
4545
entity.setPort(port);
46+
entity.setRegex(rule.isRegex());
4647
return entity;
4748
}
4849

sentinel-dashboard/src/main/webapp/resources/app/views/dialog/authority-rule-dialog.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
<form role="form" class="form-horizontal">
77
<div class="form-group">
88
<label class="col-sm-2 control-label">资源名</label>
9-
<div class="col-sm-9">
9+
<div class="col-sm-6">
1010
<input type="text" ng-if="authorityRuleDialog.type == 'edit'" class="form-control" placeholder="资源名" ng-model='currentRule.rule.resource'
1111
disabled="" />
1212
<input type="text" ng-if="authorityRuleDialog.type == 'add'" class="form-control highlight-border" placeholder="资源名称" ng-model='currentRule.rule.resource'
1313
/>
1414
</div>
15+
<label class="col-sm-2 control-label">是否正则</label>
16+
<div class="col-sm-2">
17+
<label class="checkbox-inline">
18+
<input type="checkbox" ng-if="authorityRuleDialog.type == 'add'" name="regex" ng-model="currentRule.rule.regex">
19+
<input type="checkbox" ng-if="authorityRuleDialog.type == 'edit'" name="regex" ng-model="currentRule.rule.regex" disabled="">
20+
</label>
21+
</div>
1522
</div>
1623

1724
<div class="form-group">

sentinel-dashboard/src/main/webapp/resources/app/views/dialog/degrade-rule-dialog.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
<form role="form" class="form-horizontal">
77
<div class="form-group">
88
<label class="col-sm-2 control-label">资源名</label>
9-
<div class="col-sm-9">
9+
<div class="col-sm-6">
1010
<input type="text" ng-if="degradeRuleDialog.type == 'edit'" class="form-control" placeholder="资源名" ng-model='currentRule.resource'
1111
disabled="" />
1212
<input type="text" ng-if="degradeRuleDialog.type == 'add'" class="form-control highlight-border" placeholder="资源名" ng-model='currentRule.resource'
1313
/>
1414
</div>
15+
<label class="col-sm-2 control-label">是否正则</label>
16+
<div class="col-sm-2">
17+
<label class="checkbox-inline">
18+
<input type="checkbox" ng-if="degradeRuleDialog.type == 'add'" name="regex" ng-model="currentRule.regex">
19+
<input type="checkbox" ng-if="degradeRuleDialog.type == 'edit'" name="regex" ng-model="currentRule.regex" disabled="">
20+
</label>
21+
</div>
1522
</div>
1623

1724
<!--<div class="form-group">-->

sentinel-dashboard/src/main/webapp/resources/app/views/dialog/flow-rule-dialog.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
<form role="form" class="form-horizontal">
77
<div class="form-group">
88
<label class="col-sm-2 control-label">资源名</label>
9-
<div class="col-sm-9">
9+
<div class="col-sm-6">
1010
<input type="text" ng-if="flowRuleDialog.type == 'edit'" class="form-control" placeholder="资源名" ng-model='currentRule.resource'
1111
disabled="" />
1212
<input type="text" ng-if="flowRuleDialog.type == 'add'" class="form-control highlight-border" placeholder="资源名" ng-model='currentRule.resource'
1313
/>
1414
</div>
15+
<label class="col-sm-2 control-label">是否正则</label>
16+
<div class="col-sm-2">
17+
<label class="checkbox-inline">
18+
<input type="checkbox" ng-if="flowRuleDialog.type == 'add'" name="regex" ng-model="currentRule.regex">
19+
<input type="checkbox" ng-if="flowRuleDialog.type == 'edit'" name="regex" ng-model="currentRule.regex" disabled="">
20+
</label>
21+
</div>
1522
</div>
1623

1724
<div class="form-group">

sentinel-dashboard/src/main/webapp/resources/app/views/dialog/param-flow-rule-dialog.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
<form role="form" class="form-horizontal">
77
<div class="form-group">
88
<label class="col-sm-2 control-label">资源名</label>
9-
<div class="col-sm-9">
9+
<div class="col-sm-6">
1010
<input type="text" ng-if="paramFlowRuleDialog.type == 'edit'" class="form-control" placeholder="资源名" ng-model='currentRule.rule.resource' disabled="" />
1111
<input type="text" ng-if="paramFlowRuleDialog.type == 'add'" class="form-control highlight-border" placeholder="资源名" ng-model='currentRule.rule.resource' required />
1212
</div>
13+
<label class="col-sm-2 control-label">是否正则</label>
14+
<div class="col-sm-2">
15+
<label class="checkbox-inline">
16+
<input type="checkbox" ng-if="paramFlowRuleDialog.type == 'add'" name="regex" ng-model="currentRule.rule.regex">
17+
<input type="checkbox" ng-if="paramFlowRuleDialog.type == 'edit'" name="regex" ng-model="currentRule.rule.regex" disabled="">
18+
</label>
19+
</div>
1320
</div>
1421

1522
<div class="form-group">

0 commit comments

Comments
 (0)