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 cd8cb02f6..e8f6fd81d 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 @@ -162,13 +162,15 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO { BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); boolQuery.must().add(QueryBuilders.rangeQuery(ServiceMetricTable.COLUMN_TIME_BUCKET).gte(start).lte(end)); - boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_APPLICATION_ID, applicationId)); + if (applicationId != 0) { + boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_APPLICATION_ID, applicationId)); + } boolQuery.must().add(QueryBuilders.termQuery(ServiceMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); searchRequestBuilder.setQuery(boolQuery); searchRequestBuilder.setSize(0); - TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(100); + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ServiceMetricTable.COLUMN_SERVICE_ID).field(ServiceMetricTable.COLUMN_SERVICE_ID).size(top); aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_CALLS)); aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)); aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM).field(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM)); diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java index 6d1fa55a9..afbec260d 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/query/OverViewLayerQuery.java @@ -28,7 +28,7 @@ import org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend; import org.apache.skywalking.apm.collector.storage.ui.overview.ClusterBrief; import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief; import org.apache.skywalking.apm.collector.storage.ui.server.AppServerInfo; -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.ui.graphql.Query; import org.apache.skywalking.apm.collector.ui.service.AlarmService; import org.apache.skywalking.apm.collector.ui.service.ApplicationService; @@ -118,8 +118,10 @@ public class OverViewLayerQuery implements Query { return null; } - public List getTopNSlowService(Duration duration, int topN) { - return null; + public List getTopNSlowService(Duration duration, int topN) throws ParseException { + long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); + long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); + return getServiceNameService().getSlowService(duration.getStep(), start, end, topN); } public List getTopNServerThroughput(Duration duration, int topN) { 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 a4de32ea7..2342deb3b 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 @@ -20,14 +20,18 @@ package org.apache.skywalking.apm.collector.ui.service; import java.text.ParseException; import java.util.List; +import org.apache.skywalking.apm.collector.cache.CacheModule; +import org.apache.skywalking.apm.collector.cache.service.ServiceNameCacheService; import org.apache.skywalking.apm.collector.core.module.ModuleManager; import org.apache.skywalking.apm.collector.storage.StorageModule; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceNameServiceUIDAO; +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.service.ServiceInfo; +import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; @@ -38,10 +42,12 @@ public class ServiceNameService { private final IServiceNameServiceUIDAO serviceNameServiceUIDAO; private final IServiceMetricUIDAO serviceMetricUIDAO; + private final ServiceNameCacheService serviceNameCacheService; public ServiceNameService(ModuleManager moduleManager) { this.serviceNameServiceUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceNameServiceUIDAO.class); this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class); + this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); } public int getCount() { @@ -66,4 +72,15 @@ public class ServiceNameService { slaTrend.setTrendList(serviceMetricUIDAO.getServiceSLATrend(serviceId, step, durationPoints)); return slaTrend; } + + public List getSlowService(Step step, long start, long end, + Integer top) throws ParseException { + List slowServices = serviceMetricUIDAO.getSlowService(0, step, start, end, top, MetricSource.Callee); + slowServices.forEach(slowService -> { + slowService.setName(serviceNameCacheService.get(slowService.getId()).getServiceName()); + //TODO + slowService.setTps(1); + }); + return slowServices; + } } diff --git a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls index 04b1033a6..50e1ff26c 100644 --- a/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls +++ b/apm-protocol/apm-ui-protocol/src/main/resources/ui-graphql/overview-layer.graphqls @@ -32,6 +32,6 @@ extend type Query { getClusterBrief(duration: Duration!): ClusterBrief getAlarmTrend(duration: Duration!): AlarmTrend getConjecturalApps(duration: Duration!): ConjecturalAppBrief - getTopNSlowService(duration: Duration!, topN: Int!): [ServiceInfo!]! + getTopNSlowService(duration: Duration!, topN: Int!): [ServiceMetric!]! getTopNServerThroughput(duration: Duration!, topN: Int!): [AppServerInfo!]! }