You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2019/11/14 03:23:12 UTC

[skywalking] branch oal/apdex created (now c19052a)

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

hanahmily pushed a change to branch oal/apdex
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at c19052a  Add apdex function to OAL

This branch includes the following new commits:

     new c19052a  Add apdex function to OAL

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking] 01/01: Add apdex function to OAL

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch oal/apdex
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit c19052aaec853ebbf5d691abe24d13c6f19b6c38
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Thu Nov 14 11:22:31 2019 +0800

    Add apdex function to OAL
---
 .../server/core/analysis/metrics/ApdexMetrics.java |  63 +++++++++++++
 .../analysis/metrics/ConfigurationDictionary.java  |  35 ++++++++
 .../core/analysis/metrics/ApdexMetricsTest.java    | 100 +++++++++++++++++++++
 3 files changed, 198 insertions(+)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/ApdexMetrics.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/ApdexMetrics.java
new file mode 100644
index 0000000..0238927
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/ApdexMetrics.java
@@ -0,0 +1,63 @@
+/*
+ * 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;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.Arg;
+import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.Entrance;
+import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.MetricsFunction;
+import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.SourceFrom;
+import org.apache.skywalking.oap.server.core.query.sql.Function;
+import org.apache.skywalking.oap.server.core.storage.annotation.Column;
+
+/**
+ * @author gaohongtao
+ */
+@MetricsFunction(functionName = "apdex")
+public abstract class ApdexMetrics extends Metrics implements IntValueHolder {
+    @Setter
+    private static ConfigurationDictionary DICT;
+    protected static final String VALUE = "value";
+    protected static final String T = "t";
+    protected static final String SCORE = "score";
+
+    @Getter @Setter @Column(columnName = VALUE) private long value;
+    @Getter @Setter @Column(columnName = T) private long t;
+    @Getter @Setter @Column(columnName = SCORE, isValue = true, function = Function.Avg) private int score;
+
+    @Entrance
+    public final void combine(@SourceFrom int value, @Arg String name) {
+        this.value += value;
+        this.t += DICT.lookup(name).intValue();
+    }
+
+    @Override public final void combine(Metrics metrics) {
+        t += ((ApdexMetrics)metrics).t;
+        value += ((ApdexMetrics)metrics).value;
+    }
+
+    @Override public void calculate() {
+        score = (int)(value * 10000 / t);
+    }
+
+    @Override public int getValue() {
+        return score;
+    }
+}
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/ConfigurationDictionary.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/ConfigurationDictionary.java
new file mode 100644
index 0000000..e6fce10
--- /dev/null
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/ConfigurationDictionary.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+/**
+ * Dictionary for lookup config item.
+ *
+ * @author gaohongtao
+ */
+public interface ConfigurationDictionary {
+
+    /**
+     * Lookup a number config item.
+     *
+     * @param name config key.
+     * @return a number config value.
+     */
+    Number lookup(String name);
+}
diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/ApdexMetricsTest.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/ApdexMetricsTest.java
new file mode 100644
index 0000000..8a3b280
--- /dev/null
+++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/ApdexMetricsTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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;
+
+import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.*;
+
+public class ApdexMetricsTest {
+
+    @Before
+    public void setUp() throws Exception {
+        ApdexMetrics.setDICT(name -> name.equals("foo") ? 500 : 1000);
+    }
+
+    @Test
+    public void testEntrance() {
+        ApdexMetrics apdex = new ApdexMetricsImpl();
+        apdex.combine(200, "foo");
+        apdex.combine(300, "bar");
+        apdex.calculate();
+        assertThat(apdex.getScore(), is(3333));
+
+        apdex = new ApdexMetricsImpl();
+        apdex.combine(200, "foo");
+        apdex.combine(500, "foo");
+        apdex.combine(300, "bar1");
+        apdex.combine(400, "bar2");
+        apdex.calculate();
+        assertThat(apdex.getScore(), is(4666));
+    }
+
+    @Test
+    public void testCombine() {
+        ApdexMetrics apdex1 = new ApdexMetricsImpl();
+        apdex1.combine(200, "foo");
+        apdex1.combine(300, "bar");
+
+
+        ApdexMetrics apdex2 = new ApdexMetricsImpl();
+        apdex2.combine(200, "foo");
+        apdex2.combine(500, "foo");
+        apdex2.combine(300, "bar1");
+        apdex2.combine(400, "bar2");
+
+        apdex1.combine(apdex2);
+        apdex1.calculate();
+        assertThat(apdex1.getScore(), is(4222));
+    }
+
+    public class ApdexMetricsImpl extends ApdexMetrics {
+
+        @Override public String id() {
+            return null;
+        }
+
+        @Override public Metrics toHour() {
+            return null;
+        }
+
+        @Override public Metrics toDay() {
+            return null;
+        }
+
+        @Override public Metrics toMonth() {
+            return null;
+        }
+
+        @Override public int remoteHashCode() {
+            return 0;
+        }
+
+        @Override public void deserialize(RemoteData remoteData) {
+
+        }
+
+        @Override public RemoteData.Builder serialize() {
+            return null;
+        }
+    }
+}
\ No newline at end of file