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/09 13:58:29 UTC

[GitHub] wu-sheng closed pull request #1737: Get the value column name from value column annotation manager.

wu-sheng closed pull request #1737: Get the value column name from value column annotation manager.
URL: https://github.com/apache/incubator-skywalking/pull/1737
 
 
   

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-core/src/main/java/org/apache/skywalking/oap/server/core/query/AggregationQueryService.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/AggregationQueryService.java
index f4873681a..6e247c6f0 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/AggregationQueryService.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/query/AggregationQueryService.java
@@ -25,6 +25,7 @@
 import org.apache.skywalking.oap.server.core.query.entity.*;
 import org.apache.skywalking.oap.server.core.register.*;
 import org.apache.skywalking.oap.server.core.storage.StorageModule;
+import org.apache.skywalking.oap.server.core.storage.annotation.ValueColumnIds;
 import org.apache.skywalking.oap.server.core.storage.query.IAggregationQueryDAO;
 import org.apache.skywalking.oap.server.library.module.*;
 import org.apache.skywalking.oap.server.library.module.Service;
@@ -48,9 +49,9 @@ private IAggregationQueryDAO getAggregationQueryDAO() {
         return aggregationQueryDAO;
     }
 
-    public List<TopNEntity> getServiceTopN(final String name, final int topN, final Step step, final long startTB,
+    public List<TopNEntity> getServiceTopN(final String indName, final int topN, final Step step, final long startTB,
         final long endTB, final Order order) throws IOException {
-        List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceTopN(name, topN, step, startTB, endTB, order);
+        List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceTopN(indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
         for (TopNEntity entity : topNEntities) {
             ServiceInventory inventory = moduleManager.find(CoreModule.NAME).getService(ServiceInventoryCache.class).get(Integer.valueOf(entity.getId()));
             if (inventory != null) {
@@ -60,9 +61,9 @@ private IAggregationQueryDAO getAggregationQueryDAO() {
         return topNEntities;
     }
 
-    public List<TopNEntity> getAllServiceInstanceTopN(final String name, final int topN, final Step step,
+    public List<TopNEntity> getAllServiceInstanceTopN(final String indName, final int topN, final Step step,
         final long startTB, final long endTB, final Order order) throws IOException {
-        List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllServiceInstanceTopN(name, topN, step, startTB, endTB, order);
+        List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllServiceInstanceTopN(indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
         for (TopNEntity entity : topNEntities) {
             ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class).get(Integer.valueOf(entity.getId()));
             if (inventory != null) {
@@ -72,9 +73,9 @@ private IAggregationQueryDAO getAggregationQueryDAO() {
         return topNEntities;
     }
 
-    public List<TopNEntity> getServiceInstanceTopN(final int serviceId, final String name, final int topN,
+    public List<TopNEntity> getServiceInstanceTopN(final int serviceId, final String indName, final int topN,
         final Step step, final long startTB, final long endTB, final Order order) throws IOException {
-        List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceInstanceTopN(serviceId, name, topN, step, startTB, endTB, order);
+        List<TopNEntity> topNEntities = getAggregationQueryDAO().getServiceInstanceTopN(serviceId, indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
         for (TopNEntity entity : topNEntities) {
             ServiceInstanceInventory inventory = moduleManager.find(CoreModule.NAME).getService(ServiceInstanceInventoryCache.class).get(Integer.valueOf(entity.getId()));
             if (inventory != null) {
@@ -84,9 +85,9 @@ private IAggregationQueryDAO getAggregationQueryDAO() {
         return topNEntities;
     }
 
-    public List<TopNEntity> getAllEndpointTopN(final String name, final int topN, final Step step,
+    public List<TopNEntity> getAllEndpointTopN(final String indName, final int topN, final Step step,
         final long startTB, final long endTB, final Order order) throws IOException {
-        List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllEndpointTopN(name, topN, step, startTB, endTB, order);
+        List<TopNEntity> topNEntities = getAggregationQueryDAO().getAllEndpointTopN(indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
         for (TopNEntity entity : topNEntities) {
             EndpointInventory inventory = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class).get(Integer.valueOf(entity.getId()));
             if (inventory != null) {
@@ -96,9 +97,9 @@ private IAggregationQueryDAO getAggregationQueryDAO() {
         return topNEntities;
     }
 
-    public List<TopNEntity> getEndpointTopN(final int serviceId, final String name, final int topN,
+    public List<TopNEntity> getEndpointTopN(final int serviceId, final String indName, final int topN,
         final Step step, final long startTB, final long endTB, final Order order) throws IOException {
-        List<TopNEntity> topNEntities = getAggregationQueryDAO().getEndpointTopN(serviceId, name, topN, step, startTB, endTB, order);
+        List<TopNEntity> topNEntities = getAggregationQueryDAO().getEndpointTopN(serviceId, indName, ValueColumnIds.INSTANCE.getValueCName(indName), topN, step, startTB, endTB, order);
         for (TopNEntity entity : topNEntities) {
             EndpointInventory inventory = moduleManager.find(CoreModule.NAME).getService(EndpointInventoryCache.class).get(Integer.valueOf(entity.getId()));
             if (inventory != null) {
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java
index 1310c4e3f..932aa3ee8 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/query/IAggregationQueryDAO.java
@@ -28,18 +28,20 @@
  */
 public interface IAggregationQueryDAO extends DAO {
 
-    List<TopNEntity> getServiceTopN(final String name, final int topN, final Step step, final long startTB,
+    List<TopNEntity> getServiceTopN(final String indName, String valueCName, final int topN, final Step step,
+        final long startTB,
         final long endTB, final Order order) throws IOException;
 
-    List<TopNEntity> getAllServiceInstanceTopN(final String name, final int topN, final Step step,
+    List<TopNEntity> getAllServiceInstanceTopN(final String indName, String valueCName, final int topN, final Step step,
         final long startTB, final long endTB, final Order order) throws IOException;
 
-    List<TopNEntity> getServiceInstanceTopN(final int serviceId, final String name, final int topN,
+    List<TopNEntity> getServiceInstanceTopN(final int serviceId, final String indName, String valueCName,
+        final int topN,
         final Step step, final long startTB, final long endTB, final Order order) throws IOException;
 
-    List<TopNEntity> getAllEndpointTopN(final String name, final int topN, final Step step,
+    List<TopNEntity> getAllEndpointTopN(final String indName, String valueCName, final int topN, final Step step,
         final long startTB, final long endTB, final Order order) throws IOException;
 
-    List<TopNEntity> getEndpointTopN(final int serviceId, final String name, final int topN,
+    List<TopNEntity> getEndpointTopN(final int serviceId, final String indName, String valueCName, final int topN,
         final Step step, final long startTB, final long endTB, final Order order) throws IOException;
 }
diff --git a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
index 2868da61b..eecd4ce1e 100644
--- a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
+++ b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AggregationQueryEsDAO.java
@@ -44,27 +44,27 @@ public AggregationQueryEsDAO(ElasticSearchClient client) {
     }
 
     @Override
-    public List<TopNEntity> getServiceTopN(String name, int topN, Step step, long startTB,
+    public List<TopNEntity> getServiceTopN(String indName, String valueCName, int topN, Step step, long startTB,
         long endTB, Order order) throws IOException {
-        String indexName = TimePyramidTableNameBuilder.build(step, name);
+        String indexName = TimePyramidTableNameBuilder.build(step, indName);
 
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
         sourceBuilder.query(QueryBuilders.rangeQuery(Indicator.TIME_BUCKET).lte(endTB).gte(startTB));
-        return aggregation(indexName, sourceBuilder, topN, order);
+        return aggregation(indexName, valueCName, sourceBuilder, topN, order);
     }
 
-    @Override public List<TopNEntity> getAllServiceInstanceTopN(String name, int topN, Step step,
+    @Override public List<TopNEntity> getAllServiceInstanceTopN(String indName, String valueCName, int topN, Step step,
         long startTB, long endTB, Order order) throws IOException {
-        String indexName = TimePyramidTableNameBuilder.build(step, name);
+        String indexName = TimePyramidTableNameBuilder.build(step, indName);
 
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
         sourceBuilder.query(QueryBuilders.rangeQuery(Indicator.TIME_BUCKET).lte(endTB).gte(startTB));
-        return aggregation(indexName, sourceBuilder, topN, order);
+        return aggregation(indexName, valueCName, sourceBuilder, topN, order);
     }
 
-    @Override public List<TopNEntity> getServiceInstanceTopN(int serviceId, String name, int topN,
+    @Override public List<TopNEntity> getServiceInstanceTopN(int serviceId, String indName, String valueCName, int topN,
         Step step, long startTB, long endTB, Order order) throws IOException {
-        String indexName = TimePyramidTableNameBuilder.build(step, name);
+        String indexName = TimePyramidTableNameBuilder.build(step, indName);
 
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
 
@@ -74,23 +74,23 @@ public AggregationQueryEsDAO(ElasticSearchClient client) {
         boolQueryBuilder.must().add(QueryBuilders.rangeQuery(Indicator.TIME_BUCKET).lte(endTB).gte(startTB));
         boolQueryBuilder.must().add(QueryBuilders.termQuery(ServiceInstanceInventory.SERVICE_ID, serviceId));
 
-        return aggregation(indexName, sourceBuilder, topN, order);
+        return aggregation(indexName, valueCName, sourceBuilder, topN, order);
     }
 
     @Override
-    public List<TopNEntity> getAllEndpointTopN(String name, int topN, Step step, long startTB,
+    public List<TopNEntity> getAllEndpointTopN(String indName, String valueCName, int topN, Step step, long startTB,
         long endTB, Order order) throws IOException {
-        String indexName = TimePyramidTableNameBuilder.build(step, name);
+        String indexName = TimePyramidTableNameBuilder.build(step, indName);
 
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
         sourceBuilder.query(QueryBuilders.rangeQuery(Indicator.TIME_BUCKET).lte(endTB).gte(startTB));
-        return aggregation(indexName, sourceBuilder, topN, order);
+        return aggregation(indexName, valueCName, sourceBuilder, topN, order);
     }
 
     @Override
-    public List<TopNEntity> getEndpointTopN(int serviceId, String name, int topN, Step step,
+    public List<TopNEntity> getEndpointTopN(int serviceId, String indName, String valueCName, int topN, Step step,
         long startTB, long endTB, Order order) throws IOException {
-        String indexName = TimePyramidTableNameBuilder.build(step, name);
+        String indexName = TimePyramidTableNameBuilder.build(step, indName);
 
         SearchSourceBuilder sourceBuilder = SearchSourceBuilder.searchSource();
 
@@ -100,10 +100,11 @@ public AggregationQueryEsDAO(ElasticSearchClient client) {
         boolQueryBuilder.must().add(QueryBuilders.rangeQuery(Indicator.TIME_BUCKET).lte(endTB).gte(startTB));
         boolQueryBuilder.must().add(QueryBuilders.termQuery(EndpointInventory.SERVICE_ID, serviceId));
 
-        return aggregation(indexName, sourceBuilder, topN, order);
+        return aggregation(indexName, valueCName, sourceBuilder, topN, order);
     }
 
-    private List<TopNEntity> aggregation(String indexName, SearchSourceBuilder sourceBuilder, int topN,
+    private List<TopNEntity> aggregation(String indexName, String valueCName, SearchSourceBuilder sourceBuilder,
+        int topN,
         Order order) throws IOException {
         boolean asc = false;
         if (order.equals(Order.ASC)) {
@@ -113,10 +114,10 @@ public AggregationQueryEsDAO(ElasticSearchClient client) {
         TermsAggregationBuilder aggregationBuilder = AggregationBuilders
             .terms(Indicator.ENTITY_ID)
             .field(Indicator.ENTITY_ID)
-            .order(BucketOrder.aggregation("value", asc))
+            .order(BucketOrder.aggregation(valueCName, asc))
             .size(topN)
             .subAggregation(
-                AggregationBuilders.avg("value").field("value")
+                AggregationBuilders.avg(valueCName).field(valueCName)
             );
         sourceBuilder.aggregation(aggregationBuilder);
 
@@ -127,7 +128,7 @@ public AggregationQueryEsDAO(ElasticSearchClient client) {
         for (Terms.Bucket termsBucket : idTerms.getBuckets()) {
             TopNEntity topNEntity = new TopNEntity();
             topNEntity.setId(termsBucket.getKeyAsString());
-            Avg value = termsBucket.getAggregations().get("value");
+            Avg value = termsBucket.getAggregations().get(valueCName);
             topNEntity.setValue((int)value.getValue());
             topNEntities.add(topNEntity);
         }


 

----------------------------------------------------------------
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