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

Commit

Permalink
Merge pull request #884 from studanshu/converttoabsolutetime
Browse files Browse the repository at this point in the history
Bug fix for fill transform absolute timestamping
  • Loading branch information
sundeepsf committed Aug 17, 2018
2 parents f048b75 + f6ae32b commit e22332e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 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)#\\-[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)|#\\-[0-9]+(d|h|m|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(1,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 All @@ -143,6 +142,7 @@ public String getExpressionWithAbsoluteStartAndEndTimeStamps(NotificationContext
} catch (Exception ex) {
_logger.error("Exception occurred while converting relative time within the expression to absolute time.", ex.getMessage());
}

return absoluteExpression;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ public void testAbsoluteTimeStampsInExpression() {
"LIMIT( -21d:-1d:scope:metricA:avg:4h-avg, -1d:scope:metricB:avg:4h-avg,#1#)",
"RANGE(-10d:scope:metric[ABCD]:avg:1d-max)",
"DOWNSAMPLE(DOWNSAMPLE(GROUPBYTAG(CULL_BELOW(-115m:-15m: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(-115m:-15m:iot-container.PRD.NONE.-:iot.flows.state.load.errors_count{flowsnakeEnvironmentName=iot-prd-stmfa-00ds70000000mqy}:zimsum:1m-sum), #0#, #value#), #10m-sum#)"
"DOWNSAMPLE(CULL_BELOW(DERIVATIVE(-115m:-15m:iot-container.PRD.NONE.-:iot.flows.state.load.errors_count{flowsnakeEnvironmentName=iot-prd-stmfa-00ds70000000mqy}:zimsum:1m-sum), #0#, #value#), #10m-sum#)",
"DOWNSAMPLE(-2d:alerts.scheduled:alert-1429851:zimsum, #5m-sum#,#-2d#, #-0m#, #0#)"
));

ArrayList<String> expectedOutput = new ArrayList<String> (Arrays.asList(
Expand All @@ -161,7 +162,8 @@ public void testAbsoluteTimeStampsInExpression() {
"LIMIT(1416505200000:1418233200000:scope:metricA:avg:4h-avg,1418233200000:1418319600000:scope:metricB:avg:4h-avg,#1#)",
"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(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#,#1418146800000#,#1418319600000#,#0#)"
));

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

0 comments on commit e22332e

Please sign in to comment.