提交 a8171978 编写于 作者: P peng-yongsheng

Provide the getSlowService query.

上级 90c820d1
......@@ -24,6 +24,7 @@ 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.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
/**
......@@ -36,4 +37,7 @@ public interface IServiceMetricUIDAO extends DAO {
List<Node> getServicesMetric(Step step, long startTime, long endTime,
MetricSource metricSource, Collection<Integer> serviceIds);
List<ServiceMetric> getSlowService(int applicationId, Step step, long start, long end,
Integer top, MetricSource metricSource);
}
......@@ -25,7 +25,7 @@ import java.util.List;
*/
public class Alarm {
private List<AlarmItem> items;
private Integer count;
private int total;
public List<AlarmItem> getItems() {
return items;
......@@ -35,11 +35,11 @@ public class Alarm {
this.items = items;
}
public Integer getCount() {
return count;
public int getTotal() {
return total;
}
public void setCount(Integer count) {
this.count = count;
public void setTotal(int total) {
this.total = total;
}
}
......@@ -25,6 +25,6 @@ public class AlarmItem {
private String title;
private String content;
private String startTime;
private AlarmType alertType;
private AlarmType alarmType;
private CauseType causeType;
}
/*
* 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.service;
/**
* @author peng-yongsheng
*/
public class ServiceMetric {
private int id;
private String name;
private int avgResponseTime;
private int tps;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAvgResponseTime() {
return avgResponseTime;
}
public void setAvgResponseTime(int avgResponseTime) {
this.avgResponseTime = avgResponseTime;
}
public int getTps() {
return tps;
}
public void setTps(int tps) {
this.tps = tps;
}
}
......@@ -19,8 +19,10 @@
package org.apache.skywalking.apm.collector.storage.es.dao.ui;
import java.util.Collection;
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.core.util.Const;
import org.apache.skywalking.apm.collector.storage.dao.ui.IServiceMetricUIDAO;
......@@ -29,6 +31,7 @@ import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceMetric;
import org.apache.skywalking.apm.collector.storage.ui.service.ServiceNode;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.apache.skywalking.apm.collector.storage.utils.TimePyramidTableNameBuilder;
......@@ -40,16 +43,21 @@ 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.metrics.sum.Sum;
import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders;
/**
* @author peng-yongsheng
*/
public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
private static final String AVG_DURATION = "avg_duration";
public ServiceMetricEsUIDAO(ElasticSearchClient client) {
super(client);
}
......@@ -143,4 +151,56 @@ public class ServiceMetricEsUIDAO extends EsDAO implements IServiceMetricUIDAO {
});
return nodes;
}
@Override public List<ServiceMetric> getSlowService(int applicationId, Step step, long start, long end, Integer top,
MetricSource metricSource) {
String tableName = TimePyramidTableNameBuilder.build(step, ServiceMetricTable.TABLE);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(tableName);
searchRequestBuilder.setTypes(ServiceMetricTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
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));
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);
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));
aggregationBuilder.subAggregation(AggregationBuilders.sum(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM).field(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM));
Map<String, String> bucketsPathsMap = new HashMap<>();
bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_CALLS, ServiceMetricTable.COLUMN_TRANSACTION_CALLS);
bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS, ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS);
bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM, ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM);
bucketsPathsMap.put(ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM, ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM);
String idOrCode = "(params." + ServiceMetricTable.COLUMN_TRANSACTION_DURATION_SUM + " - params." + ServiceMetricTable.COLUMN_TRANSACTION_ERROR_DURATION_SUM + ")"
+ " / "
+ "(params." + ServiceMetricTable.COLUMN_TRANSACTION_CALLS + " - params." + ServiceMetricTable.COLUMN_TRANSACTION_ERROR_CALLS + ")";
Script script = new Script(idOrCode);
aggregationBuilder.subAggregation(PipelineAggregatorBuilders.bucketScript(AVG_DURATION, bucketsPathsMap, script));
searchRequestBuilder.addAggregation(aggregationBuilder);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<ServiceMetric> serviceMetrics = new LinkedList<>();
Terms serviceIdTerms = searchResponse.getAggregations().get(ServiceMetricTable.COLUMN_SERVICE_ID);
serviceIdTerms.getBuckets().forEach(serviceIdTerm -> {
int serviceId = serviceIdTerm.getKeyAsNumber().intValue();
ServiceMetric serviceMetric = new ServiceMetric();
InternalSimpleValue simpleValue = serviceIdTerm.getAggregations().get(AVG_DURATION);
serviceMetric.setId(serviceId);
serviceMetric.setAvgResponseTime((int)simpleValue.getValue());
serviceMetrics.add(serviceMetric);
});
return serviceMetrics;
}
}
......@@ -33,6 +33,7 @@ import org.apache.skywalking.apm.collector.storage.table.MetricSource;
import org.apache.skywalking.apm.collector.storage.table.service.ServiceMetricTable;
import org.apache.skywalking.apm.collector.storage.ui.common.Node;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
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.storage.utils.TimePyramidTableNameBuilder;
import org.slf4j.Logger;
......@@ -106,9 +107,13 @@ public class ServiceMetricH2UIDAO extends H2DAO implements IServiceMetricUIDAO {
return trends;
}
@Override
public List<Node> getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource,
@Override public List<Node> getServicesMetric(Step step, long startTime, long endTime, MetricSource metricSource,
Collection<Integer> serviceIds) {
return null;
}
@Override public List<ServiceMetric> getSlowService(int applicationId, Step step, long start, long end, Integer top,
MetricSource metricSource) {
return null;
}
}
......@@ -29,9 +29,9 @@ import org.apache.skywalking.apm.collector.storage.ui.common.Pagination;
*/
public class AlarmQuery implements Query {
public Alarm loadAlertList(String keyword, AlarmType alarmType, Duration duration, Pagination pagination) {
public Alarm loadAlarmList(String keyword, AlarmType alarmType, Duration duration, Pagination paging) {
Alarm alarm = new Alarm();
alarm.setCount(0);
alarm.setTotal(0);
return alarm;
}
}
......@@ -26,7 +26,7 @@ import org.apache.skywalking.apm.collector.storage.ui.application.Application;
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.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.ApplicationService;
import org.apache.skywalking.apm.collector.ui.service.ApplicationTopologyService;
......@@ -73,8 +73,11 @@ public class ApplicationQuery implements Query {
return getApplicationTopologyService().getApplicationTopology(duration.getStep(), applicationId, start, end);
}
public List<ServiceInfo> getSlowService(int applicationId, Duration duration, Integer top) {
return null;
public List<ServiceMetric> getSlowService(int applicationId, Duration duration, Integer top) throws ParseException {
long start = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getStart());
long end = DurationUtils.INSTANCE.exchangeToTimeBucket(duration.getEnd());
return getApplicationService().getSlowService(applicationId, duration.getStep(), start, end, top);
}
public List<AppServerInfo> getServerThroughput(int applicationId, Duration duration, Integer top) {
......
......@@ -18,13 +18,19 @@
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.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.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.service.ServiceMetric;
/**
* @author peng-yongsheng
......@@ -32,11 +38,15 @@ import org.apache.skywalking.apm.collector.storage.ui.application.Application;
public class ApplicationService {
private final IInstanceUIDAO instanceDAO;
private final IServiceMetricUIDAO serviceMetricUIDAO;
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.applicationCacheService = moduleManager.find(CacheModule.NAME).getService(ApplicationCacheService.class);
this.serviceNameCacheService = moduleManager.find(CacheModule.NAME).getService(ServiceNameCacheService.class);
}
public List<Application> getApplications(long startTime, long endTime, int... applicationIds) {
......@@ -48,4 +58,15 @@ public class ApplicationService {
});
return applications;
}
public List<ServiceMetric> getSlowService(int applicationId, Step step, long start, long end,
Integer top) throws ParseException {
List<ServiceMetric> slowServices = serviceMetricUIDAO.getSlowService(applicationId, step, start, end, top, MetricSource.Callee);
slowServices.forEach(slowService -> {
slowService.setName(serviceNameCacheService.get(slowService.getId()).getServiceName());
//TODO
slowService.setTps(1);
});
return slowServices;
}
}
......@@ -43,6 +43,6 @@ type Application {
extend type Query {
getAllApplication(duration: Duration!): [Application!]!
getApplicationTopology(applicationId: ID!, duration: Duration!): Topology
getSlowService(applicationId: ID!, duration: Duration!, top: Int!): [ServiceInfo!]!
getSlowService(applicationId: ID!, duration: Duration!, top: Int!): [ServiceMetric!]!
getServerThroughput(applicationId: ID!, duration: Duration!, top: Int!): [AppServerInfo!]!
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册