From 0c9686e4373483e1fe767021bfa262e5c2bceb78 Mon Sep 17 00:00:00 2001 From: peng-yongsheng <8082209@qq.com> Date: Sat, 10 Feb 2018 14:52:42 +0800 Subject: [PATCH] Provide the getServiceTPSTrend query. --- .../storage/dao/ui/IServiceMetricUIDAO.java | 2 ++ .../storage/ui/common/ThroughputTrend.java | 5 ++++ .../es/dao/ui/ServiceMetricEsUIDAO.java | 23 +++++++++++++++++++ .../h2/dao/ui/ServiceMetricH2UIDAO.java | 4 ++++ .../apm/collector/ui/query/ServiceQuery.java | 7 ++++-- .../ui/service/ServiceNameService.java | 12 ++++++++++ 6 files changed, 51 insertions(+), 2 deletions(-) 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 @@ import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; public interface IServiceMetricUIDAO extends DAO { List getServiceResponseTimeTrend(int serviceId, Step step, List durationPoints); + List getServiceTPSTrend(int serviceId, Step step, List durationPoints); + List getServiceSLATrend(int serviceId, Step step, List durationPoints); List 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 @@ import java.util.List; public class ThroughputTrend { private List trendList; + public ThroughputTrend() { + this.trendList = new LinkedList<>(); + } + public List 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 class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO { return trends; } + @Override public List getServiceTPSTrend(int serviceId, Step step, List 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 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 getServiceSLATrend(int serviceId, Step step, List 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 class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO { return trends; } + @Override public List getServiceTPSTrend(int serviceId, Step step, List durationPoints) { + return null; + } + @Override public List getServiceSLATrend(int serviceId, Step step, List 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 class ServiceQuery implements Query { 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.table.MetricSource; 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 class ServiceNameService { return serviceNameServiceUIDAO.searchService(keyword, topN); } + public ThroughputTrend getServiceTPSTrend(int serviceId, Step step, long start, long end) throws ParseException { + ThroughputTrend throughputTrend = new ThroughputTrend(); + List durationPoints = DurationUtils.INSTANCE.getDurationPoints(step, start, end); + List 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();