This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch rt-oal
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit 429ebf7aa1c01204ec031eb00a5152fa81e20644
Author: Wu Sheng <[email protected]>
AuthorDate: Wed Jul 17 23:44:13 2019 +0800

    Implement disable in hardcode.
---
 .../org/apache/skywalking/oal/rt/OALRuntime.java   | 10 +++
 .../code-templates/dispatcher/doMetrics.ftl        | 18 ++----
 .../oap/server/core/analysis/DisableRegister.java  |  6 +-
 .../metrics/expression/BinaryMatchExpression.java  | 74 ----------------------
 .../analysis/metrics/expression/EqualMatch.java    | 46 ++++++++++++--
 .../core/analysis/metrics/PercentMetricsTest.java  | 24 +++----
 6 files changed, 73 insertions(+), 105 deletions(-)

diff --git 
a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java 
b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java
index 6037892..3d30baa 100644
--- 
a/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java
+++ 
b/oap-server/oal-rt/src/main/java/org/apache/skywalking/oal/rt/OALRuntime.java
@@ -45,6 +45,7 @@ import javassist.bytecode.ClassFile;
 import javassist.bytecode.ConstPool;
 import javassist.bytecode.SignatureAttribute;
 import javassist.bytecode.annotation.Annotation;
+import javassist.bytecode.annotation.ArrayMemberValue;
 import javassist.bytecode.annotation.ClassMemberValue;
 import javassist.bytecode.annotation.IntegerMemberValue;
 import javassist.bytecode.annotation.StringMemberValue;
@@ -55,13 +56,17 @@ import 
org.apache.skywalking.oal.rt.output.AllDispatcherContext;
 import org.apache.skywalking.oal.rt.output.DispatcherContext;
 import org.apache.skywalking.oal.rt.output.FileGenerator;
 import org.apache.skywalking.oal.rt.parser.AnalysisResult;
+import org.apache.skywalking.oal.rt.parser.DisableCollection;
 import org.apache.skywalking.oal.rt.parser.MetricsHolder;
 import org.apache.skywalking.oal.rt.parser.OALScripts;
 import org.apache.skywalking.oal.rt.parser.ScriptParser;
 import org.apache.skywalking.oal.rt.parser.SourceColumn;
 import org.apache.skywalking.oal.rt.parser.SourceColumnsFactory;
 import org.apache.skywalking.oap.server.core.WorkPath;
+import org.apache.skywalking.oap.server.core.analysis.Disable;
+import org.apache.skywalking.oap.server.core.analysis.DisableRegister;
 import 
org.apache.skywalking.oap.server.core.analysis.DispatcherDetectorListener;
+import org.apache.skywalking.oap.server.core.analysis.MultipleDisable;
 import org.apache.skywalking.oap.server.core.analysis.SourceDispatcher;
 import org.apache.skywalking.oap.server.core.analysis.Stream;
 import org.apache.skywalking.oap.server.core.analysis.StreamAnnotationListener;
@@ -88,6 +93,7 @@ public class OALRuntime implements OALEngine {
     private static final String DYNAMIC_METRICS_CLASS_PACKAGE = 
"org.apache.skywalking.oal.rt.metrics.";
     private static final String DYNAMIC_METRICS_BUILDER_CLASS_PACKAGE = 
"org.apache.skywalking.oal.rt.metrics.builder.";
     private static final String DYNAMIC_DISPATCHER_CLASS_PACKAGE = 
"org.apache.skywalking.oal.rt.dispatcher.";
+    private static final String DYNAMIC_DISABLE_CLASS_NAME = 
"org.apache.skywalking.oal.rt.DisableSourceDefinition";
     private static final String WITH_METADATA_INTERFACE = 
"org.apache.skywalking.oap.server.core.analysis.metrics.WithMetadata";
     private static final String STORAGE_BUILDER_INTERFACE = 
"org.apache.skywalking.oap.server.core.storage.StorageBuilder";
     private static final String DISPATCHER_INTERFACE = 
"org.apache.skywalking.oap.server.core.analysis.SourceDispatcher";
@@ -185,6 +191,10 @@ public class OALRuntime implements OALEngine {
         for (Map.Entry<String, DispatcherContext> entry : 
allDispatcherContext.getAllContext().entrySet()) {
             dispatcherClasses.add(generateDispatcherClass(entry.getKey(), 
entry.getValue()));
         }
+
+        
oalScripts.getDisableCollection().getAllDisableSources().forEach(disable -> {
+            DisableRegister.INSTANCE.add(disable);
+        });
     }
 
     /**
diff --git 
a/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/doMetrics.ftl 
b/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/doMetrics.ftl
index 6e7c6f4..058352e 100644
--- 
a/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/doMetrics.ftl
+++ 
b/oap-server/oal-rt/src/main/resources/code-templates/dispatcher/doMetrics.ftl
@@ -3,15 +3,9 @@ private void 
do${metricsName}(org.apache.skywalking.oap.server.core.source.${sou
 
     <#if filterExpressions??>
         <#list filterExpressions as filterExpression>
-            <#if filterExpression.expressionObject == "GreaterMatch" || 
filterExpression.expressionObject == "LessMatch" || 
filterExpression.expressionObject == "GreaterEqualMatch" || 
filterExpression.expressionObject == "LessEqualMatch">
-                if (!new 
org.apache.skywalking.oap.server.core.analysis.metrics.expression.${filterExpression.expressionObject}().match(${filterExpression.left},
 ${filterExpression.right})) {
-                    return;
-                }
-            <#else>
-                if (!new 
org.apache.skywalking.oap.server.core.analysis.metrics.expression.${filterExpression.expressionObject}().setLeft(${filterExpression.left}).setRight(${filterExpression.right}).match())
 {
-                    return;
-                }
-            </#if>
+            if (!new 
org.apache.skywalking.oap.server.core.analysis.metrics.expression.${filterExpression.expressionObject}().match(${filterExpression.left},
 ${filterExpression.right})) {
+                return;
+            }
         </#list>
     </#if>
 
@@ -24,11 +18,7 @@ private void 
do${metricsName}(org.apache.skywalking.oap.server.core.source.${sou
             <#if entryMethod.argTypes[arg_index] == 1>
                 ${arg}
             <#else>
-                <#if arg.expressionObject == "GreaterMatch" || 
arg.expressionObject == "LessMatch" || arg.expressionObject == 
"GreaterEqualMatch" || arg.expressionObject == "LessEqualMatch">
-                    new 
org.apache.skywalking.oap.server.core.analysis.metrics.expression.${arg.expressionObject}().match(${arg.left},
 ${arg.right})
-                <#else>
-                    new 
org.apache.skywalking.oap.server.core.analysis.metrics.expression.${arg.expressionObject}().setLeft(${arg.left}).setRight(${arg.right}).match()
-                </#if>
+                 new 
org.apache.skywalking.oap.server.core.analysis.metrics.expression.${arg.expressionObject}().match(${arg.left},
 ${arg.right})
             </#if><#if arg_has_next>, </#if>
         </#list>);
 
diff --git 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/DisableRegister.java
 
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/DisableRegister.java
index d90462e..b87dd79 100644
--- 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/DisableRegister.java
+++ 
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/DisableRegister.java
@@ -43,11 +43,15 @@ public class DisableRegister implements AnnotationListener {
         Disable[] valueList = annotation.value();
         if (valueList != null) {
             for (Disable disable : valueList) {
-                disableEntitySet.add(disable.value());
+                add(disable.value());
             }
         }
     }
 
+    public void add(String name) {
+        disableEntitySet.add(name);
+    }
+
     public boolean include(String name) {
         return disableEntitySet.contains(name);
     }
diff --git 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/BinaryMatchExpression.java
 
b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/BinaryMatchExpression.java
deleted file mode 100644
index f2985e5..0000000
--- 
a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/expression/BinaryMatchExpression.java
+++ /dev/null
@@ -1,74 +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;
-
-/**
- * BinaryMatchExpression accepts two calculate factors,
- * and return the True/False result.
- *
- * @author wusheng
- */
-public abstract class BinaryMatchExpression {
-    protected Object left;
-    protected Object right;
-
-    public BinaryMatchExpression setLeft(Object left) {
-        this.left = left;
-        return this;
-    }
-
-    public BinaryMatchExpression setLeft(boolean left) {
-        return setLeft(left);
-    }
-
-    public BinaryMatchExpression setLeft(int left) {
-        return setLeft(left);
-    }
-
-    public BinaryMatchExpression setLeft(long left) {
-        return setLeft(left);
-    }
-
-    public BinaryMatchExpression setLeft(double left) {
-        return setLeft(left);
-    }
-
-    public BinaryMatchExpression setRight(Object right) {
-        this.right = right;
-        return this;
-    }
-
-    public BinaryMatchExpression setRight(boolean left) {
-        return setLeft(left);
-    }
-
-    public BinaryMatchExpression setRight(int left) {
-        return setLeft(left);
-    }
-
-    public BinaryMatchExpression setRight(long left) {
-        return setLeft(left);
-    }
-
-    public BinaryMatchExpression setRight(double left) {
-        return setLeft(left);
-    }
-
-    public abstract boolean match();
-}
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/EqualMatch.java
index f5916f6..c40783e 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/EqualMatch.java
@@ -19,12 +19,50 @@
 package org.apache.skywalking.oap.server.core.analysis.metrics.expression;
 
 /**
- *
- *
  * @author wusheng
  */
-public class EqualMatch extends BinaryMatchExpression {
-    @Override public boolean match() {
+public class EqualMatch {
+    public boolean match(int left, int 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;
+    }
+
+    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;
+    }
+
+    public boolean match(Boolean left, Boolean right) {
+        return left == right;
+    }
+
+    public boolean match(boolean left, boolean right) {
+        return left == right;
+    }
+
+    public boolean match(Object left, Object right) {
         return left.equals(right);
     }
 }
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 97a3f0d..9e976dd 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
@@ -30,18 +30,18 @@ public class PercentMetricsTest {
     @Test
     public void testEntranceCombine() {
         PercentMetricsImpl impl = new PercentMetricsImpl();
-        impl.combine(new EqualMatch().setLeft(true).setRight(true).match());
-        impl.combine(new EqualMatch().setLeft(true).setRight(false).match());
-        impl.combine(new EqualMatch().setLeft(true).setRight(false).match());
+        impl.combine(new EqualMatch().match(true,true));
+        impl.combine(new EqualMatch().match(true,false));
+        impl.combine(new EqualMatch().match(true,false));
 
         impl.calculate();
 
         Assert.assertEquals(3333, impl.getValue());
 
         impl = new PercentMetricsImpl();
-        impl.combine(new EqualMatch().setLeft(true).setRight(true).match());
-        impl.combine(new EqualMatch().setLeft(true).setRight(true).match());
-        impl.combine(new EqualMatch().setLeft(true).setRight(false).match());
+        impl.combine(new EqualMatch().match(true,true));
+        impl.combine(new EqualMatch().match(true,true));
+        impl.combine(new EqualMatch().match(true,false));
 
         impl.calculate();
 
@@ -51,14 +51,14 @@ public class PercentMetricsTest {
     @Test
     public void testSelfCombine() {
         PercentMetricsImpl impl = new PercentMetricsImpl();
-        impl.combine(new EqualMatch().setLeft(true).setRight(true).match());
-        impl.combine(new EqualMatch().setLeft(true).setRight(false).match());
-        impl.combine(new EqualMatch().setLeft(true).setRight(false).match());
+        impl.combine(new EqualMatch().match(true,true));
+        impl.combine(new EqualMatch().match(true,false));
+        impl.combine(new EqualMatch().match(true,false));
 
         PercentMetricsImpl impl2 = new PercentMetricsImpl();
-        impl2.combine(new EqualMatch().setLeft(true).setRight(true).match());
-        impl2.combine(new EqualMatch().setLeft(true).setRight(true).match());
-        impl2.combine(new EqualMatch().setLeft(true).setRight(false).match());
+        impl2.combine(new EqualMatch().match(true,true));
+        impl2.combine(new EqualMatch().match(true,true));
+        impl2.combine(new EqualMatch().match(true,false));
 
         impl.combine(impl2);
 

Reply via email to