Merge branch 'master' into qualified-spring-mvc-endpoints
This commit is contained in:
commit
9a1518a652
|
|
@ -49,7 +49,7 @@ BOOL_LITERAL: 'true'
|
|||
| 'false'
|
||||
;
|
||||
|
||||
INT_LITERAL : Digits+;
|
||||
NUMBER_LITERAL : Digits+;
|
||||
|
||||
CHAR_LITERAL: '\'' (~['\\\r\n] | EscapeSequence) '\'';
|
||||
|
||||
|
|
@ -111,4 +111,8 @@ COMMA: ',';
|
|||
SEMI: ';';
|
||||
EQUAL: '=';
|
||||
DUALEQUALS: '==';
|
||||
ALL: '*';
|
||||
ALL: '*';
|
||||
GREATER: '>';
|
||||
LESS: '<';
|
||||
GREATER_EQUAL: '>=';
|
||||
LESS_EQUAL: '<=';
|
||||
|
|
@ -74,11 +74,11 @@ funcParamExpression
|
|||
;
|
||||
|
||||
literalExpression
|
||||
: BOOL_LITERAL | INT_LITERAL
|
||||
: BOOL_LITERAL | NUMBER_LITERAL
|
||||
;
|
||||
|
||||
expression
|
||||
: booleanMatch | stringMatch
|
||||
: booleanMatch | stringMatch | greaterMatch | lessMatch | greaterEqualMatch | lessEqualMatch
|
||||
;
|
||||
|
||||
booleanMatch
|
||||
|
|
@ -89,6 +89,22 @@ stringMatch
|
|||
: conditionAttribute DUALEQUALS (stringConditionValue | enumConditionValue)
|
||||
;
|
||||
|
||||
greaterMatch
|
||||
: conditionAttribute GREATER numberConditionValue
|
||||
;
|
||||
|
||||
lessMatch
|
||||
: conditionAttribute LESS numberConditionValue
|
||||
;
|
||||
|
||||
greaterEqualMatch
|
||||
: conditionAttribute GREATER_EQUAL numberConditionValue
|
||||
;
|
||||
|
||||
lessEqualMatch
|
||||
: conditionAttribute LESS_EQUAL numberConditionValue
|
||||
;
|
||||
|
||||
conditionAttribute
|
||||
: IDENTIFIER
|
||||
;
|
||||
|
|
@ -103,4 +119,8 @@ stringConditionValue
|
|||
|
||||
enumConditionValue
|
||||
: IDENTIFIER DOT IDENTIFIER
|
||||
;
|
||||
|
||||
numberConditionValue
|
||||
: NUMBER_LITERAL
|
||||
;
|
||||
|
|
@ -51,6 +51,26 @@ public class DeepAnalysis {
|
|||
filterExpression.setLeft("source." + ClassMethodUtil.toGetMethod(expression.getAttribute()) + "()");
|
||||
filterExpression.setRight(expression.getValue());
|
||||
result.addFilterExpressions(filterExpression);
|
||||
} else if ("greaterMatch".equals(expression.getExpressionType())) {
|
||||
filterExpression.setExpressionObject("GreaterMatch");
|
||||
filterExpression.setLeft("source." + ClassMethodUtil.toGetMethod(expression.getAttribute()) + "()");
|
||||
filterExpression.setRight(expression.getValue());
|
||||
result.addFilterExpressions(filterExpression);
|
||||
} else if ("lessMatch".equals(expression.getExpressionType())) {
|
||||
filterExpression.setExpressionObject("LessMatch");
|
||||
filterExpression.setLeft("source." + ClassMethodUtil.toGetMethod(expression.getAttribute()) + "()");
|
||||
filterExpression.setRight(expression.getValue());
|
||||
result.addFilterExpressions(filterExpression);
|
||||
} else if ("greaterEqualMatch".equals(expression.getExpressionType())) {
|
||||
filterExpression.setExpressionObject("GreaterEqualMatch");
|
||||
filterExpression.setLeft("source." + ClassMethodUtil.toGetMethod(expression.getAttribute()) + "()");
|
||||
filterExpression.setRight(expression.getValue());
|
||||
result.addFilterExpressions(filterExpression);
|
||||
} else if ("lessEqualMatch".equals(expression.getExpressionType())) {
|
||||
filterExpression.setExpressionObject("LessEqualMatch");
|
||||
filterExpression.setLeft("source." + ClassMethodUtil.toGetMethod(expression.getAttribute()) + "()");
|
||||
filterExpression.setRight(expression.getValue());
|
||||
result.addFilterExpressions(filterExpression);
|
||||
} else {
|
||||
throw new IllegalArgumentException("filter expression [" + expression.getExpressionType() + "] not found");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,22 @@ public class OALListener extends OALParserBaseListener {
|
|||
conditionExpression.setExpressionType("stringMatch");
|
||||
}
|
||||
|
||||
@Override public void enterGreaterMatch(OALParser.GreaterMatchContext ctx) {
|
||||
conditionExpression.setExpressionType("greaterMatch");
|
||||
}
|
||||
|
||||
@Override public void enterGreaterEqualMatch(OALParser.GreaterEqualMatchContext ctx) {
|
||||
conditionExpression.setExpressionType("greaterEqualMatch");
|
||||
}
|
||||
|
||||
@Override public void enterLessMatch(OALParser.LessMatchContext ctx) {
|
||||
conditionExpression.setExpressionType("lessMatch");
|
||||
}
|
||||
|
||||
@Override public void enterLessEqualMatch(OALParser.LessEqualMatchContext ctx) {
|
||||
conditionExpression.setExpressionType("lessEqualMatch");
|
||||
}
|
||||
|
||||
@Override public void enterBooleanConditionValue(OALParser.BooleanConditionValueContext ctx) {
|
||||
conditionExpression.setValue(ctx.getText());
|
||||
}
|
||||
|
|
@ -113,6 +129,10 @@ public class OALListener extends OALParserBaseListener {
|
|||
conditionExpression.setValue(ctx.getText());
|
||||
}
|
||||
|
||||
@Override public void enterNumberConditionValue(OALParser.NumberConditionValueContext ctx) {
|
||||
conditionExpression.setValue(ctx.getText());
|
||||
}
|
||||
|
||||
/////////////
|
||||
// Expression end.
|
||||
////////////
|
||||
|
|
|
|||
|
|
@ -49,9 +49,15 @@ public class ${source}Dispatcher implements SourceDispatcher<${source}> {
|
|||
|
||||
<#if indicator.filterExpressions??>
|
||||
<#list indicator.filterExpressions as filterExpression>
|
||||
<#if filterExpression.expressionObject == "GreaterMatch" || filterExpression.expressionObject == "LessMatch" || filterExpression.expressionObject == "GreaterEqualMatch" || filterExpression.expressionObject == "LessEqualMatch">
|
||||
if (!new ${filterExpression.expressionObject}().match(${filterExpression.left}, ${filterExpression.right})) {
|
||||
return;
|
||||
}
|
||||
<#else>
|
||||
if (!new ${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match()) {
|
||||
return;
|
||||
}
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
|
|
|
|||
|
|
@ -46,11 +46,17 @@ public class FileGeneratorTest {
|
|||
result.setAggregationFunctionName("avg");
|
||||
result.setIndicatorClassName("LongAvgIndicator");
|
||||
|
||||
FilterExpression expression = new FilterExpression();
|
||||
expression.setExpressionObject("EqualMatch");
|
||||
expression.setLeft("source.getName()");
|
||||
expression.setRight("\"/service/prod/save\"");
|
||||
result.addFilterExpressions(expression);
|
||||
FilterExpression equalExpression = new FilterExpression();
|
||||
equalExpression.setExpressionObject("EqualMatch");
|
||||
equalExpression.setLeft("source.getName()");
|
||||
equalExpression.setRight("\"/service/prod/save\"");
|
||||
result.addFilterExpressions(equalExpression);
|
||||
|
||||
FilterExpression greaterExpression = new FilterExpression();
|
||||
greaterExpression.setExpressionObject("GreaterMatch");
|
||||
greaterExpression.setLeft("source.getLatency()");
|
||||
greaterExpression.setRight("1000");
|
||||
result.addFilterExpressions(greaterExpression);
|
||||
|
||||
EntryMethod method = new EntryMethod();
|
||||
method.setMethodName("combine");
|
||||
|
|
@ -96,7 +102,7 @@ public class FileGeneratorTest {
|
|||
fileGenerator.generateDispatcher(result, writer);
|
||||
Assert.assertEquals(readExpectedFile("ServiceDispatcherExpected.java"), writer.toString());
|
||||
|
||||
//fileGenerator.generateServiceDispatcher(new OutputStreamWriter(System.out));
|
||||
// fileGenerator.generateDispatcher(result, new OutputStreamWriter(System.out));
|
||||
}
|
||||
|
||||
private String readExpectedFile(String filename) throws IOException {
|
||||
|
|
|
|||
|
|
@ -112,4 +112,59 @@ public class ScriptParserTest {
|
|||
Assert.assertEquals("\"/product/abc\"", stringMatchExp.getValue());
|
||||
Assert.assertEquals("stringMatch", stringMatchExp.getExpressionType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse4() throws IOException {
|
||||
ScriptParser parser = ScriptParser.createFromScriptText(
|
||||
"service_response_s1_summary = from(Service.latency).filter(latency > 1000).sum();" + "\n" +
|
||||
"service_response_s2_summary = from(Service.latency).filter(latency < 2000).sum();" + "\n" +
|
||||
"service_response_s3_summary = from(Service.latency).filter(latency >= 3000).sum();" + "\n" +
|
||||
"service_response_s4_summary = from(Service.latency).filter(latency <= 4000).sum();"
|
||||
);
|
||||
List<AnalysisResult> results = parser.parse();
|
||||
|
||||
AnalysisResult responseSummary = results.get(0);
|
||||
Assert.assertEquals("ServiceResponseS1Summary", responseSummary.getMetricName());
|
||||
Assert.assertEquals("Service", responseSummary.getSourceName());
|
||||
Assert.assertEquals("latency", responseSummary.getSourceAttribute());
|
||||
Assert.assertEquals("sum", responseSummary.getAggregationFunctionName());
|
||||
List<ConditionExpression> expressions = responseSummary.getFilterExpressionsParserResult();
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
ConditionExpression booleanMatchExp = expressions.get(0);
|
||||
Assert.assertEquals("latency", booleanMatchExp.getAttribute());
|
||||
Assert.assertEquals("1000", booleanMatchExp.getValue());
|
||||
Assert.assertEquals("greaterMatch", booleanMatchExp.getExpressionType());
|
||||
|
||||
responseSummary = results.get(1);
|
||||
expressions = responseSummary.getFilterExpressionsParserResult();
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
booleanMatchExp = expressions.get(0);
|
||||
Assert.assertEquals("latency", booleanMatchExp.getAttribute());
|
||||
Assert.assertEquals("2000", booleanMatchExp.getValue());
|
||||
Assert.assertEquals("lessMatch", booleanMatchExp.getExpressionType());
|
||||
|
||||
responseSummary = results.get(2);
|
||||
expressions = responseSummary.getFilterExpressionsParserResult();
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
booleanMatchExp = expressions.get(0);
|
||||
Assert.assertEquals("latency", booleanMatchExp.getAttribute());
|
||||
Assert.assertEquals("3000", booleanMatchExp.getValue());
|
||||
Assert.assertEquals("greaterEqualMatch", booleanMatchExp.getExpressionType());
|
||||
|
||||
responseSummary = results.get(3);
|
||||
expressions = responseSummary.getFilterExpressionsParserResult();
|
||||
|
||||
Assert.assertEquals(1, expressions.size());
|
||||
|
||||
booleanMatchExp = expressions.get(0);
|
||||
Assert.assertEquals("latency", booleanMatchExp.getAttribute());
|
||||
Assert.assertEquals("4000", booleanMatchExp.getValue());
|
||||
Assert.assertEquals("lessEqualMatch", booleanMatchExp.getExpressionType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ public class ServiceDispatcher implements SourceDispatcher<Service> {
|
|||
if (!new EqualMatch().setLeft(source.getName()).setRight("/service/prod/save").match()) {
|
||||
return;
|
||||
}
|
||||
if (!new GreaterMatch().match(source.getLatency(), 1000)) {
|
||||
return;
|
||||
}
|
||||
|
||||
indicator.setTimeBucket(source.getTimeBucket());
|
||||
indicator.setEntityId(source.getEntityId());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.core.analysis.indicator.expression;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class GreaterEqualMatch {
|
||||
|
||||
public boolean match(Integer left, Integer right) {
|
||||
return left >= right;
|
||||
}
|
||||
|
||||
public boolean match(Long left, Long right) {
|
||||
return left >= right;
|
||||
}
|
||||
|
||||
public boolean match(Float left, Float right) {
|
||||
return left >= right;
|
||||
}
|
||||
|
||||
public boolean match(Double left, Double right) {
|
||||
return left >= right;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.core.analysis.indicator.expression;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class GreaterMatch {
|
||||
|
||||
public boolean match(Integer left, Integer right) {
|
||||
return left > right;
|
||||
}
|
||||
|
||||
public boolean match(Long left, Long right) {
|
||||
return left > right;
|
||||
}
|
||||
|
||||
public boolean match(Float left, Float right) {
|
||||
return left > right;
|
||||
}
|
||||
|
||||
public boolean match(Double left, Double right) {
|
||||
return left > right;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.core.analysis.indicator.expression;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class LessEqualMatch {
|
||||
|
||||
public boolean match(Integer left, Integer right) {
|
||||
return left <= right;
|
||||
}
|
||||
|
||||
public boolean match(Long left, Long right) {
|
||||
return left <= right;
|
||||
}
|
||||
|
||||
public boolean match(Float left, Float right) {
|
||||
return left <= right;
|
||||
}
|
||||
|
||||
public boolean match(Double left, Double right) {
|
||||
return left <= right;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.skywalking.oap.server.core.analysis.indicator.expression;
|
||||
|
||||
/**
|
||||
* @author peng-yongsheng
|
||||
*/
|
||||
public class LessMatch {
|
||||
|
||||
public boolean match(Integer left, Integer right) {
|
||||
return left < right;
|
||||
}
|
||||
|
||||
public boolean match(Long left, Long right) {
|
||||
return left < right;
|
||||
}
|
||||
|
||||
public boolean match(Float left, Float right) {
|
||||
return left < right;
|
||||
}
|
||||
|
||||
public boolean match(Double left, Double right) {
|
||||
return left < right;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue