-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrules.drl
39 lines (33 loc) · 1.26 KB
/
rules.drl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import io.github.hephaestusmetrics.model.metrics.Metric
import java.util.List
import org.k8loud.executor.actions.openstack.IpThrottleAction
global org.k8loud.executor.drools.UsableServices usableServices;
global org.k8loud.executor.drools.CronChecker cronChecker;
dialect "mvel"
rule "throttling-rule"
dialect "mvel"
when
test1 : Metric(
queryTag == "demo-app-last-minute-rq-count-per-origin",
origin : labels["origin"],
sum : value
)
eval(sum > 90 && cronChecker.checkPatternForSession("0 0/1 * ? * * *"))
then
System.out.println("Processing 'throttling-rule'...");
String[] ipParts = origin.split("\\.");
remoteIpPrefix = ipParts[0] + "." + ipParts[1] + "." + ipParts[2] + "." + "0/24";
IpThrottleAction.builder()
.region("RegionOne")
.serverId("c2f615ca-9f6a-407a-a32c-dbdb64109fa4")
.ethertype("IPv4")
.remoteIpPrefix(remoteIpPrefix)
.protocol("TCP")
.portRangeMin(80)
.portRangeMax(80)
.secDuration(1000)
.openstackService(usableServices.getOpenstackService())
.build()
.execute();
System.out.println("...Processed 'throttling-rule'");
end