wu-sheng closed pull request #805: Provide the getServiceTPSTrend query.
URL: https://github.com/apache/incubator-skywalking/pull/805
 
 
   

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/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceMetricUIDAO.java
 
b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceMetricUIDAO.java
index 0ca4c752a..d97396ddc 100644
--- 
a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceMetricUIDAO.java
+++ 
b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IServiceMetricUIDAO.java
@@ -33,6 +33,8 @@
 public interface IServiceMetricUIDAO extends DAO {
     List<Integer> getServiceResponseTimeTrend(int serviceId, Step step, 
List<DurationPoint> durationPoints);
 
+    List<Integer> getServiceTPSTrend(int serviceId, Step step, 
List<DurationPoint> durationPoints);
+
     List<Integer> getServiceSLATrend(int serviceId, Step step, 
List<DurationPoint> durationPoints);
 
     List<Node> getServicesMetric(Step step, long startTime, long endTime,
diff --git 
a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ThroughputTrend.java
 
b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ThroughputTrend.java
index f20866964..a40716360 100644
--- 
a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ThroughputTrend.java
+++ 
b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/common/ThroughputTrend.java
@@ -18,6 +18,7 @@
 
 package org.apache.skywalking.apm.collector.storage.ui.common;
 
+import java.util.LinkedList;
 import java.util.List;
 
 /**
@@ -26,6 +27,10 @@
 public class ThroughputTrend {
     private List<Integer> trendList;
 
+    public ThroughputTrend() {
+        this.trendList = new LinkedList<>();
+    }
+
     public List<Integer> getTrendList() {
         return trendList;
     }
diff --git 
a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceMetricEsUIDAO.java
 
b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceMetricEsUIDAO.java
index e8f6fd81d..96ad55993 100644
--- 
a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceMetricEsUIDAO.java
+++ 
b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceMetricEsUIDAO.java
@@ -88,6 +88,29 @@ public ServiceMetricEsUIDAO(ElasticSearchClient client) {
         return trends;
     }
 
+    @Override public List<Integer> getServiceTPSTrend(int serviceId, Step 
step, List<DurationPoint> durationPoints) {
+        MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
+        String tableName = TimePyramidTableNameBuilder.build(step, 
ServiceMetricTable.TABLE);
+
+        durationPoints.forEach(durationPoint -> {
+            String id = durationPoint.getPoint() + Const.ID_SPLIT + serviceId 
+ Const.ID_SPLIT + MetricSource.Callee.getValue();
+            prepareMultiGet.add(tableName, ServiceMetricTable.TABLE_TYPE, id);
+        });
+
+        List<Integer> trends = new LinkedList<>();
+        MultiGetResponse multiGetResponse = prepareMultiGet.get();
+        for (MultiGetItemResponse response : multiGetResponse.getResponses()) {
+            if (response.getResponse().isExists()) {
+                long calls = 
((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)).longValue();
+                long errorCalls = 
((Number)response.getResponse().getSource().get(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)).longValue();
+                trends.add((int)(calls - errorCalls));
+            } else {
+                trends.add(0);
+            }
+        }
+        return trends;
+    }
+
     @Override public List<Integer> getServiceSLATrend(int serviceId, Step 
step, List<DurationPoint> durationPoints) {
         MultiGetRequestBuilder prepareMultiGet = getClient().prepareMultiGet();
         String tableName = TimePyramidTableNameBuilder.build(step, 
ServiceMetricTable.TABLE);
diff --git 
a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
 
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
index 0bab7e5b8..d21b39196 100644
--- 
a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
+++ 
b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceMetricH2UIDAO.java
@@ -80,6 +80,10 @@ public ServiceMetricH2UIDAO(H2Client client) {
         return trends;
     }
 
+    @Override public List<Integer> getServiceTPSTrend(int serviceId, Step 
step, List<DurationPoint> durationPoints) {
+        return null;
+    }
+
     @Override public List<Integer> getServiceSLATrend(int serviceId, Step 
step, List<DurationPoint> durationPoints) {
         String tableName = TimePyramidTableNameBuilder.build(step, 
ServiceMetricTable.TABLE);
 
diff --git 
a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServiceQuery.java
 
b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServiceQuery.java
index d4051b035..09c17cccf 100644
--- 
a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServiceQuery.java
+++ 
b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/ServiceQuery.java
@@ -70,8 +70,11 @@ public ResponseTimeTrend getServiceResponseTimeTrend(int 
serviceId, Duration dur
         return getServiceNameService().getServiceResponseTimeTrend(serviceId, 
duration.getStep(), start, end);
     }
 
-    public ThroughputTrend getServiceTPSTrend(int serviceId, Duration 
duration) {
-        return null;
+    public ThroughputTrend getServiceTPSTrend(int serviceId, Duration 
duration) throws ParseException {
+        long start = 
DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
+        long end = 
DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
+
+        return getServiceNameService().getServiceTPSTrend(serviceId, 
duration.getStep(), start, end);
     }
 
     public SLATrend getServiceSLATrend(int serviceId, Duration duration) 
throws ParseException {
diff --git 
a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameService.java
 
b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameService.java
index 2342deb3b..52061a754 100644
--- 
a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameService.java
+++ 
b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServiceNameService.java
@@ -30,6 +30,7 @@
 import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend;
 import org.apache.skywalking.apm.collector.storage.ui.common.SLATrend;
 import org.apache.skywalking.apm.collector.storage.ui.common.Step;
+import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend;
 import org.apache.skywalking.apm.collector.storage.ui.service.ServiceInfo;
 import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
 import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
@@ -58,6 +59,17 @@ public int getCount() {
         return serviceNameServiceUIDAO.searchService(keyword, topN);
     }
 
+    public ThroughputTrend getServiceTPSTrend(int serviceId, Step step, long 
start, long end) throws ParseException {
+        ThroughputTrend throughputTrend = new ThroughputTrend();
+        List<DurationPoint> durationPoints = 
DurationUtils.INSTANCE.getDurationPoints(step, start, end);
+        List<Integer> callsTrends = 
serviceMetricUIDAO.getServiceTPSTrend(serviceId, step, durationPoints);
+
+        //TODO
+        callsTrends.forEach(calls -> throughputTrend.getTrendList().add(calls 
/ 1000));
+
+        return throughputTrend;
+    }
+
     public ResponseTimeTrend getServiceResponseTimeTrend(int serviceId, Step 
step, long start,
         long end) throws ParseException {
         ResponseTimeTrend responseTimeTrend = new ResponseTimeTrend();


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to