From dc4b7a8ecffd976bda61e24bd2064b7afaa3a542 Mon Sep 17 00:00:00 2001 From: yanchengzhe Date: Thu, 2 Sep 2021 10:07:09 +0800 Subject: [PATCH 1/7] Support for filter filtering of int type values --- .../skywalking/oal/rt/grammar/OALParser.g4 | 6 ++- .../skywalking/oal/rt/parser/OALListener.java | 5 ++ .../oal/rt/parser/DeepAnalysisTest.java | 6 +-- .../oal/rt/parser/ScriptParserTest.java | 22 ++++++++ .../analysis/metrics/expression/IntMatch.java | 31 +++++++++++ .../{EqualMatch.java => StringMatch.java} | 2 +- .../analysis/metrics/PercentMetricsTest.java | 26 +++++----- .../metrics/expression/IntMatchTest.java | 51 +++++++++++++++++++ ...ualMatchTest.java => StringMatchTest.java} | 16 +++--- 9 files changed, 139 insertions(+), 26 deletions(-) create mode 100644 oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java rename oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/{EqualMatch.java => StringMatch.java} (98%) create mode 100644 oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java rename oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/{EqualMatchTest.java => StringMatchTest.java} (79%) diff --git a/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 b/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 index 050defc2f490..92070c40fa3d 100644 --- a/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 +++ b/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 @@ -93,7 +93,7 @@ literalExpression ; expression - : booleanMatch | stringMatch | greaterMatch | lessMatch | greaterEqualMatch | lessEqualMatch | notEqualMatch | booleanNotEqualMatch | likeMatch | inMatch | containMatch | notContainMatch + : booleanMatch | intMatch | stringMatch | greaterMatch | lessMatch | greaterEqualMatch | lessEqualMatch | notEqualMatch | booleanNotEqualMatch | likeMatch | inMatch | containMatch | notContainMatch ; containMatch @@ -108,6 +108,10 @@ booleanMatch : conditionAttributeStmt DUALEQUALS booleanConditionValue ; +intMatch + : conditionAttributeStmt DUALEQUALS numberConditionValue + ; + stringMatch : conditionAttributeStmt DUALEQUALS (stringConditionValue | enumConditionValue) ; diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java index 4bc80ce7e8e2..051c638533f7 100644 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java +++ b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java @@ -114,6 +114,11 @@ public void enterBooleanMatch(OALParser.BooleanMatchContext ctx) { conditionExpression.setExpressionType("booleanMatch"); } + @Override + public void enterIntMatch(OALParser.IntMatchContext ctx) { + conditionExpression.setExpressionType("intMatch"); + } + @Override public void enterStringMatch(OALParser.StringMatchContext ctx) { conditionExpression.setExpressionType("stringMatch"); diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java index 1eb6fa524d3a..58d353ce7462 100644 --- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java +++ b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/DeepAnalysisTest.java @@ -22,7 +22,7 @@ import java.util.List; import org.apache.skywalking.oap.server.core.analysis.metrics.expression.BooleanMatch; import org.apache.skywalking.oap.server.core.analysis.metrics.expression.BooleanNotEqualMatch; -import org.apache.skywalking.oap.server.core.analysis.metrics.expression.EqualMatch; +import org.apache.skywalking.oap.server.core.analysis.metrics.expression.StringMatch; import org.apache.skywalking.oap.server.core.analysis.metrics.expression.NotEqualMatch; import org.apache.skywalking.oap.server.core.annotation.AnnotationScan; import org.apache.skywalking.oap.server.core.source.DefaultScopeDefine; @@ -127,7 +127,7 @@ public void testFilterAnalysis() { List filterExpressions = result.getFilterExpressions(); Assert.assertEquals(1, filterExpressions.size()); Expression filterExpression = filterExpressions.get(0); - Assert.assertEquals(EqualMatch.class.getName(), filterExpression.getExpressionObject()); + Assert.assertEquals(StringMatch.class.getName(), filterExpression.getExpressionObject()); Assert.assertEquals("source.getName()", filterExpression.getLeft()); Assert.assertEquals("\"/service/prod/save\"", filterExpression.getRight()); } @@ -157,7 +157,7 @@ public void shouldUseCorrectMatcher() { result.addFilterExpressionsParserResult(new ConditionExpression("stringMatch", "type", "")); result = analysis.analysis(result); assertTrue(result.getFilterExpressions().size() > 0); - assertEquals(EqualMatch.class.getName(), result.getFilterExpressions().get(0).getExpressionObject()); + assertEquals(StringMatch.class.getName(), result.getFilterExpressions().get(0).getExpressionObject()); assertEquals("source.getType()", result.getFilterExpressions().get(0).getLeft()); result.setFilterExpressions(null); diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java index 10c9322c0616..acb86e5b36e2 100644 --- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java +++ b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java @@ -269,6 +269,28 @@ public void testParse9() throws IOException { Assert.assertEquals(1, methodArgsExpressions.size()); } + @Test + public void testParse10() throws IOException { + ScriptParser parser = ScriptParser.createFromScriptText( + "all_percentile = from(All.latency).percentile(10);", TEST_SOURCE_PACKAGE); +// "ClientCpm = from(ServiceInstanceRelation.*).filter(componentId == 7).cpm();", TEST_SOURCE_PACKAGE); + List results = parser.parse().getMetricsStmts(); + + AnalysisResult clientCpm = results.get(0); + Assert.assertEquals("ClientCpm",clientCpm.getMetricsName()); + Assert.assertEquals("ServiceInstanceRelation",clientCpm.getSourceName()); + Assert.assertEquals("[*]",clientCpm.getSourceAttribute().toString()); + final List filterExpressions = clientCpm.getFilterExpressions(); + Assert.assertEquals(1, filterExpressions.size()); + Assert.assertEquals("source.getComponentId()", filterExpressions.get(0).getLeft()); + Assert.assertEquals("cpm", clientCpm.getAggregationFunctionName()); + + EntryMethod entryMethod = clientCpm.getEntryMethod(); + List methodArgsExpressions = entryMethod.getArgsExpressions(); + Assert.assertEquals(1, methodArgsExpressions.size()); + + } + @Test public void testDisable() throws IOException { ScriptParser parser = ScriptParser.createFromScriptText("disable(segment);", TEST_SOURCE_PACKAGE); diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java new file mode 100644 index 000000000000..448f7a2a267b --- /dev/null +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java @@ -0,0 +1,31 @@ +/* + * 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.metrics.expression; + +import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.FilterMatcher; + +@FilterMatcher +public class IntMatch { + + public boolean match(int left, int right) { + return left == right; + } + + public boolean match(Integer left, Integer right) { + return left.equals(right); + } +} diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/EqualMatch.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/StringMatch.java similarity index 98% rename from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/EqualMatch.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/StringMatch.java index 32c8a0091cfc..d0b6b0182576 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/EqualMatch.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/StringMatch.java @@ -22,7 +22,7 @@ import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.FilterMatcher; @FilterMatcher("stringMatch") -public class EqualMatch { +public class StringMatch { public boolean match(String left, String right) { if (left.startsWith("\"") && left.endsWith("\"")) { diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentMetricsTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentMetricsTest.java index eec91eb69768..51a2dbc655c7 100644 --- a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentMetricsTest.java +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentMetricsTest.java @@ -18,7 +18,7 @@ package org.apache.skywalking.oap.server.core.analysis.metrics; -import org.apache.skywalking.oap.server.core.analysis.metrics.expression.EqualMatch; +import org.apache.skywalking.oap.server.core.analysis.metrics.expression.StringMatch; import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData; import org.junit.Assert; import org.junit.Test; @@ -27,18 +27,18 @@ public class PercentMetricsTest { @Test public void testEntranceCombine() { PercentMetricsImpl impl = new PercentMetricsImpl(); - impl.combine(new EqualMatch().match(true, true)); - impl.combine(new EqualMatch().match(true, false)); - impl.combine(new EqualMatch().match(true, false)); + impl.combine(new StringMatch().match(true, true)); + impl.combine(new StringMatch().match(true, false)); + impl.combine(new StringMatch().match(true, false)); impl.calculate(); Assert.assertEquals(3333, impl.getValue()); impl = new PercentMetricsImpl(); - impl.combine(new EqualMatch().match(true, true)); - impl.combine(new EqualMatch().match(true, true)); - impl.combine(new EqualMatch().match(true, false)); + impl.combine(new StringMatch().match(true, true)); + impl.combine(new StringMatch().match(true, true)); + impl.combine(new StringMatch().match(true, false)); impl.calculate(); @@ -48,14 +48,14 @@ public void testEntranceCombine() { @Test public void testSelfCombine() { PercentMetricsImpl impl = new PercentMetricsImpl(); - impl.combine(new EqualMatch().match(true, true)); - impl.combine(new EqualMatch().match(true, false)); - impl.combine(new EqualMatch().match(true, false)); + impl.combine(new StringMatch().match(true, true)); + impl.combine(new StringMatch().match(true, false)); + impl.combine(new StringMatch().match(true, false)); PercentMetricsImpl impl2 = new PercentMetricsImpl(); - impl2.combine(new EqualMatch().match(true, true)); - impl2.combine(new EqualMatch().match(true, true)); - impl2.combine(new EqualMatch().match(true, false)); + impl2.combine(new StringMatch().match(true, true)); + impl2.combine(new StringMatch().match(true, true)); + impl2.combine(new StringMatch().match(true, false)); impl.combine(impl2); diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java new file mode 100644 index 000000000000..d73a290c9cbe --- /dev/null +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java @@ -0,0 +1,51 @@ +/* + * 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.metrics.expression; + +import org.junit.Test; + +import static org.junit.Assert.*; + +public class IntMatchTest { + + @Test + public void integerShouldEqual() { + Integer a = 334; + Integer b = 334; + boolean match = new IntMatch().match(a, b); + assertTrue(match); + + a = -123; + b = -123; + match = new IntMatch().match(a, b); + assertTrue(match); + + + a = -122; + b = -123; + match = new IntMatch().match(a, b); + assertFalse(match); + + a = -123; + b = -122; + match = new IntMatch().match(a, b); + assertFalse(match); + } + + + +} \ No newline at end of file diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/EqualMatchTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/StringMatchTest.java similarity index 79% rename from oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/EqualMatchTest.java rename to oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/StringMatchTest.java index bce02419b044..e3b665feace7 100644 --- a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/EqualMatchTest.java +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/StringMatchTest.java @@ -23,13 +23,13 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class EqualMatchTest { +public class StringMatchTest { @Test public void integerShouldEqualWhenLargerThan128() { Integer a = 334; Integer b = 334; - boolean match = new EqualMatch().match(a, b); + boolean match = new StringMatch().match(a, b); assertTrue(match); } @@ -37,7 +37,7 @@ public void integerShouldEqualWhenLargerThan128() { public void longShouldEqualWhenLargerThan128() { Long a = 334L; Long b = 334L; - boolean match = new EqualMatch().match(a, b); + boolean match = new StringMatch().match(a, b); assertTrue(match); } @@ -45,7 +45,7 @@ public void longShouldEqualWhenLargerThan128() { public void doubleShouldEqualWhenLargerThan128() { Double a = 334.0; Double b = 334.0; - boolean match = new EqualMatch().match(a, b); + boolean match = new StringMatch().match(a, b); assertTrue(match); } @@ -53,14 +53,14 @@ public void doubleShouldEqualWhenLargerThan128() { public void floatShouldEqualWhenLargerThan128() { Float a = 334.0F; Float b = 334.0F; - boolean match = new EqualMatch().match(a, b); + boolean match = new StringMatch().match(a, b); assertTrue(match); } @Test public void stringShouldEqual() { - assertTrue(new EqualMatch().match("\"a\"", "a")); - assertTrue(new EqualMatch().match("a", "a")); - assertFalse(new EqualMatch().match("\"a\"", "ab")); + assertTrue(new StringMatch().match("\"a\"", "a")); + assertTrue(new StringMatch().match("a", "a")); + assertFalse(new StringMatch().match("\"a\"", "ab")); } } \ No newline at end of file From 74b9906b00faa3e818852d5277535db0c75d41c9 Mon Sep 17 00:00:00 2001 From: yanchengzhe Date: Thu, 2 Sep 2021 16:45:41 +0800 Subject: [PATCH 2/7] Support for filter filtering of int type values --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 8ebee84964c2..62edfc1b0006 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,6 +40,7 @@ Release Notes. * Fix NPE when OAP nodes synchronize events with each other in cluster mode. * Support k8s configmap grouped dynamic configurations. * Add desc sort function in H2 and ElasticSearch implementations of IBrowserLogQueryDAO +* Support for filter function filtering of int type values. #### UI From 474a8c8ba9a7fe8079d8ab364bee47799252d6c5 Mon Sep 17 00:00:00 2001 From: YczYanchengzhe <18846837104@163.com> Date: Thu, 2 Sep 2021 18:42:12 +0800 Subject: [PATCH 3/7] fix ci error --- .../analysis/metrics/expression/IntMatch.java | 13 ++--- .../metrics/expression/IntMatchTest.java | 48 +++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java index 448f7a2a267b..6da89f950291 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.skywalking.oap.server.core.analysis.metrics.expression; import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.FilterMatcher; @@ -21,11 +22,11 @@ @FilterMatcher public class IntMatch { - public boolean match(int left, int right) { - return left == right; - } + public boolean match(int left, int right) { + return left == right; + } - public boolean match(Integer left, Integer right) { - return left.equals(right); - } + public boolean match(Integer left, Integer right) { + return left.equals(right); + } } diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java index d73a290c9cbe..7ab5b79c4b64 100644 --- a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.skywalking.oap.server.core.analysis.metrics.expression; import org.junit.Test; @@ -22,30 +23,27 @@ public class IntMatchTest { - @Test - public void integerShouldEqual() { - Integer a = 334; - Integer b = 334; - boolean match = new IntMatch().match(a, b); - assertTrue(match); - - a = -123; - b = -123; - match = new IntMatch().match(a, b); - assertTrue(match); - - - a = -122; - b = -123; - match = new IntMatch().match(a, b); - assertFalse(match); - - a = -123; - b = -122; - match = new IntMatch().match(a, b); - assertFalse(match); - } - - + @Test + public void integerShouldEqual() { + Integer a = 334; + Integer b = 334; + boolean match = new IntMatch().match(a, b); + assertTrue(match); + + a = -123; + b = -123; + match = new IntMatch().match(a, b); + assertTrue(match); + + a = -122; + b = -123; + match = new IntMatch().match(a, b); + assertFalse(match); + + a = -123; + b = -122; + match = new IntMatch().match(a, b); + assertFalse(match); + } } \ No newline at end of file From 64635e4c5ef89f70437307fa1575071befdf5cf7 Mon Sep 17 00:00:00 2001 From: YczYanchengzhe <18846837104@163.com> Date: Thu, 2 Sep 2021 19:35:20 +0800 Subject: [PATCH 4/7] fix ci error --- .../server/core/analysis/metrics/expression/IntMatchTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java index 7ab5b79c4b64..412c2563dbfe 100644 --- a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java @@ -19,7 +19,8 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; public class IntMatchTest { From 60827a6dc24ed5f5df34679899b41ea6debf399e Mon Sep 17 00:00:00 2001 From: YczYanchengzhe <18846837104@163.com> Date: Thu, 2 Sep 2021 19:55:13 +0800 Subject: [PATCH 5/7] fix ci error --- .../skywalking/oal/rt/parser/ScriptParserTest.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java index acb86e5b36e2..99ee17b58a99 100644 --- a/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java +++ b/oap-server/oal-rt/src/test/java/org/apache/skywalking/oal/rt/parser/ScriptParserTest.java @@ -272,23 +272,19 @@ public void testParse9() throws IOException { @Test public void testParse10() throws IOException { ScriptParser parser = ScriptParser.createFromScriptText( - "all_percentile = from(All.latency).percentile(10);", TEST_SOURCE_PACKAGE); -// "ClientCpm = from(ServiceInstanceRelation.*).filter(componentId == 7).cpm();", TEST_SOURCE_PACKAGE); + "ClientCpm = from(ServiceInstanceRelation.*).filter(componentId == 7).cpm();", TEST_SOURCE_PACKAGE); List results = parser.parse().getMetricsStmts(); - AnalysisResult clientCpm = results.get(0); - Assert.assertEquals("ClientCpm",clientCpm.getMetricsName()); - Assert.assertEquals("ServiceInstanceRelation",clientCpm.getSourceName()); - Assert.assertEquals("[*]",clientCpm.getSourceAttribute().toString()); + Assert.assertEquals("ClientCpm", clientCpm.getMetricsName()); + Assert.assertEquals("ServiceInstanceRelation", clientCpm.getSourceName()); + Assert.assertEquals("[*]", clientCpm.getSourceAttribute().toString()); final List filterExpressions = clientCpm.getFilterExpressions(); Assert.assertEquals(1, filterExpressions.size()); Assert.assertEquals("source.getComponentId()", filterExpressions.get(0).getLeft()); Assert.assertEquals("cpm", clientCpm.getAggregationFunctionName()); - EntryMethod entryMethod = clientCpm.getEntryMethod(); List methodArgsExpressions = entryMethod.getArgsExpressions(); Assert.assertEquals(1, methodArgsExpressions.size()); - } @Test From a7447af6759d98e983b725110ef2f0cc0b95338c Mon Sep 17 00:00:00 2001 From: YczYanchengzhe <18846837104@163.com> Date: Thu, 2 Sep 2021 23:03:30 +0800 Subject: [PATCH 6/7] Optimization --- .../skywalking/oal/rt/grammar/OALParser.g4 | 4 +- .../skywalking/oal/rt/parser/OALListener.java | 4 +- .../{IntMatch.java => NumberMatch.java} | 12 +- .../metrics/expression/IntMatchTest.java | 50 ------- .../metrics/expression/NumberMatchTest.java | 122 ++++++++++++++++++ 5 files changed, 136 insertions(+), 56 deletions(-) rename oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/{IntMatch.java => NumberMatch.java} (81%) delete mode 100644 oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java create mode 100644 oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java diff --git a/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 b/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 index 92070c40fa3d..643e29fccd85 100644 --- a/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 +++ b/oap-server/oal-grammar/src/main/antlr4/org/apache/skywalking/oal/rt/grammar/OALParser.g4 @@ -93,7 +93,7 @@ literalExpression ; expression - : booleanMatch | intMatch | stringMatch | greaterMatch | lessMatch | greaterEqualMatch | lessEqualMatch | notEqualMatch | booleanNotEqualMatch | likeMatch | inMatch | containMatch | notContainMatch + : booleanMatch | numberMatch | stringMatch | greaterMatch | lessMatch | greaterEqualMatch | lessEqualMatch | notEqualMatch | booleanNotEqualMatch | likeMatch | inMatch | containMatch | notContainMatch ; containMatch @@ -108,7 +108,7 @@ booleanMatch : conditionAttributeStmt DUALEQUALS booleanConditionValue ; -intMatch +numberMatch : conditionAttributeStmt DUALEQUALS numberConditionValue ; diff --git a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java index 051c638533f7..38cc77509962 100644 --- a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java +++ b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/parser/OALListener.java @@ -115,8 +115,8 @@ public void enterBooleanMatch(OALParser.BooleanMatchContext ctx) { } @Override - public void enterIntMatch(OALParser.IntMatchContext ctx) { - conditionExpression.setExpressionType("intMatch"); + public void enterNumberMatch(OALParser.NumberMatchContext ctx) { + conditionExpression.setExpressionType("numberMatch"); } @Override diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatch.java similarity index 81% rename from oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java rename to oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatch.java index 6da89f950291..a58eb039cb13 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatch.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatch.java @@ -20,13 +20,21 @@ import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.FilterMatcher; @FilterMatcher -public class IntMatch { +public class NumberMatch { public boolean match(int left, int right) { return left == right; } - public boolean match(Integer left, Integer right) { + public boolean match(long left, long right) { + return left == right; + } + + public boolean match(float left, float right) { + return left == right; + } + + public boolean match(Number left, Number right) { return left.equals(right); } } diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java deleted file mode 100644 index 412c2563dbfe..000000000000 --- a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/IntMatchTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.metrics.expression; - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; - -public class IntMatchTest { - - @Test - public void integerShouldEqual() { - Integer a = 334; - Integer b = 334; - boolean match = new IntMatch().match(a, b); - assertTrue(match); - - a = -123; - b = -123; - match = new IntMatch().match(a, b); - assertTrue(match); - - a = -122; - b = -123; - match = new IntMatch().match(a, b); - assertFalse(match); - - a = -123; - b = -122; - match = new IntMatch().match(a, b); - assertFalse(match); - } - -} \ No newline at end of file diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java new file mode 100644 index 000000000000..f12ff9f58b41 --- /dev/null +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java @@ -0,0 +1,122 @@ +/* + * 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.metrics.expression; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +public class NumberMatchTest { + + @Test + public void integerShouldEqual() { + Integer a = 334; + Integer b = 334; + boolean match = new NumberMatch().match(a, b); + assertTrue(match); + + a = -123; + b = -123; + match = new NumberMatch().match(a, b); + assertTrue(match); + + a = -122; + b = -123; + match = new NumberMatch().match(a, b); + assertFalse(match); + + a = -123; + b = -122; + match = new NumberMatch().match(a, b); + assertFalse(match); + } + + @Test + public void intShouldEqual() { + int a = 334; + int b = 334; + boolean match = new NumberMatch().match(a, b); + assertTrue(match); + + a = -123; + b = -123; + match = new NumberMatch().match(a, b); + assertTrue(match); + + a = -122; + b = -123; + match = new NumberMatch().match(a, b); + assertFalse(match); + + a = -123; + b = -122; + match = new NumberMatch().match(a, b); + assertFalse(match); + } + + @Test + public void longShouldEqual() { + long a = 21474836478L; + long b = 21474836478L; + boolean match = new NumberMatch().match(a, b); + assertTrue(match); + + a = -21474836478L; + b = -21474836479L; + match = new NumberMatch().match(a, b); + assertFalse(match); + + Long c = -123L; + Long d = -123L; + match = new NumberMatch().match(c, d); + assertTrue(match); + + c = -21474836478L; + d = -21474836479L; + match = new NumberMatch().match(c, d); + assertFalse(match); + } + + @Test + public void doubleShouldEqual() { + Double a = 334.0; + Double b = 334.0; + boolean match = new NumberMatch().match(a, b); + assertTrue(match); + + double c = 334.0; + double d = 334.0; + match = new NumberMatch().match(c, d); + assertTrue(match); + } + + @Test + public void floatShouldEqual() { + Float a = 334.0F; + Float b = 334.0F; + boolean match = new NumberMatch().match(a, b); + assertTrue(match); + + float c = 334.0F; + float d = 334.0F; + match = new NumberMatch().match(c, d); + assertTrue(match); + } + +} \ No newline at end of file From db443db241707503508c3f13af414faf6ba8f81e Mon Sep 17 00:00:00 2001 From: YczYanchengzhe <18846837104@163.com> Date: Thu, 2 Sep 2021 23:28:30 +0800 Subject: [PATCH 7/7] 1. Number doesn't include float 2. delete number object --- .../metrics/expression/NumberMatch.java | 7 ----- .../metrics/expression/NumberMatchTest.java | 26 ------------------- 2 files changed, 33 deletions(-) diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatch.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatch.java index a58eb039cb13..17b3629cf277 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatch.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatch.java @@ -30,11 +30,4 @@ public boolean match(long left, long right) { return left == right; } - public boolean match(float left, float right) { - return left == right; - } - - public boolean match(Number left, Number right) { - return left.equals(right); - } } diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java index f12ff9f58b41..2048f4451fbd 100644 --- a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java +++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/NumberMatchTest.java @@ -93,30 +93,4 @@ public void longShouldEqual() { assertFalse(match); } - @Test - public void doubleShouldEqual() { - Double a = 334.0; - Double b = 334.0; - boolean match = new NumberMatch().match(a, b); - assertTrue(match); - - double c = 334.0; - double d = 334.0; - match = new NumberMatch().match(c, d); - assertTrue(match); - } - - @Test - public void floatShouldEqual() { - Float a = 334.0F; - Float b = 334.0F; - boolean match = new NumberMatch().match(a, b); - assertTrue(match); - - float c = 334.0F; - float d = 334.0F; - match = new NumberMatch().match(c, d); - assertTrue(match); - } - } \ No newline at end of file