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 2020/02/19 13:14:05 UTC

[skywalking] branch oap-metric created (now c0dbc54)

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

hanahmily pushed a change to branch oap-metric
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at c0dbc54  Fix NPE of decoding IntKeyLongValuesHashMap

This branch includes the following new commits:

     new c0dbc54  Fix NPE of decoding IntKeyLongValuesHashMap

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: Fix NPE of decoding IntKeyLongValuesHashMap

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

hanahmily pushed a commit to branch oap-metric
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit c0dbc5441d98f04a7e7dc60564bddcc4e66ea5b7
Author: Gao Hongtao <ha...@gmail.com>
AuthorDate: Wed Feb 19 21:08:42 2020 +0800

    Fix NPE of decoding IntKeyLongValuesHashMap
    
    If IntKeyLongValuesHashMap#toStorageDate generate an empty string,
    that usually because there's no any traffic in one minute. When syncing
    it to cache, IntKeyLongValuesHashMap#toObject will raise a NPE.
    
    Signed-off-by: Gao Hongtao <ha...@gmail.com>
---
 .../server/core/analysis/metrics/IntKeyLongValueHashMap.java   |  4 ++++
 .../oap/server/core/analysis/metrics/PercentileMetrics.java    | 10 +++++++++-
 .../core/analysis/metrics/IntKeyLongValueHashMapTestCase.java  |  8 ++++++++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMap.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMap.java
index d2d149e..3572d42 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMap.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMap.java
@@ -17,6 +17,7 @@
 
 package org.apache.skywalking.oap.server.core.analysis.metrics;
 
+import com.google.common.base.Strings;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -57,6 +58,9 @@ public class IntKeyLongValueHashMap extends HashMap<Integer, IntKeyLongValue> im
 
     @Override
     public void toObject(String data) {
+        if (Strings.isNullOrEmpty(data)) {
+            return;
+        }
         String[] keyValues = data.split(Const.ARRAY_PARSER_SPLIT);
         for (String keyValue : keyValues) {
             IntKeyLongValue value = new IntKeyLongValue();
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java
index 2c0e2b2..e147499 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/analysis/metrics/PercentileMetrics.java
@@ -61,7 +61,7 @@ public abstract class PercentileMetrics extends GroupMetrics implements MultiInt
     private boolean isCalculated;
 
     public PercentileMetrics() {
-        percentileValues = new IntKeyLongValueHashMap(RANKS.length);
+        percentileValues = initDataset();
         dataset = new IntKeyLongValueHashMap(30);
     }
 
@@ -128,4 +128,12 @@ public abstract class PercentileMetrics extends GroupMetrics implements MultiInt
         }
         return values;
     }
+
+    private IntKeyLongValueHashMap initDataset() {
+        IntKeyLongValueHashMap r = new IntKeyLongValueHashMap(RANKS.length);
+        for (final int rank : RANKS) {
+            r.put(rank, new IntKeyLongValue(rank, 0));
+        }
+        return r;
+    }
 }
diff --git a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMapTestCase.java b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMapTestCase.java
index 8d8a7da..335fd3b 100644
--- a/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMapTestCase.java
+++ b/oap-server/server-core/src/test/java/org/apache/skywalking/oap/server/core/analysis/metrics/IntKeyLongValueHashMapTestCase.java
@@ -65,4 +65,12 @@ public class IntKeyLongValueHashMapTestCase {
 
         Assert.assertEquals("1,100|2,200|5,500|6,600|7,700", intKeyLongValueHashMap.toStorageData());
     }
+
+    @Test
+    public void testNull() {
+        IntKeyLongValueHashMap nullHm = new IntKeyLongValueHashMap();
+        IntKeyLongValueHashMap m = new IntKeyLongValueHashMap();
+        m.toObject(nullHm.toStorageData());
+        Assert.assertEquals(m.toStorageData(), "");
+    }
 }