Provide the getConjecturalApps query.

This commit is contained in:
peng-yongsheng 2018-02-11 18:00:48 +08:00
parent eda2d8141b
commit 508b11dd46
7 changed files with 82 additions and 2 deletions

View File

@ -18,11 +18,15 @@
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.ui.overview.ConjecturalApp;
/**
* @author peng-yongsheng
*/
public interface INetworkAddressUIDAO extends DAO {
int getNumOfSpanLayer(int spanLayer);
List<ConjecturalApp> getConjecturalApps();
}

View File

@ -22,9 +22,18 @@ package org.apache.skywalking.apm.collector.storage.ui.overview;
* @author peng-yongsheng
*/
public class ConjecturalApp {
private int id;
private String name;
private int num;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}

View File

@ -18,6 +18,7 @@
package org.apache.skywalking.apm.collector.storage.ui.overview;
import java.util.LinkedList;
import java.util.List;
/**
@ -26,6 +27,10 @@ import java.util.List;
public class ConjecturalAppBrief {
private List<ConjecturalApp> apps;
public ConjecturalAppBrief() {
this.apps = new LinkedList<>();
}
public List<ConjecturalApp> getApps() {
return apps;
}

View File

@ -18,14 +18,21 @@
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
import java.util.LinkedList;
import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddressTable;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp;
import org.apache.skywalking.apm.network.proto.SpanLayer;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
/**
* @author peng-yongsheng
@ -46,4 +53,31 @@ public class NetworkAddressEsUIDAO extends EsDAO implements INetworkAddressUIDAO
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
return (int)searchResponse.getHits().getTotalHits();
}
@Override public List<ConjecturalApp> getConjecturalApps() {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(NetworkAddressTable.TABLE);
searchRequestBuilder.setTypes(NetworkAddressTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
int[] spanLayers = new int[] {SpanLayer.Database_VALUE, SpanLayer.Cache_VALUE, SpanLayer.MQ_VALUE};
searchRequestBuilder.setQuery(QueryBuilders.termsQuery(NetworkAddressTable.COLUMN_SPAN_LAYER, spanLayers));
searchRequestBuilder.setSize(0);
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms(NetworkAddressTable.COLUMN_SERVER_TYPE).field(NetworkAddressTable.COLUMN_SERVER_TYPE).size(100);
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<ConjecturalApp> conjecturalApps = new LinkedList<>();
Terms serverTypeTerms = searchResponse.getAggregations().get(NetworkAddressTable.COLUMN_SERVER_TYPE);
serverTypeTerms.getBuckets().forEach(serverTypeTerm -> {
int serverType = serverTypeTerm.getKeyAsNumber().intValue();
ConjecturalApp conjecturalApp = new ConjecturalApp();
conjecturalApp.setId(serverType);
conjecturalApp.setNum((int)serverTypeTerm.getDocCount());
conjecturalApps.add(conjecturalApp);
});
return conjecturalApps;
}
}

View File

@ -20,12 +20,14 @@ package org.apache.skywalking.apm.collector.storage.h2.dao.ui;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.apache.skywalking.apm.collector.client.h2.H2Client;
import org.apache.skywalking.apm.collector.client.h2.H2ClientException;
import org.apache.skywalking.apm.collector.storage.base.sql.SqlBuilder;
import org.apache.skywalking.apm.collector.storage.dao.ui.INetworkAddressUIDAO;
import org.apache.skywalking.apm.collector.storage.h2.base.dao.H2DAO;
import org.apache.skywalking.apm.collector.storage.table.register.NetworkAddressTable;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalApp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -54,4 +56,8 @@ public class NetworkAddressH2UIDAO extends H2DAO implements INetworkAddressUIDAO
}
return 0;
}
@Override public List<ConjecturalApp> getConjecturalApps() {
return null;
}
}

View File

@ -115,8 +115,11 @@ public class OverViewLayerQuery implements Query {
return getAlarmService().getApplicationAlarmTrend(duration.getStep(), start, end);
}
public ConjecturalAppBrief getConjecturalApps(Duration duration) {
return null;
public ConjecturalAppBrief getConjecturalApps(Duration duration) throws ParseException {
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getStart());
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(duration.getStep(), duration.getEnd());
return getApplicationService().getConjecturalApps(duration.getStep(), start, end);
}
public List<ServiceMetric> getTopNSlowService(Duration duration, int topN) throws ParseException {

View File

@ -27,11 +27,15 @@ 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.INetworkAddressUIDAO;
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.table.register.ServerTypeDefine;
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.overview.ConjecturalApp;
import org.apache.skywalking.apm.collector.storage.ui.overview.ConjecturalAppBrief;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
/**
@ -42,6 +46,7 @@ public class ApplicationService {
private final IInstanceUIDAO instanceDAO;
private final IServiceMetricUIDAO serviceMetricUIDAO;
private final IApplicationMetricUIDAO applicationMetricUIDAO;
private final INetworkAddressUIDAO networkAddressUIDAO;
private final ApplicationCacheService applicationCacheService;
private final ServiceNameCacheService serviceNameCacheService;
@ -49,6 +54,7 @@ public class ApplicationService {
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.networkAddressUIDAO = moduleManager.find(StorageModule.NAME).getService(INetworkAddressUIDAO.class);
this.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
}
@ -84,4 +90,17 @@ public class ApplicationService {
});
return applicationThroughput;
}
public ConjecturalAppBrief getConjecturalApps(Step step, long start, long end) throws ParseException {
List<ConjecturalApp> conjecturalApps = networkAddressUIDAO.getConjecturalApps();
conjecturalApps.forEach(conjecturalApp -> {
String name = ServerTypeDefine.getInstance().getServerType(conjecturalApp.getId());
conjecturalApp.setName(name);
});
ConjecturalAppBrief conjecturalAppBrief = new ConjecturalAppBrief();
conjecturalAppBrief.setApps(conjecturalApps);
return conjecturalAppBrief;
}
}