Skip to content

Push taskId filter down to storage layer in AsyncProfilerTaskLog query#13787

Merged
wu-sheng merged 7 commits intoapache:masterfrom
currenjin:fix/async-profiler-task-log-query-filter-by-taskid
Apr 3, 2026
Merged

Push taskId filter down to storage layer in AsyncProfilerTaskLog query#13787
wu-sheng merged 7 commits intoapache:masterfrom
currenjin:fix/async-profiler-task-log-query-filter-by-taskid

Conversation

@currenjin
Copy link
Copy Markdown
Contributor

What this PR does

IAsyncProfilerTaskLogQueryDAO.getTaskLogList() had no parameters, causing all implementations (JDBC, Elasticsearch, BanyanDB) to fetch every task log from storage. The service layer then filtered by taskId in memory.

This PR pushes the filter down to the storage layer by adding taskId as a parameter to getTaskLogList() and updating all three implementations to apply DB-level filtering.

Changes

  • IAsyncProfilerTaskLogQueryDAO: add taskId parameter to getTaskLogList()
  • JDBCAsyncProfilerTaskLogQueryDAO: add WHERE task_id = ? to SQL
  • AsyncProfilerTaskLogQueryEsDAO: add term query on task_id
  • BanyanDBAsyncProfilerTaskLogQueryDAO: add eq(TASK_ID, taskId) condition
  • AsyncProfilerQueryService: pass taskId directly to DAO, remove findMatchedLogs() in-memory filtering

Related

Related to #13593

@wu-sheng
Copy link
Copy Markdown
Member

wu-sheng commented Apr 3, 2026

@mrproliu Could you check this? Why did it only filter in memory?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the async-profiler task log query flow so taskId filtering happens in the storage layer (JDBC / Elasticsearch / BanyanDB) rather than fetching all logs and filtering in memory within AsyncProfilerQueryService.

Changes:

  • Add taskId parameter to IAsyncProfilerTaskLogQueryDAO.getTaskLogList(...).
  • Apply taskId filtering in JDBC (WHERE task_id = ?), Elasticsearch (term query), and BanyanDB (eq(task_id, ...)).
  • Simplify AsyncProfilerQueryService by removing in-memory filtering and passing taskId directly to the DAO.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/common/dao/JDBCAsyncProfilerTaskLogQueryDAO.java Adds task_id predicate to SQL generation for task log queries.
oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/query/AsyncProfilerTaskLogQueryEsDAO.java Adds task_id term filter to the ES query.
oap-server/server-storage-plugin/storage-banyandb-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/banyandb/stream/BanyanDBAsyncProfilerTaskLogQueryDAO.java Adds task_id equality condition to the BanyanDB stream query.
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/storage/profiling/asyncprofiler/IAsyncProfilerTaskLogQueryDAO.java Updates DAO API to require taskId when listing task logs.
oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/profiling/asyncprofiler/AsyncProfilerQueryService.java Passes taskId to DAO and removes in-memory filtering logic.
docs/en/changes/changes.md Documents the behavioral change in the changelog.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 104 to 107
public List<AsyncProfilerTaskLog> queryAsyncProfilerTaskLogs(String taskId) throws IOException {
List<AsyncProfilerTaskLog> taskLogList = getTaskLogQueryDAO().getTaskLogList();
return findMatchedLogs(taskId, taskLogList);
}

private List<AsyncProfilerTaskLog> findMatchedLogs(final String taskID, final List<AsyncProfilerTaskLog> allLogs) {
return allLogs.stream()
.filter(l -> Objects.equals(l.getId(), taskID))
return getTaskLogQueryDAO().getTaskLogList(taskId).stream()
.map(this::extendTaskLog)
.collect(Collectors.toList());
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTaskLogList(taskId) is now called directly and the ES implementation uses Query.term(..., taskId) which throws a NullPointerException when taskId is null. To keep behavior consistent across storage implementations (JDBC would just bind null) and avoid unexpected NPEs, add a fast-fail/guard here (e.g., validate taskId is non-null/non-blank and return empty list or throw an IllegalArgumentException with a clear message) before invoking the DAO.

Copilot uses AI. Check for mistakes.
Comment on lines 49 to 58
@Override
public List<AsyncProfilerTaskLog> getTaskLogList() throws IOException {
public List<AsyncProfilerTaskLog> getTaskLogList(String taskId) throws IOException {
final String index = IndexController.LogicIndicesRegister.getPhysicalTableName(
AsyncProfilerTaskLogRecord.INDEX_NAME);
final BoolQueryBuilder query = Query.bool();
if (IndexController.LogicIndicesRegister.isMergedTable(AsyncProfilerTaskLogRecord.INDEX_NAME)) {
query.must(Query.term(IndexController.LogicIndicesRegister.RECORD_TABLE_NAME, AsyncProfilerTaskLogRecord.INDEX_NAME));
}
query.must(Query.term(AsyncProfilerTaskLogRecord.TASK_ID, taskId));
final SearchBuilder search =
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query.term(..., taskId) will throw a NullPointerException with a generic message ("value") if taskId is null. Consider validating taskId at the start of this method (e.g., requireNonNull / checkArgument) and throwing an IllegalArgumentException with a clearer message, so failures are easier to diagnose and consistent with other storage implementations.

Copilot uses AI. Check for mistakes.
@wu-sheng wu-sheng added bug Something isn't working and you are sure it's a bug! backend OAP backend related. labels Apr 3, 2026
@wu-sheng
Copy link
Copy Markdown
Member

wu-sheng commented Apr 3, 2026

Please resolve conflicts.

@currenjin currenjin force-pushed the fix/async-profiler-task-log-query-filter-by-taskid branch from 139d82e to 0e804ca Compare April 3, 2026 03:09
@wu-sheng wu-sheng added this to the 10.5.0 milestone Apr 3, 2026
@wu-sheng wu-sheng merged commit f213c3b into apache:master Apr 3, 2026
415 of 421 checks passed
@currenjin currenjin deleted the fix/async-profiler-task-log-query-filter-by-taskid branch April 3, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend OAP backend related. bug Something isn't working and you are sure it's a bug!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants