You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2018/10/10 05:05:44 UTC
[incubator-skywalking] branch master updated: Fixed the bug of the
getValues method in metric query. (#1739)
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/incubator-skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 9e208d0 Fixed the bug of the getValues method in metric query. (#1739)
9e208d0 is described below
commit 9e208d048447bc1d41afcd136d518dd83963f6b0
Author: 彭勇升 pengys <80...@qq.com>
AuthorDate: Wed Oct 10 13:05:40 2018 +0800
Fixed the bug of the getValues method in metric query. (#1739)
---
.../elasticsearch/query/MetricQueryEsDAO.java | 23 ++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
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 ba9d192..de50486 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.get.*;
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 class MetricQueryEsDAO extends EsDAO implements IMetricQueryDAO {
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;
}