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

queryBasicTraces:

1. Query segment id from global trace table by trace id.
2. Query BasicTrace from segment duration table by segment id.
上级 ce3bff89
......@@ -25,6 +25,6 @@ import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief;
* @author peng-yongsheng
*/
public interface ISegmentDurationUIDAO extends DAO {
TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName,
int applicationId, String traceId, int limit, int from);
TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration,
String operationName, int applicationId, int limit, int from, String... segmentIds);
}
......@@ -22,31 +22,31 @@ package org.apache.skywalking.apm.collector.storage.ui.common;
* @author peng-yongsheng
*/
public class Pagination {
private Integer pageNum;
private Integer pageSize;
private Boolean needTotal;
private int pageNum;
private int pageSize;
private boolean needTotal;
public Integer getPageNum() {
public int getPageNum() {
return pageNum;
}
public void setPageNum(Integer pageNum) {
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public Integer getPageSize() {
public int getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public Boolean getNeedTotal() {
public boolean isNeedTotal() {
return needTotal;
}
public void setNeedTotal(Boolean needTotal) {
public void setNeedTotal(boolean needTotal) {
this.needTotal = needTotal;
}
}
......@@ -21,6 +21,7 @@ package org.apache.skywalking.apm.collector.storage.es.dao.ui;
import java.util.List;
import org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient;
import org.apache.skywalking.apm.collector.core.util.BooleanUtils;
import org.apache.skywalking.apm.collector.core.util.CollectionUtils;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO;
import org.apache.skywalking.apm.collector.storage.es.base.dao.EsDAO;
......@@ -46,8 +47,8 @@ public class SegmentDurationEsUIDAO extends EsDAO implements ISegmentDurationUID
}
@Override
public TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName,
int applicationId, String traceId, int limit, int from) {
public TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration,
String operationName, int applicationId, int limit, int from, String... segmentIds) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(SegmentDurationTable.TABLE);
searchRequestBuilder.setTypes(SegmentDurationTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
......@@ -55,7 +56,10 @@ public class SegmentDurationEsUIDAO extends EsDAO implements ISegmentDurationUID
searchRequestBuilder.setQuery(boolQueryBuilder);
List<QueryBuilder> mustQueryList = boolQueryBuilder.must();
mustQueryList.add(QueryBuilders.rangeQuery(SegmentDurationTable.COLUMN_TIME_BUCKET).gte(startTime).lte(endTime));
if (startSecondTimeBucket != 0 && endSecondTimeBucket != 0) {
mustQueryList.add(QueryBuilders.rangeQuery(SegmentDurationTable.COLUMN_TIME_BUCKET).gte(startSecondTimeBucket).lte(endSecondTimeBucket));
}
if (minDuration != 0 || maxDuration != 0) {
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(SegmentDurationTable.COLUMN_DURATION);
if (minDuration != 0) {
......@@ -69,8 +73,8 @@ public class SegmentDurationEsUIDAO extends EsDAO implements ISegmentDurationUID
if (StringUtils.isNotEmpty(operationName)) {
mustQueryList.add(QueryBuilders.matchQuery(SegmentDurationTable.COLUMN_SERVICE_NAME, operationName));
}
if (StringUtils.isNotEmpty(traceId)) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentDurationTable.COLUMN_SEGMENT_ID, traceId));
if (CollectionUtils.isNotEmpty(segmentIds)) {
boolQueryBuilder.must().add(QueryBuilders.termsQuery(SegmentDurationTable.COLUMN_SEGMENT_ID, segmentIds));
}
if (applicationId != 0) {
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentDurationTable.COLUMN_APPLICATION_ID, applicationId));
......
......@@ -47,16 +47,16 @@ public class SegmentDurationH2UIDAO extends H2DAO implements ISegmentDurationUID
}
@Override
public TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName,
int applicationId, String traceId, int limit, int from) {
public TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration,
String operationName, int applicationId, int limit, int from, String... segmentIds) {
H2Client client = getClient();
String sql = "select * from {0} where {1} >= ? and {1} <= ?";
List<Object> params = new ArrayList<>();
List<Object> columns = new ArrayList<>();
columns.add(SegmentDurationTable.TABLE);
columns.add(SegmentDurationTable.COLUMN_TIME_BUCKET);
params.add(startTime);
params.add(endTime);
params.add(startSecondTimeBucket);
params.add(endSecondTimeBucket);
int paramIndex = 1;
if (minDuration != -1 || maxDuration != -1) {
if (minDuration != -1) {
......@@ -78,10 +78,10 @@ public class SegmentDurationH2UIDAO extends H2DAO implements ISegmentDurationUID
params.add(operationName);
columns.add(SegmentDurationTable.COLUMN_SERVICE_NAME);
}
if (StringUtils.isNotEmpty(traceId)) {
if (StringUtils.isNotEmpty(segmentIds)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(traceId);
params.add(segmentIds);
columns.add(SegmentDurationTable.COLUMN_TRACE_ID);
}
if (applicationId != 0) {
......
......@@ -19,8 +19,11 @@
package org.apache.skywalking.apm.collector.ui.query;
import java.text.ParseException;
import org.apache.skywalking.apm.collector.core.UnexpectedException;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.Const;
import org.apache.skywalking.apm.collector.core.util.ObjectUtils;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.storage.ui.trace.Trace;
import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief;
import org.apache.skywalking.apm.collector.storage.ui.trace.TraceQueryCondition;
......@@ -57,18 +60,27 @@ public class TraceQuery implements Query {
}
public TraceBrief queryBasicTraces(TraceQueryCondition condition) throws ParseException {
long start = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getStart());
long end = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getEnd());
long startSecondTimeBucket = 0;
long endSecondTimeBucket = 0;
String traceId = Const.EMPTY_STRING;
if (ObjectUtils.isNotEmpty(condition.getQueryDuration())) {
startSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getStart());
endSecondTimeBucket = DurationUtils.INSTANCE.durationToSecondTimeBucket(condition.getQueryDuration().getStep(), condition.getQueryDuration().getEnd());
} else if (StringUtils.isNotEmpty(condition.getTraceId())) {
traceId = condition.getTraceId();
} else {
throw new UnexpectedException("The condition must contains either queryDuration or traceId.");
}
long minDuration = condition.getMinTraceDuration();
long maxDuration = condition.getMaxTraceDuration();
String operationName = condition.getOperationName();
String traceId = condition.getTraceId();
int applicationId = condition.getApplicationId();
int limit = condition.getPaging().getPageSize();
int from = condition.getPaging().getPageSize() * condition.getPaging().getPageNum();
return getSegmentTopService().loadTop(start, end, minDuration, maxDuration, operationName, traceId, applicationId, limit, from);
return getSegmentTopService().loadTop(startSecondTimeBucket, endSecondTimeBucket, minDuration, maxDuration, operationName, traceId, applicationId, limit, from);
}
public Trace queryTrace(String traceId) {
......
......@@ -18,8 +18,11 @@
package org.apache.skywalking.apm.collector.ui.service;
import java.util.List;
import org.apache.skywalking.apm.collector.core.module.ModuleManager;
import org.apache.skywalking.apm.collector.core.util.StringUtils;
import org.apache.skywalking.apm.collector.storage.StorageModule;
import org.apache.skywalking.apm.collector.storage.dao.ui.IGlobalTraceUIDAO;
import org.apache.skywalking.apm.collector.storage.dao.ui.ISegmentDurationUIDAO;
import org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief;
import org.slf4j.Logger;
......@@ -33,15 +36,26 @@ public class SegmentTopService {
private final Logger logger = LoggerFactory.getLogger(SegmentTopService.class);
private final ISegmentDurationUIDAO segmentDurationUIDAO;
private final IGlobalTraceUIDAO globalTraceUIDAO;
public SegmentTopService(ModuleManager moduleManager) {
this.segmentDurationUIDAO = moduleManager.find(StorageModule.NAME).getService(ISegmentDurationUIDAO.class);
this.globalTraceUIDAO = moduleManager.find(StorageModule.NAME).getService(IGlobalTraceUIDAO.class);
}
public TraceBrief loadTop(long startTime, long endTime, long minDuration, long maxDuration, String operationName,
public TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration,
String operationName,
String traceId, int applicationId, int limit, int from) {
logger.debug("startTime: {}, endTime: {}, minDuration: {}, maxDuration: {}, operationName: {}, traceId: {}, applicationId: {}, limit: {}, from: {}", startTime, endTime, minDuration, maxDuration, operationName, traceId, applicationId, limit, from);
return segmentDurationUIDAO.loadTop(startTime, endTime, minDuration, maxDuration, operationName, applicationId, traceId, limit, from);
logger.debug("startSecondTimeBucket: {}, endSecondTimeBucket: {}, minDuration: {}, " +
"maxDuration: {}, operationName: {}, traceId: {}, applicationId: {}, limit: {}, from: {}",
startSecondTimeBucket, endSecondTimeBucket, minDuration,
maxDuration, operationName, traceId, applicationId, limit, from);
if (StringUtils.isNotEmpty(traceId)) {
List<String> segmentIds = globalTraceUIDAO.getSegmentIds(traceId);
return segmentDurationUIDAO.loadTop(startSecondTimeBucket, endSecondTimeBucket, minDuration, maxDuration, operationName, applicationId, limit, from, segmentIds.toArray(new String[0]));
} else {
return segmentDurationUIDAO.loadTop(startSecondTimeBucket, endSecondTimeBucket, minDuration, maxDuration, operationName, applicationId, limit, from);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册