Skip to content

Commit ab52bdb

Browse files
authored
Merge branch 'master' into master
2 parents 3dba464 + 02f939a commit ab52bdb

File tree

11 files changed

+70
-18
lines changed

11 files changed

+70
-18
lines changed

apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/SegmentCostSpanListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void parseFirst(SpanObject spanObject, int applicationId, int application
3838
public void parseEntry(SpanObject spanObject, int applicationId, int applicationInstanceId, String segmentId) {
3939
SegmentCostDataDefine.SegmentCost segmentCost = new SegmentCostDataDefine.SegmentCost();
4040
segmentCost.setSegmentId(segmentId);
41+
segmentCost.setApplicationId(applicationId);
4142
segmentCost.setCost(spanObject.getEndTime() - spanObject.getStartTime());
4243
segmentCost.setStartTime(spanObject.getStartTime());
4344
segmentCost.setEndTime(spanObject.getEndTime());

apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/dao/SegmentCostEsDAO.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import java.util.Map;
55
import org.elasticsearch.action.index.IndexRequestBuilder;
66
import org.elasticsearch.action.update.UpdateRequestBuilder;
7+
import org.skywalking.apm.collector.core.stream.Data;
8+
import org.skywalking.apm.collector.storage.define.DataDefine;
79
import org.skywalking.apm.collector.storage.define.segment.SegmentCostTable;
810
import org.skywalking.apm.collector.storage.elasticsearch.dao.EsDAO;
911
import org.skywalking.apm.collector.stream.worker.impl.dao.IPersistenceDAO;
10-
import org.skywalking.apm.collector.core.stream.Data;
11-
import org.skywalking.apm.collector.storage.define.DataDefine;
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

@@ -31,6 +31,7 @@ public class SegmentCostEsDAO extends EsDAO implements ISegmentCostDAO, IPersist
3131
logger.debug("segment cost prepareBatchInsert, id: {}", data.getDataString(0));
3232
Map<String, Object> source = new HashMap<>();
3333
source.put(SegmentCostTable.COLUMN_SEGMENT_ID, data.getDataString(1));
34+
source.put(SegmentCostTable.COLUMN_APPLICATION_ID, data.getDataInteger(0));
3435
source.put(SegmentCostTable.COLUMN_SERVICE_NAME, data.getDataString(2));
3536
source.put(SegmentCostTable.COLUMN_COST, data.getDataLong(0));
3637
source.put(SegmentCostTable.COLUMN_START_TIME, data.getDataLong(1));

apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/define/SegmentCostEsTableDefine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public SegmentCostEsTableDefine() {
1919

2020
@Override public void initialize() {
2121
addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, ElasticSearchColumnDefine.Type.Keyword.name()));
22+
addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, ElasticSearchColumnDefine.Type.Integer.name()));
2223
addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, ElasticSearchColumnDefine.Type.Text.name()));
2324
addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_COST, ElasticSearchColumnDefine.Type.Long.name()));
2425
addColumn(new ElasticSearchColumnDefine(SegmentCostTable.COLUMN_START_TIME, ElasticSearchColumnDefine.Type.Long.name()));

apm-collector/apm-collector-agentstream/src/main/java/org/skywalking/apm/collector/agentstream/worker/segment/cost/define/SegmentCostH2TableDefine.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.skywalking.apm.collector.agentstream.worker.segment.cost.define;
22

3+
import org.skywalking.apm.collector.storage.define.segment.SegmentCostTable;
34
import org.skywalking.apm.collector.storage.h2.define.H2ColumnDefine;
45
import org.skywalking.apm.collector.storage.h2.define.H2TableDefine;
5-
import org.skywalking.apm.collector.storage.define.segment.SegmentCostTable;
66

77
/**
88
* @author pengys5
@@ -16,6 +16,7 @@ public SegmentCostH2TableDefine() {
1616
@Override public void initialize() {
1717
addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_ID, H2ColumnDefine.Type.Varchar.name()));
1818
addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SEGMENT_ID, H2ColumnDefine.Type.Varchar.name()));
19+
addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_APPLICATION_ID, H2ColumnDefine.Type.Int.name()));
1920
addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_SERVICE_NAME, H2ColumnDefine.Type.Varchar.name()));
2021
addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_COST, H2ColumnDefine.Type.Bigint.name()));
2122
addColumn(new H2ColumnDefine(SegmentCostTable.COLUMN_START_TIME, H2ColumnDefine.Type.Bigint.name()));

apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/define/segment/SegmentCostDataDefine.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@
1515
public class SegmentCostDataDefine extends DataDefine {
1616

1717
@Override protected int initialCapacity() {
18-
return 8;
18+
return 9;
1919
}
2020

2121
@Override protected void attributeDefine() {
2222
addAttribute(0, new Attribute(SegmentCostTable.COLUMN_ID, AttributeType.STRING, new NonOperation()));
2323
addAttribute(1, new Attribute(SegmentCostTable.COLUMN_SEGMENT_ID, AttributeType.STRING, new CoverOperation()));
24-
addAttribute(2, new Attribute(SegmentCostTable.COLUMN_SERVICE_NAME, AttributeType.STRING, new CoverOperation()));
25-
addAttribute(3, new Attribute(SegmentCostTable.COLUMN_COST, AttributeType.LONG, new CoverOperation()));
26-
addAttribute(4, new Attribute(SegmentCostTable.COLUMN_START_TIME, AttributeType.LONG, new CoverOperation()));
27-
addAttribute(5, new Attribute(SegmentCostTable.COLUMN_END_TIME, AttributeType.LONG, new CoverOperation()));
28-
addAttribute(6, new Attribute(SegmentCostTable.COLUMN_IS_ERROR, AttributeType.BOOLEAN, new CoverOperation()));
29-
addAttribute(7, new Attribute(SegmentCostTable.COLUMN_TIME_BUCKET, AttributeType.LONG, new NonOperation()));
24+
addAttribute(2, new Attribute(SegmentCostTable.COLUMN_APPLICATION_ID, AttributeType.INTEGER, new CoverOperation()));
25+
addAttribute(3, new Attribute(SegmentCostTable.COLUMN_SERVICE_NAME, AttributeType.STRING, new CoverOperation()));
26+
addAttribute(4, new Attribute(SegmentCostTable.COLUMN_COST, AttributeType.LONG, new CoverOperation()));
27+
addAttribute(5, new Attribute(SegmentCostTable.COLUMN_START_TIME, AttributeType.LONG, new CoverOperation()));
28+
addAttribute(6, new Attribute(SegmentCostTable.COLUMN_END_TIME, AttributeType.LONG, new CoverOperation()));
29+
addAttribute(7, new Attribute(SegmentCostTable.COLUMN_IS_ERROR, AttributeType.BOOLEAN, new CoverOperation()));
30+
addAttribute(8, new Attribute(SegmentCostTable.COLUMN_TIME_BUCKET, AttributeType.LONG, new NonOperation()));
3031
}
3132

3233
@Override public Object deserialize(RemoteData remoteData) {
@@ -39,6 +40,7 @@ public class SegmentCostDataDefine extends DataDefine {
3940

4041
public static class SegmentCost implements Transform {
4142
private String id;
43+
private int applicationId;
4244
private String segmentId;
4345
private String serviceName;
4446
private Long cost;
@@ -56,6 +58,7 @@ public SegmentCost() {
5658
data.setDataString(0, this.id);
5759
data.setDataString(1, this.segmentId);
5860
data.setDataString(2, this.serviceName);
61+
data.setDataInteger(0, this.applicationId);
5962
data.setDataLong(0, this.cost);
6063
data.setDataLong(1, this.startTime);
6164
data.setDataLong(2, this.endTime);
@@ -131,5 +134,13 @@ public long getTimeBucket() {
131134
public void setTimeBucket(long timeBucket) {
132135
this.timeBucket = timeBucket;
133136
}
137+
138+
public int getApplicationId() {
139+
return applicationId;
140+
}
141+
142+
public void setApplicationId(int applicationId) {
143+
this.applicationId = applicationId;
144+
}
134145
}
135146
}

apm-collector/apm-collector-storage/src/main/java/org/skywalking/apm/collector/storage/define/segment/SegmentCostTable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public class SegmentCostTable extends CommonTable {
99
public static final String TABLE = "segment_cost";
1010
public static final String COLUMN_SEGMENT_ID = "segment_id";
11+
public static final String COLUMN_APPLICATION_ID = "application_id";
1112
public static final String COLUMN_START_TIME = "start_time";
1213
public static final String COLUMN_END_TIME = "end_time";
1314
public static final String COLUMN_SERVICE_NAME = "service_name";

apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/ISegmentCostDAO.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88
*/
99
public interface ISegmentCostDAO {
1010
JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName,
11-
List<String> segmentIds, int limit, int from, Sort sort);
11+
Error error, int applicationId, List<String> segmentIds, int limit, int from, Sort sort);
1212

13-
public enum Sort {
13+
enum Sort {
1414
Cost, Time
1515
}
16+
17+
enum Error {
18+
All, True, False
19+
}
1620
}

apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/SegmentCostEsDAO.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class SegmentCostEsDAO extends EsDAO implements ISegmentCostDAO {
2626

2727
@Override public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName,
28-
List<String> segmentIds, int limit, int from, Sort sort) {
28+
Error error, int applicationId, List<String> segmentIds, int limit, int from, Sort sort) {
2929
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(SegmentCostTable.TABLE);
3030
searchRequestBuilder.setTypes(SegmentCostTable.TABLE_TYPE);
3131
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
@@ -50,6 +50,14 @@ public class SegmentCostEsDAO extends EsDAO implements ISegmentCostDAO {
5050
if (CollectionUtils.isNotEmpty(segmentIds)) {
5151
boolQueryBuilder.must().add(QueryBuilders.termsQuery(SegmentCostTable.COLUMN_SEGMENT_ID, segmentIds.toArray(new String[0])));
5252
}
53+
if (Error.True.equals(error)) {
54+
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_IS_ERROR, true));
55+
} else if (Error.False.equals(error)) {
56+
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_IS_ERROR, false));
57+
}
58+
if (applicationId != 0) {
59+
boolQueryBuilder.must().add(QueryBuilders.termQuery(SegmentCostTable.COLUMN_APPLICATION_ID, applicationId));
60+
}
5361

5462
if (Sort.Cost.equals(sort)) {
5563
searchRequestBuilder.addSort(SegmentCostTable.COLUMN_COST, SortOrder.DESC);
@@ -84,6 +92,7 @@ public class SegmentCostEsDAO extends EsDAO implements ISegmentCostDAO {
8492
topSegmentJson.addProperty(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID, globalTraces.get(0));
8593
}
8694

95+
topSegmentJson.addProperty(SegmentCostTable.COLUMN_APPLICATION_ID, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_APPLICATION_ID));
8796
topSegmentJson.addProperty(SegmentCostTable.COLUMN_SERVICE_NAME, (String)searchHit.getSource().get(SegmentCostTable.COLUMN_SERVICE_NAME));
8897
topSegmentJson.addProperty(SegmentCostTable.COLUMN_COST, (Number)searchHit.getSource().get(SegmentCostTable.COLUMN_COST));
8998
topSegmentJson.addProperty(SegmentCostTable.COLUMN_IS_ERROR, (Boolean)searchHit.getSource().get(SegmentCostTable.COLUMN_IS_ERROR));

apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/dao/SegmentCostH2DAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
public class SegmentCostH2DAO extends H2DAO implements ISegmentCostDAO {
1111
@Override public JsonObject loadTop(long startTime, long endTime, long minCost, long maxCost, String operationName,
12-
List<String> segmentIds, int limit, int from, Sort sort) {
12+
Error error, int applicationId, List<String> segmentIds, int limit, int from, Sort sort) {
1313
return null;
1414
}
1515
}

apm-collector/apm-collector-ui/src/main/java/org/skywalking/apm/collector/ui/jetty/handler/SegmentTopGetHandler.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.JsonElement;
44
import javax.servlet.http.HttpServletRequest;
5+
import org.skywalking.apm.collector.core.util.StringUtils;
56
import org.skywalking.apm.collector.server.jetty.ArgumentsParseException;
67
import org.skywalking.apm.collector.server.jetty.JettyHandler;
78
import org.skywalking.apm.collector.ui.dao.ISegmentCostDAO;
@@ -78,6 +79,27 @@ public class SegmentTopGetHandler extends JettyHandler {
7879
operationName = req.getParameter("operationName");
7980
}
8081

82+
int applicationId;
83+
try {
84+
applicationId = Integer.valueOf(req.getParameter("applicationId"));
85+
} catch (NumberFormatException e) {
86+
throw new ArgumentsParseException("the request parameter applicationId must be a int");
87+
}
88+
89+
ISegmentCostDAO.Error error;
90+
String errorStr = req.getParameter("error");
91+
if (StringUtils.isNotEmpty(errorStr)) {
92+
if ("true".equals(errorStr)) {
93+
error = ISegmentCostDAO.Error.True;
94+
} else if ("false".equals(errorStr)) {
95+
error = ISegmentCostDAO.Error.False;
96+
} else {
97+
error = ISegmentCostDAO.Error.All;
98+
}
99+
} else {
100+
error = ISegmentCostDAO.Error.All;
101+
}
102+
81103
ISegmentCostDAO.Sort sort = ISegmentCostDAO.Sort.Cost;
82104
if (req.getParameterMap().containsKey("sort")) {
83105
String sortStr = req.getParameter("sort");
@@ -86,7 +108,7 @@ public class SegmentTopGetHandler extends JettyHandler {
86108
}
87109
}
88110

89-
return service.loadTop(startTime, endTime, minCost, maxCost, operationName, globalTraceId, limit, from, sort);
111+
return service.loadTop(startTime, endTime, minCost, maxCost, operationName, globalTraceId, error, applicationId, limit, from, sort);
90112
}
91113

92114
@Override protected JsonElement doPost(HttpServletRequest req) throws ArgumentsParseException {

0 commit comments

Comments
 (0)