use of org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief in project incubator-skywalking by apache.
the class SegmentTopService method loadTop.
public TraceBrief loadTop(long startSecondTimeBucket, long endSecondTimeBucket, long minDuration, long maxDuration, String operationName, String traceId, int applicationId, int limit, int from) {
logger.debug("startSecondTimeBucket: {}, endSecondTimeBucket: {}, minDuration: {}, " + "maxDuration: {}, operationName: {}, traceId: {}, applicationId: {}, limit: {}, from: {}", startSecondTimeBucket, endSecondTimeBucket, minDuration, maxDuration, operationName, traceId, applicationId, limit, from);
TraceBrief traceBrief;
if (StringUtils.isNotEmpty(traceId)) {
List<String> segmentIds = globalTraceUIDAO.getSegmentIds(traceId);
traceBrief = segmentDurationUIDAO.loadTop(startSecondTimeBucket, endSecondTimeBucket, minDuration, maxDuration, operationName, applicationId, limit, from, segmentIds.toArray(new String[0]));
} else {
traceBrief = segmentDurationUIDAO.loadTop(startSecondTimeBucket, endSecondTimeBucket, minDuration, maxDuration, operationName, applicationId, limit, from);
}
traceBrief.getTraces().forEach(trace -> {
List<String> traceIds = globalTraceUIDAO.getGlobalTraceId(trace.getSegmentId());
trace.getTraceIds().addAll(traceIds);
});
return traceBrief;
}
use of org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief in project incubator-skywalking by apache.
the class SegmentDurationEsUIDAO method loadTop.
@Override
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);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
searchRequestBuilder.setQuery(boolQueryBuilder);
List<QueryBuilder> mustQueryList = boolQueryBuilder.must();
if (startSecondTimeBucket != 0 && endSecondTimeBucket != 0) {
// TODO second
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) {
rangeQueryBuilder.gte(minDuration);
}
if (maxDuration != 0) {
rangeQueryBuilder.lte(maxDuration);
}
boolQueryBuilder.must().add(rangeQueryBuilder);
}
if (StringUtils.isNotEmpty(operationName)) {
mustQueryList.add(QueryBuilders.matchQuery(SegmentDurationTable.COLUMN_SERVICE_NAME, operationName));
}
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));
}
searchRequestBuilder.setSize(limit);
searchRequestBuilder.setFrom(from);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
TraceBrief traceBrief = new TraceBrief();
traceBrief.setTotal((int) searchResponse.getHits().totalHits);
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
BasicTrace basicTrace = new BasicTrace();
basicTrace.setSegmentId((String) searchHit.getSource().get(SegmentDurationTable.COLUMN_SEGMENT_ID));
basicTrace.setStart(((Number) searchHit.getSource().get(SegmentDurationTable.COLUMN_START_TIME)).longValue());
basicTrace.setOperationName((String) searchHit.getSource().get(SegmentDurationTable.COLUMN_SERVICE_NAME));
basicTrace.setDuration(((Number) searchHit.getSource().get(SegmentDurationTable.COLUMN_DURATION)).intValue());
basicTrace.setError(BooleanUtils.valueToBoolean(((Number) searchHit.getSource().get(SegmentDurationTable.COLUMN_IS_ERROR)).intValue()));
traceBrief.getTraces().add(basicTrace);
}
return traceBrief;
}
use of org.apache.skywalking.apm.collector.storage.ui.trace.TraceBrief in project incubator-skywalking by apache.
the class SegmentDurationH2UIDAO method loadTop.
@Override
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(startSecondTimeBucket);
params.add(endSecondTimeBucket);
int paramIndex = 1;
if (minDuration != -1 || maxDuration != -1) {
if (minDuration != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} >= ?";
params.add(minDuration);
columns.add(SegmentDurationTable.COLUMN_DURATION);
}
if (maxDuration != -1) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} <= ?";
params.add(maxDuration);
columns.add(SegmentDurationTable.COLUMN_DURATION);
}
}
if (StringUtils.isNotEmpty(operationName)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(operationName);
columns.add(SegmentDurationTable.COLUMN_SERVICE_NAME);
}
if (StringUtils.isNotEmpty(segmentIds)) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(segmentIds);
columns.add(SegmentDurationTable.COLUMN_TRACE_ID);
}
if (applicationId != 0) {
paramIndex++;
sql = sql + " and {" + paramIndex + "} = ?";
params.add(applicationId);
columns.add(SegmentDurationTable.COLUMN_APPLICATION_ID);
}
sql = sql + " limit " + from + "," + limit;
sql = SqlBuilder.buildSql(sql, columns);
Object[] p = params.toArray(new Object[0]);
TraceBrief traceBrief = new TraceBrief();
int cnt = 0;
try (ResultSet rs = client.executeQuery(sql, p)) {
while (rs.next()) {
BasicTrace basicTrace = new BasicTrace();
basicTrace.setSegmentId(rs.getString(SegmentDurationTable.COLUMN_SEGMENT_ID));
basicTrace.setDuration(rs.getInt(SegmentDurationTable.COLUMN_DURATION));
basicTrace.setStart(rs.getLong(SegmentDurationTable.COLUMN_START_TIME));
basicTrace.setOperationName(rs.getString(SegmentDurationTable.COLUMN_SERVICE_NAME));
basicTrace.setError(BooleanUtils.valueToBoolean(rs.getInt(SegmentDurationTable.COLUMN_IS_ERROR)));
traceBrief.getTraces().add(basicTrace);
cnt++;
}
} catch (SQLException | H2ClientException e) {
logger.error(e.getMessage(), e);
}
traceBrief.setTotal(cnt);
return traceBrief;
}
Aggregations