Skip to content

Commit

Permalink
feat: Replace timestamps with Duration in async profiler query && Add…
Browse files Browse the repository at this point in the history
… AsyncProfiling widget (#12816)
  • Loading branch information
zhengziyi0117 authored Dec 2, 2024
1 parent eb4d38c commit f008277
Show file tree
Hide file tree
Showing 162 changed files with 429 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ public void saveTask(String serviceId, AsyncProfilerTask task) {
}

/**
* use for every db query, -5 start time
* use for every db query, -5min start time
*/
public long getCacheStartTimeBucket() {
return TimeBucket.getMinuteTimeBucket(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
return TimeBucket.getRecordTimeBucket(System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5));
}

/**
* use for every db query, +5 end time(because search through task's start time)
* use for every db query, +5min end time(because search through task's start time)
*/
public long getCacheEndTimeBucket() {
return TimeBucket.getMinuteTimeBucket(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5));
return TimeBucket.getRecordTimeBucket(System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public AsyncProfilerTaskCreationResult createTask(String serviceId,
task.setEventsFromList(rowEvents);
task.setCreateTime(createTime);
task.setExecArgs(execArgs);
task.setTimeBucket(TimeBucket.getMinuteTimeBucket(createTime));
task.setTimeBucket(TimeBucket.getRecordTimeBucket(createTime));
NoneStreamProcessor.getInstance().in(task);

return AsyncProfilerTaskCreationResult.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
import com.google.gson.Gson;
import lombok.RequiredArgsConstructor;
import org.apache.skywalking.oap.server.core.analysis.IDManager;
import org.apache.skywalking.oap.server.core.analysis.TimeBucket;
import org.apache.skywalking.oap.server.core.profiling.asyncprofiler.storage.JFRProfilingDataRecord;
import org.apache.skywalking.oap.server.core.query.AsyncProfilerTaskLog;
import org.apache.skywalking.oap.server.core.query.input.Duration;
import org.apache.skywalking.oap.server.core.query.type.AsyncProfilerStackTree;
import org.apache.skywalking.oap.server.core.query.type.AsyncProfilerTask;
import org.apache.skywalking.oap.server.core.storage.StorageModule;
import org.apache.skywalking.oap.server.core.storage.profiling.asyncprofiler.IAsyncProfilerTaskLogQueryDAO;
import org.apache.skywalking.oap.server.core.storage.profiling.asyncprofiler.IAsyncProfilerTaskQueryDAO;
import org.apache.skywalking.oap.server.core.storage.profiling.asyncprofiler.IJFRDataQueryDAO;
import org.apache.skywalking.oap.server.library.jfr.parser.JFRMergeBuilder;
import org.apache.skywalking.oap.server.library.jfr.type.FrameTree;
import org.apache.skywalking.oap.server.library.jfr.type.JFREventType;
import org.apache.skywalking.oap.server.library.jfr.parser.JFRMergeBuilder;
import org.apache.skywalking.oap.server.library.module.ModuleManager;
import org.apache.skywalking.oap.server.library.module.Service;

Expand Down Expand Up @@ -79,15 +79,12 @@ private IAsyncProfilerTaskLogQueryDAO getTaskLogQueryDAO() {
return logQueryDAO;
}

public List<AsyncProfilerTask> queryTask(String serviceId, Long startTime, Long endTime, Integer limit) throws IOException {
public List<AsyncProfilerTask> queryTask(String serviceId, Duration duration, Integer limit) throws IOException {
Long startTimeBucket = null;
if (Objects.nonNull(startTime)) {
startTimeBucket = TimeBucket.getMinuteTimeBucket(startTime);
}

Long endTimeBucket = null;
if (Objects.nonNull(endTime)) {
endTimeBucket = TimeBucket.getMinuteTimeBucket(endTime);
if (Objects.nonNull(duration)) {
startTimeBucket = duration.getStartTimeBucketInSec();
endTimeBucket = duration.getEndTimeBucketInSec();
}

return getTaskQueryDAO().getTaskList(serviceId, startTimeBucket, endTimeBucket, limit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
@Setter
public class AsyncProfilerTaskListRequest {
private String serviceId;
private Long startTime;
private Long endTime;
private Duration queryDuration;
private Integer limit;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.apache.skywalking.oap.server.core.query.type.AsyncProfilerTaskListResult;
import org.apache.skywalking.oap.server.core.query.type.AsyncProfilerTaskLogOperationType;
import org.apache.skywalking.oap.server.core.query.type.AsyncProfilerTaskProgress;
import org.apache.skywalking.oap.server.library.jfr.type.JFREventType;
import org.apache.skywalking.oap.server.library.module.ModuleManager;

import java.io.IOException;
Expand Down Expand Up @@ -60,19 +59,12 @@ private AsyncProfilerQueryService getAsyncProfilerQueryService() {

public AsyncProfilerTaskListResult queryAsyncProfilerTaskList(AsyncProfilerTaskListRequest request) throws IOException {
List<AsyncProfilerTask> tasks = getAsyncProfilerQueryService().queryTask(
request.getServiceId(), request.getStartTime(), request.getEndTime(), request.getLimit()
request.getServiceId(), request.getQueryDuration(), request.getLimit()
);
return new AsyncProfilerTaskListResult(null, tasks);
}

public AsyncProfilerAnalyzation queryAsyncProfilerAnalyze(AsyncProfilerAnalyzatonRequest request) throws IOException {
/**
* Due to the replacement of async-profiler-convert package, after JfrReader reads JFR events, it cannot distinguish lock events.
* Therefore, JAVA_MONITOR_ENTER and THREAD_PARK events are merged into one during query and parsing.
*/
if (JFREventType.isLockSample(request.getEventType())) {
request.setEventType(JFREventType.LOCK);
}
AsyncProfilerStackTree eventFrameTrees = getAsyncProfilerQueryService().queryJFRData(
request.getTaskId(), request.getInstanceIds(), request.getEventType()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,35 @@
}
]
},
{
"name": "Async Profiling",
"children": [
{
"x": 0,
"y": 2,
"w": 24,
"h": 46,
"i": "0",
"type": "AsyncProfiling"
},
{
"x": 0,
"y": 0,
"w": 24,
"h": 2,
"i": "2",
"type": "Text",
"graph": {
"fontColor": "theme",
"backgroundColor": "theme",
"content": "Async Profiling supported services written in Java with SkyWalking native agents installed.",
"fontSize": 14,
"textAlign": "left",
"url": ""
}
}
]
},
{
"name": "Log",
"children": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.EsDAO;
import org.apache.skywalking.oap.server.storage.plugin.elasticsearch.base.IndexController;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -89,14 +88,19 @@ public List<AsyncProfilerTask> getTaskList(String serviceId, Long startTimeBucke
}

@Override
public AsyncProfilerTask getById(String id) throws IOException {
public AsyncProfilerTask getById(String id) {
if (StringUtil.isEmpty(id)) {
return null;
}
final BoolQueryBuilder query = Query.bool();
final String index = IndexController.LogicIndicesRegister.getPhysicalTableName(AsyncProfilerTaskRecord.INDEX_NAME);
if (IndexController.LogicIndicesRegister.isMergedTable(AsyncProfilerTaskRecord.INDEX_NAME)) {
query.must(Query.term(IndexController.LogicIndicesRegister.RECORD_TABLE_NAME, AsyncProfilerTaskRecord.INDEX_NAME));
}
query.must(Query.term(AsyncProfilerTaskRecord.TASK_ID, id));

final SearchBuilder search = Search.builder()
.query(Query.bool().must(Query.term(AsyncProfilerTaskRecord.TASK_ID, id)))
.query(query)
.size(1);

final SearchResponse response = getClient().search(index, search.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ results:
{{- contains .values }}
- id: {{ notEmpty .id }}
value: {{ .value }}
owner: null
traceid: null
- id: {{ notEmpty .id }}
value: null
owner: null
traceid: null
{{- end}}
{{- end}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
{{- end}}
error: null
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
{{- end}}
error: null
2 changes: 2 additions & 0 deletions test/e2e-v2/cases/activemq/expected/metrics-has-value.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
{{- end}}
error: null
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -39,9 +41,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
{{- end}}
error: null
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -43,9 +45,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -58,9 +62,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -73,9 +79,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -88,9 +96,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -103,9 +113,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -118,9 +130,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -133,9 +147,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -148,9 +164,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -163,9 +181,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -178,9 +198,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
- metric:
labels:
Expand All @@ -193,9 +215,11 @@ results:
- id: {{ notEmpty .id }}
value: {{ .value }}
traceid: null
owner: null
- id: {{ notEmpty .id }}
value: null
traceid: null
owner: null
{{- end}}
{{- end}}
error: null
Loading

0 comments on commit f008277

Please sign in to comment.