From 71275468c59404076014c1befa9e3d05c3a22b7f Mon Sep 17 00:00:00 2001 From: peng-yongsheng <8082209@qq.com> Date: Sat, 10 Feb 2018 10:17:32 +0800 Subject: [PATCH] Provide the getTopNApplicationThroughput query. --- .../apm/collector/storage/StorageModule.java | 2 + .../dao/ui/IApplicationMetricUIDAO.java | 33 ++++++ .../storage/ui/overview/ApplicationTPS.java | 52 +++++++++ .../storage/es/StorageModuleEsProvider.java | 3 + .../es/dao/ui/ApplicationMetricEsUIDAO.java | 104 ++++++++++++++++++ .../storage/h2/StorageModuleH2Provider.java | 3 + .../h2/dao/ui/ApplicationMetricH2UIDAO.java | 47 ++++++++ .../ui/query/OverViewLayerQuery.java | 15 +-- .../ui/service/ApplicationService.java | 15 +++ .../collector/ui/service/ServerService.java | 14 --- 10 files changed, 262 insertions(+), 26 deletions(-) create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationMetricUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ApplicationTPS.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationMetricEsUIDAO.java create mode 100644 apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationMetricH2UIDAO.java diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java index b2230b947..9434ee859 100644 --- a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/StorageModule.java @@ -104,6 +104,7 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMin import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; @@ -248,6 +249,7 @@ public class StorageModule extends Module { classes.add(IInstanceMetricUIDAO.class); classes.add(IApplicationComponentUIDAO.class); classes.add(IApplicationMappingUIDAO.class); + classes.add(IApplicationMetricUIDAO.class); classes.add(IApplicationReferenceMetricUIDAO.class); classes.add(ISegmentDurationUIDAO.class); classes.add(ISegmentUIDAO.class); diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationMetricUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationMetricUIDAO.java new file mode 100644 index 000000000..2ced95a36 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/dao/ui/IApplicationMetricUIDAO.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.dao.ui; + +import java.util.List; +import org.apache.skywalking.apm.collector.storage.base.dao.DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS; + +/** + * @author peng-yongsheng + */ +public interface IApplicationMetricUIDAO extends DAO { + List getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond, int topN, + MetricSource metricSource); +} diff --git a/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ApplicationTPS.java b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ApplicationTPS.java new file mode 100644 index 000000000..51e4c339c --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-define/src/main/java/org/apache/skywalking/apm/collector/storage/ui/overview/ApplicationTPS.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.ui.overview; + +/** + * @author peng-yongsheng + */ +public class ApplicationTPS { + private int applicationId; + private String applicationCode; + private int tps; + + public int getApplicationId() { + return applicationId; + } + + public void setApplicationId(int applicationId) { + this.applicationId = applicationId; + } + + public String getApplicationCode() { + return applicationCode; + } + + public void setApplicationCode(String applicationCode) { + this.applicationCode = applicationCode; + } + + public int getTps() { + return tps; + } + + public void setTps(int tps) { + this.tps = tps; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java index 943af2af3..789c9d652 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/StorageModuleEsProvider.java @@ -113,6 +113,7 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMin import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; @@ -211,6 +212,7 @@ import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceM import org.apache.skywalking.apm.collector.storage.es.dao.srmp.ServiceReferenceMonthMetricEsPersistenceDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationComponentEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationMappingEsUIDAO; +import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationMetricEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.ApplicationReferenceMetricEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.CpuMetricEsUIDAO; import org.apache.skywalking.apm.collector.storage.es.dao.ui.GCMetricEsUIDAO; @@ -407,6 +409,7 @@ public class StorageModuleEsProvider extends ModuleProvider { this.registerServiceImplementation(IInstanceMetricUIDAO.class, new InstanceMetricEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingEsUIDAO(elasticSearchClient)); + this.registerServiceImplementation(IApplicationMetricUIDAO.class, new ApplicationMetricEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(ISegmentDurationUIDAO.class, new SegmentDurationEsUIDAO(elasticSearchClient)); this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentEsUIDAO(elasticSearchClient)); diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationMetricEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationMetricEsUIDAO.java new file mode 100644 index 000000000..0f67efc23 --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ApplicationMetricEsUIDAO.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.es.dao.ui; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.table.application.ApplicationMetricTable; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS; +import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder; +import org.elasticsearch.action.search.SearchRequestBuilder; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.BoolQueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.script.Script; +import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.bucket.terms.Terms; +import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; +import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders; + +/** + * @author peng-yongsheng + */ +public class ApplicationMetricEsUIDAO extends EsDAO implements IApplicationMetricUIDAO { + + public ApplicationMetricEsUIDAO(ElasticSearchClient client) { + super(client); + } + + private static final String AVG_TPS = "avg_tps"; + + @Override + public List getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond, + int topN, + MetricSource metricSource) { + String tableName = TimePyramidTableNameBuilder.build(step, ApplicationMetricTable.TABLE); + + SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName); + searchRequestBuilder.setTypes(ApplicationMetricTable.TABLE_TYPE); + searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); + + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.rangeQuery(ApplicationMetricTable.COLUMN_TIME_BUCKET).gte(start).lte(end)); + boolQuery.must().add(QueryBuilders.termQuery(ApplicationMetricTable.COLUMN_SOURCE_VALUE, metricSource.getValue())); + + searchRequestBuilder.setQuery(boolQuery); + searchRequestBuilder.setSize(0); + + TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(ApplicationMetricTable.COLUMN_APPLICATION_ID).field(ApplicationMetricTable.COLUMN_APPLICATION_ID).size(topN); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS)); + aggregationBuilder.subAggregation(AggregationBuilders.sum(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS).field(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS)); + + Map bucketsPathsMap = new HashMap<>(); + bucketsPathsMap.put(ApplicationMetricTable.COLUMN_TRANSACTION_CALLS, ApplicationMetricTable.COLUMN_TRANSACTION_CALLS); + bucketsPathsMap.put(ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS); + + String idOrCode = "(params." + ApplicationMetricTable.COLUMN_TRANSACTION_CALLS + " - params." + ApplicationMetricTable.COLUMN_TRANSACTION_ERROR_CALLS + ")" + + " / " + + "(" + betweenSecond + ")"; + Script script = new Script(idOrCode); + aggregationBuilder.subAggregation(PipelineAggregatorBuilders.bucketScript(AVG_TPS, bucketsPathsMap, script)); + + searchRequestBuilder.addAggregation(aggregationBuilder); + SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); + + List applicationTPSs = new LinkedList<>(); + Terms serviceIdTerms = searchResponse.getAggregations().get(ApplicationMetricTable.COLUMN_APPLICATION_ID); + serviceIdTerms.getBuckets().forEach(serviceIdTerm -> { + int applicationId = serviceIdTerm.getKeyAsNumber().intValue(); + + ApplicationTPS serviceMetric = new ApplicationTPS(); + InternalSimpleValue simpleValue = serviceIdTerm.getAggregations().get(AVG_TPS); + + serviceMetric.setApplicationId(applicationId); + serviceMetric.setTps((int)simpleValue.getValue()); + applicationTPSs.add(serviceMetric); + }); + return applicationTPSs; + } +} diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java index ba2512525..55c3db8a0 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/StorageModuleH2Provider.java @@ -109,6 +109,7 @@ import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMin import org.apache.skywalking.apm.collector.storage.dao.srmp.IServiceReferenceMonthMetricPersistenceDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationComponentUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMappingUIDAO; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationReferenceMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.ICpuMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; @@ -207,6 +208,7 @@ import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceM import org.apache.skywalking.apm.collector.storage.h2.dao.srmp.ServiceReferenceMonthMetricH2PersistenceDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationComponentH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationMappingH2UIDAO; +import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationMetricH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.ApplicationReferenceMetricH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.CpuMetricH2UIDAO; import org.apache.skywalking.apm.collector.storage.h2.dao.ui.GCMetricH2UIDAO; @@ -383,6 +385,7 @@ public class StorageModuleH2Provider extends ModuleProvider { this.registerServiceImplementation(IInstanceMetricUIDAO.class, new InstanceMetricH2UIDAO(h2Client)); this.registerServiceImplementation(IApplicationComponentUIDAO.class, new ApplicationComponentH2UIDAO(h2Client)); this.registerServiceImplementation(IApplicationMappingUIDAO.class, new ApplicationMappingH2UIDAO(h2Client)); + this.registerServiceImplementation(IApplicationMetricUIDAO.class, new ApplicationMetricH2UIDAO(h2Client)); this.registerServiceImplementation(IApplicationReferenceMetricUIDAO.class, new ApplicationReferenceMetricH2UIDAO(h2Client)); this.registerServiceImplementation(ISegmentDurationUIDAO.class, new SegmentDurationH2UIDAO(h2Client)); this.registerServiceImplementation(ISegmentUIDAO.class, new SegmentH2UIDAO(h2Client)); diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationMetricH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationMetricH2UIDAO.java new file mode 100644 index 000000000..d055b60dc --- /dev/null +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ApplicationMetricH2UIDAO.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.apache.skywalking.apm.collector.storage.h2.dao.ui; + +import java.util.List; +import org.apache.skywalking.apm.collector.client.h2.H2Client; +import org.apache.skywalking.apm.collector.storage.dao.ui.IApplicationMetricUIDAO; +import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO; +import org.apache.skywalking.apm.collector.storage.table.MetricSource; +import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author peng-yongsheng + */ +public class ApplicationMetricH2UIDAO extends H2DAO implements IApplicationMetricUIDAO { + + private final Logger logger = LoggerFactory.getLogger(ApplicationMetricH2UIDAO.class); + + public ApplicationMetricH2UIDAO(H2Client client) { + super(client); + } + + @Override + public List getTopNApplicationThroughput(Step step, long start, long end, long betweenSecond, + int topN, MetricSource metricSource) { + return null; + } +} 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 e424512dd..917146e11 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 @@ -25,16 +25,15 @@ import org.apache.skywalking.apm.collector.core.util.ObjectUtils; import org.apache.skywalking.apm.collector.storage.ui.common.Duration; import org.apache.skywalking.apm.collector.storage.ui.common.Topology; import org.apache.skywalking.apm.collector.storage.ui.overview.AlarmTrend; +import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS; 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.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; import org.apache.skywalking.apm.collector.ui.service.ClusterTopologyService; import org.apache.skywalking.apm.collector.ui.service.NetworkAddressService; -import org.apache.skywalking.apm.collector.ui.service.ServerService; import org.apache.skywalking.apm.collector.ui.service.ServiceNameService; import org.apache.skywalking.apm.collector.ui.utils.DurationUtils; @@ -48,7 +47,6 @@ public class OverViewLayerQuery implements Query { private ApplicationService applicationService; private NetworkAddressService networkAddressService; private ServiceNameService serviceNameService; - private ServerService serverService; private AlarmService alarmService; public OverViewLayerQuery(ModuleManager moduleManager) { @@ -90,13 +88,6 @@ public class OverViewLayerQuery implements Query { return alarmService; } - private ServerService getServerService() { - if (ObjectUtils.isEmpty(serverService)) { - this.serverService = new ServerService(moduleManager); - } - return serverService; - } - public Topology getClusterTopology(Duration duration) throws ParseException { long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart()); long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd()); @@ -135,11 +126,11 @@ public class OverViewLayerQuery implements Query { return getServiceNameService().getSlowService(duration.getStep(), start, end, topN); } - public List getTopNServerThroughput(int applicationId, Duration duration, + public List getTopNApplicationThroughput(Duration duration, int topN) throws ParseException { long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart()); long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd()); - return getServerService().getTopNServerThroughput(applicationId, duration.getStep(), start, end, topN); + return getApplicationService().getTopNApplicationThroughput(duration.getStep(), start, end, topN); } } diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java index 42c094fe8..639a2bfd7 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ApplicationService.java @@ -25,11 +25,13 @@ import org.apache.skywalking.apm.collector.cache.service.ApplicationCacheService 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.IApplicationMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO; import org.apache.skywalking.apm.collector.storage.table.MetricSource; import org.apache.skywalking.apm.collector.storage.ui.application.Application; import org.apache.skywalking.apm.collector.storage.ui.common.Step; +import org.apache.skywalking.apm.collector.storage.ui.overview.ApplicationTPS; import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric; /** @@ -39,12 +41,14 @@ public class ApplicationService { private final IInstanceUIDAO instanceDAO; private final IServiceMetricUIDAO serviceMetricUIDAO; + private final IApplicationMetricUIDAO applicationMetricUIDAO; private final ApplicationCacheService applicationCacheService; private final ServiceNameCacheService serviceNameCacheService; public ApplicationService(ModuleManager moduleManager) { this.instanceDAO = moduleManager.find(StorageModule.NAME).getService(IInstanceUIDAO.class); this.serviceMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IServiceMetricUIDAO.class); + this.applicationMetricUIDAO = moduleManager.find(StorageModule.NAME).getService(IApplicationMetricUIDAO.class); this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class); } @@ -69,4 +73,15 @@ public class ApplicationService { }); return slowServices; } + + public List getTopNApplicationThroughput(Step step, long start, long end, + int topN) throws ParseException { + //TODO + List applicationThroughput = applicationMetricUIDAO.getTopNApplicationThroughput(step, start, end, 1000, topN, MetricSource.Callee); + applicationThroughput.forEach(applicationTPS -> { + String applicationCode = applicationCacheService.getApplicationById(applicationTPS.getApplicationId()).getApplicationCode(); + applicationTPS.setApplicationCode(applicationCode); + }); + return applicationThroughput; + } } diff --git a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java index 12a27420d..ce91185ee 100644 --- a/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java +++ b/apm-collector/apm-collector-ui/collector-ui-jetty-provider/src/main/java/org/apache/skywalking/apm/collector/ui/service/ServerService.java @@ -36,8 +36,6 @@ import org.apache.skywalking.apm.collector.storage.dao.ui.IGCMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceMetricUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IInstanceUIDAO; import org.apache.skywalking.apm.collector.storage.dao.ui.IMemoryMetricUIDAO; -import org.apache.skywalking.apm.collector.storage.table.MetricSource; -import org.apache.skywalking.apm.collector.storage.table.register.Instance; import org.apache.skywalking.apm.collector.storage.ui.common.ResponseTimeTrend; import org.apache.skywalking.apm.collector.storage.ui.common.Step; import org.apache.skywalking.apm.collector.storage.ui.common.ThroughputTrend; @@ -72,18 +70,6 @@ public class ServerService { this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class); } - public List getTopNServerThroughput(int applicationId, Step step, long start, long end, int topN) { - //TODO - List appServerInfos = instanceMetricUIDAO.getTopNServerThroughput(applicationId, step, start, end, 1000, topN, MetricSource.Callee); - appServerInfos.forEach(appServerInfo -> { - Instance instance = instanceUIDAO.getInstance(appServerInfo.getId()); - appServerInfo.setOsInfo(instance.getOsInfo()); - }); - buildAppServerInfo(appServerInfos); - - return appServerInfos; - } - public List searchServer(String keyword, long start, long end) { List serverInfos = instanceUIDAO.searchServer(keyword, start, end); serverInfos.forEach(serverInfo -> {