You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2018/10/10 05:05:41 UTC

[GitHub] wu-sheng closed pull request #1739: Fixed the bug of the getValues method in metric query.

wu-sheng closed pull request #1739: Fixed the bug of the getValues method in metric query.
URL: https://github.com/apache/incubator-skywalking/pull/1739
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetricQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetricQueryEsDAO.java
index ba9d192c7..de5048608 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetricQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/MetricQueryEsDAO.java
@@ -31,6 +31,8 @@
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.search.aggregations.AggregationBuilders;
 import org.elasticsearch.search.aggregations.bucket.terms.*;
+import org.elasticsearch.search.aggregations.metrics.avg.Avg;
+import org.elasticsearch.search.aggregations.metrics.sum.Sum;
 import org.elasticsearch.search.builder.SearchSourceBuilder;
 
 /**
@@ -59,13 +61,22 @@ public IntValues getValues(String indName, Step step, long startTB, long endTB,
         IntValues intValues = new IntValues();
         Terms idTerms = response.getAggregations().get(Indicator.ENTITY_ID);
         for (Terms.Bucket idBucket : idTerms.getBuckets()) {
-            Terms valueTerms = idBucket.getAggregations().get(valueCName);
-            for (Terms.Bucket valueBucket : valueTerms.getBuckets()) {
-                KVInt value = new KVInt();
-                value.setId(idBucket.getKeyAsString());
-                value.setValue(valueBucket.getKeyAsNumber().intValue());
-                intValues.getValues().add(value);
+            int value = 0;
+            switch (function) {
+                case Sum:
+                    Sum sum = idBucket.getAggregations().get(valueCName);
+                    value = (int)sum.getValue();
+                    break;
+                case Avg:
+                    Avg avg = idBucket.getAggregations().get(valueCName);
+                    value = (int)avg.getValue();
+                    break;
             }
+
+            KVInt kvInt = new KVInt();
+            kvInt.setId(idBucket.getKeyAsString());
+            kvInt.setValue(value);
+            intValues.getValues().add(kvInt);
         }
         return intValues;
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services