Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
all constants with relative timestamp should be replaced by absolute …
Browse files Browse the repository at this point in the history
…timestamp
  • Loading branch information
studanshu committed Aug 17, 2018
1 parent a119c23 commit f6ae32b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public String getExpressionWithAbsoluteStartAndEndTimeStamps(NotificationContext
try {
String expression = "@" + context.getAlert().getExpression().replaceAll("[\\s\\t\\r\\n\\f]*", "");
String regexMatcherWithStartAndEnd = "(?i)\\-[0-9]+(d|m|h|s):\\-[0-9]+(d|m|h|s)";
String regexMatcherWithStartAndEndFill = "(?i)FILL\\(#\\-[0-9]+(d|h|m|s)#,#\\-[0-9]+(d|h|m|s)#";
String regexMatcherWithoutEnd = "(?i)\\@\\-[0-9]+(d|m|h|s)|\\(\\-[0-9]+(d|m|h|s)|:\\-[0-9]+(d|m|h|s)|,\\-[0-9]+(d|m|h|s)";
String regexMatcherWithConstants = "(?i)#\\-[0-9]+(d|h|m|s)";
String regexMatcherWithoutEnd = "(?i)\\@\\-[0-9]+(d|m|h|s)|\\(\\-[0-9]+(d|m|h|s)|,\\-[0-9]+(d|m|h|s)";
Long relativeTo = context.getAlertEnqueueTimestamp();

Matcher m = Pattern.compile(regexMatcherWithStartAndEnd).matcher(expression);
Expand All @@ -125,12 +125,11 @@ public String getExpressionWithAbsoluteStartAndEndTimeStamps(NotificationContext
}
}

m = Pattern.compile(regexMatcherWithStartAndEndFill).matcher(expression);
m = Pattern.compile(regexMatcherWithConstants).matcher(expression);
while (m.find()) {
for (String timeStr: m.group().substring(6,m.group().length()-1).split("#,#")) {
Long absoluteTime = MetricReader.getTime(relativeTo, timeStr);
expression = expression.replaceFirst(timeStr, "" + absoluteTime);
}
String timeStr = m.group();
Long absoluteTime = MetricReader.getTime(relativeTo, timeStr.substring(1));
expression = expression.replaceFirst(timeStr, ("" + timeStr.charAt(0)) + absoluteTime);
}

m = Pattern.compile(regexMatcherWithoutEnd).matcher(expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testAbsoluteTimeStampsInExpression() {
"RANGE(1417455600000:1418319600000:scope:metric[ABCD]:avg:1d-max)",
"DOWNSAMPLE(DOWNSAMPLE(GROUPBYTAG(CULL_BELOW(1418312700000:1418318700000:iot-provisioning-server.PRD.SP2.-:health.status{device=provisioning-warden-*}:avg:1m-max,#1#,#value#),#DeploymentName#,#MAX#),#1m-max#),#10m-count#)",
"DOWNSAMPLE(CULL_BELOW(DERIVATIVE(1418312700000:1418318700000:iot-container.PRD.NONE.-:iot.flows.state.load.errors_count{flowsnakeEnvironmentName=iot-prd-stmfa-00ds70000000mqy}:zimsum:1m-sum),#0#,#value#),#10m-sum#)",
"DOWNSAMPLE(1418146800000:1418319600000:alerts.scheduled:alert-1429851:zimsum,#5m-sum#,#-2d#,#-0m#,#0#)"
"DOWNSAMPLE(1418146800000:1418319600000:alerts.scheduled:alert-1429851:zimsum,#5m-sum#,#1418146800000#,#1418319600000#,#0#)"
));

UserService userService = system.getServiceFactory().getUserService();
Expand Down

0 comments on commit f6ae32b

Please sign in to comment.