skywalking-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wush...@apache.org
Subject [skywalking-agent-test-tool] branch master updated: Change histogram meter validate function (#26)
Date Mon, 12 Oct 2020 13:37:28 GMT
This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-agent-test-tool.git


The following commit(s) were added to refs/heads/master by this push:
     new d75f7e1  Change histogram meter validate function (#26)
d75f7e1 is described below

commit d75f7e1f593bd3816f6cd815482e355658adb8a0
Author: mrproliu <741550557@qq.com>
AuthorDate: Mon Oct 12 21:37:21 2020 +0800

    Change histogram meter validate function (#26)
    
    * Change histogram meter validate function
    
    * Change exception reason
    
    Co-authored-by: Mrproliu <mrproliu@lagou.com>
---
 .../plugin/test/mockcollector/entity/Meter.java    | 29 ++++++---------------
 .../test/mockcollector/util/MeterHandler.java      |  7 +++--
 .../agent/tool/validator/assertor/MeterAssert.java | 30 ++++++++++++++++------
 .../exception/HistogramSizeNotEqualsException.java |  2 +-
 ...va => MeterHistogramValueInvalidException.java} | 19 ++++++--------
 .../test/agent/tool/validator/entity/Meter.java    | 19 ++++++++++----
 6 files changed, 58 insertions(+), 48 deletions(-)

diff --git a/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Meter.java
b/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Meter.java
index ee9e467..cbf247f 100644
--- a/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Meter.java
+++ b/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/entity/Meter.java
@@ -31,25 +31,8 @@ import java.util.List;
 public class Meter {
     private MeterId meterId;
     private Double singleValue;
-    private List<BucketAndValue> histogram;
-
-    public static class BucketAndValue {
-        private double bucket;
-        private long count;
-
-        public BucketAndValue(double bucket, long count) {
-            this.bucket = bucket;
-            this.count = count;
-        }
-
-        public double getBucket() {
-            return bucket;
-        }
-
-        public long getCount() {
-            return count;
-        }
-    }
+    private List<Double> histogramBuckets;
+    private List<Long> histogramValues;
 
     public MeterId getMeterId() {
         return meterId;
@@ -59,7 +42,11 @@ public class Meter {
         return singleValue;
     }
 
-    public List<BucketAndValue> getHistogram() {
-        return histogram;
+    public List<Double> getHistogramBuckets() {
+        return histogramBuckets;
+    }
+
+    public List<Long> getHistogramValues() {
+        return histogramValues;
     }
 }
diff --git a/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/util/MeterHandler.java
b/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/util/MeterHandler.java
index a99389a..b78ad9f 100644
--- a/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/util/MeterHandler.java
+++ b/mock-collector/src/main/java/org/apache/skywalking/plugin/test/mockcollector/util/MeterHandler.java
@@ -18,6 +18,7 @@
 package org.apache.skywalking.plugin.test.mockcollector.util;
 
 import org.apache.skywalking.apm.network.language.agent.v3.Label;
+import org.apache.skywalking.apm.network.language.agent.v3.MeterBucketValue;
 import org.apache.skywalking.apm.network.language.agent.v3.MeterData;
 import org.apache.skywalking.apm.network.language.agent.v3.MeterHistogram;
 import org.apache.skywalking.apm.network.language.agent.v3.MeterSingleValue;
@@ -55,8 +56,10 @@ public class MeterHandler {
                         .name(histogram.getName())
                         .tags(parseTags(histogram.getLabelsList()))
                         .build());
-                    builder.histogram(histogram.getValuesList().stream()
-                        .map(b -> new Meter.BucketAndValue(b.getBucket(), b.getCount())).collect(Collectors.toList()));
+                    builder.histogramBuckets(histogram.getValuesList().stream()
+                        .map(MeterBucketValue::getBucket).collect(Collectors.toList()));
+                    builder.histogramValues(histogram.getValuesList().stream()
+                        .map(MeterBucketValue::getCount).collect(Collectors.toList()));
                     break;
                 case METRIC_NOT_SET:
                     return;
diff --git a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/MeterAssert.java
b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/MeterAssert.java
index d510905..280599e 100644
--- a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/MeterAssert.java
+++ b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/MeterAssert.java
@@ -19,8 +19,9 @@ package org.apache.skywalking.plugin.test.agent.tool.validator.assertor;
 
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.HistogramSizeNotEqualsException;
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.MeterAssertFailedException;
+import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.MeterHistogramValueInvalidException;
 import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.MeterNotFoundException;
-import org.apache.skywalking.plugin.test.agent.tool.validator.entity.BucketAndValue;
+import org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception.ValueAssertFailedException;
 import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Meter;
 import org.apache.skywalking.plugin.test.agent.tool.validator.entity.MeterItem;
 import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException;
@@ -60,17 +61,30 @@ public class MeterAssert {
         } else {
             // histogram
             // check size
-            if (excepted.getHistogram().size() != actual.getHistogram().size()) {
-                throw new HistogramSizeNotEqualsException(excepted, actual.getHistogram().size());
+            if (excepted.getHistogramBuckets().size() != actual.getHistogramBuckets().size())
{
+                throw new HistogramSizeNotEqualsException(excepted, actual.getHistogramBuckets().size());
             }
 
             // check buckets
-            for (int bucketIndex = 0; bucketIndex < excepted.getHistogram().size(); bucketIndex++)
{
-                final BucketAndValue exceptedBucket = excepted.getHistogram().get(bucketIndex);
-                final BucketAndValue actualBucket = actual.getHistogram().get(bucketIndex);
+            for (int bucketIndex = 0; bucketIndex < excepted.getHistogramBuckets().size();
bucketIndex++) {
+                final String exceptedBucket = excepted.getHistogramBuckets().get(bucketIndex);
+                final String actualBucket = actual.getHistogramBuckets().get(bucketIndex);
 
-                ExpressParser.parse(exceptedBucket.getBucket()).assertValue("histogram bucket",
actualBucket.getBucket());
-                ExpressParser.parse(exceptedBucket.getCount()).assertValue("histogram count["
+ actualBucket.getBucket() + "]", actualBucket.getCount());
+                if (!Objects.equals(exceptedBucket, actualBucket)) {
+                    throw new ValueAssertFailedException("histogram bucket", exceptedBucket,
actualBucket);
+                }
+            }
+
+            // check values
+            boolean valueContainValid = false;
+            for (String histogramValue : actual.getHistogramValues()) {
+                if (Long.parseLong(histogramValue) > 0) {
+                    valueContainValid = true;
+                    break;
+                }
+            }
+            if (!valueContainValid) {
+                throw new MeterHistogramValueInvalidException(actual.getMeterId());
             }
         }
     }
diff --git a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/HistogramSizeNotEqualsException.java
b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/HistogramSizeNotEqualsException.java
index 55ad439..b234e03 100644
--- a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/HistogramSizeNotEqualsException.java
+++ b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/HistogramSizeNotEqualsException.java
@@ -33,7 +33,7 @@ public class HistogramSizeNotEqualsException extends AssertFailedException
{
     public String getCauseMessage() {
         return String.format("HistogramSizeNotEqualsException:\nmeter id:%s\nexpected:%s\nactual:%s\n",
             exceptedMeter.getMeterId(),
-            exceptedMeter.getHistogram().size(),
+            exceptedMeter.getHistogramBuckets().size(),
             actualSize);
     }
 }
diff --git a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/HistogramSizeNotEqualsException.java
b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/MeterHistogramValueInvalidException.java
similarity index 67%
copy from validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/HistogramSizeNotEqualsException.java
copy to validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/MeterHistogramValueInvalidException.java
index 55ad439..7bc76aa 100644
--- a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/HistogramSizeNotEqualsException.java
+++ b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/assertor/exception/MeterHistogramValueInvalidException.java
@@ -17,23 +17,20 @@
 
 package org.apache.skywalking.plugin.test.agent.tool.validator.assertor.exception;
 
-import org.apache.skywalking.plugin.test.agent.tool.validator.entity.Meter;
+import org.apache.skywalking.plugin.test.agent.tool.validator.entity.MeterId;
 import org.apache.skywalking.plugin.test.agent.tool.validator.exception.AssertFailedException;
 
-public class HistogramSizeNotEqualsException extends AssertFailedException {
-    private final Meter exceptedMeter;
-    private final int actualSize;
+public class MeterHistogramValueInvalidException extends AssertFailedException {
+    private final MeterId meterId;
 
-    public HistogramSizeNotEqualsException(Meter exceptedMeter, int actualSize) {
-        this.exceptedMeter = exceptedMeter;
-        this.actualSize = actualSize;
+    public MeterHistogramValueInvalidException(MeterId meterId) {
+        this.meterId = meterId;
     }
 
     @Override
     public String getCauseMessage() {
-        return String.format("HistogramSizeNotEqualsException:\nmeter id:%s\nexpected:%s\nactual:%s\n",
-            exceptedMeter.getMeterId(),
-            exceptedMeter.getHistogram().size(),
-            actualSize);
+        return String.format("MeterHistogramValueInvalidException:\nmeter id:%s\nreason:%s\n",
+            meterId,
+            "One of the histogram bucket value must bigger than 0");
     }
 }
diff --git a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Meter.java
b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Meter.java
index 63c97f3..78840e2 100644
--- a/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Meter.java
+++ b/validator/src/main/java/org/apache/skywalking/plugin/test/agent/tool/validator/entity/Meter.java
@@ -22,7 +22,8 @@ import java.util.List;
 public class Meter {
     private MeterId meterId;
     private String singleValue;
-    private List<BucketAndValue> histogram;
+    private List<String> histogramBuckets;
+    private List<String> histogramValues;
 
     public MeterId getMeterId() {
         return meterId;
@@ -40,11 +41,19 @@ public class Meter {
         this.singleValue = singleValue;
     }
 
-    public List<BucketAndValue> getHistogram() {
-        return histogram;
+    public List<String> getHistogramBuckets() {
+        return histogramBuckets;
     }
 
-    public void setHistogram(List<BucketAndValue> histogram) {
-        this.histogram = histogram;
+    public void setHistogramBuckets(List<String> histogramBuckets) {
+        this.histogramBuckets = histogramBuckets;
+    }
+
+    public List<String> getHistogramValues() {
+        return histogramValues;
+    }
+
+    public void setHistogramValues(List<String> histogramValues) {
+        this.histogramValues = histogramValues;
     }
 }


Mime
View raw message