Skip to content

feat: Show running PPL queries in Live Queries - #699

Merged
KishoreKicha14 merged 2 commits into
opensearch-project:mainfrom
KishoreKicha14:feat/ppl-live-queries
Oct 30, 2026
Merged

KishoreKicha14 merged 2 commits into
opensearch-project:mainfrom
KishoreKicha14:feat/ppl-live-queries

Conversation

@KishoreKicha14

@KishoreKicha14 KishoreKicha14 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A PPL query runs as a cluster:admin/opensearch/ppl task, and the searches it runs are its child tasks. Live Queries listed only search tasks, so the PPL task was filtered out: each of its searches showed up as a separate row, and between searches the query wasn't listed at all.

This lists the PPL task alongside searches and reports each PPL query as one live query:

  • coordinator_task is the PPL task. Its child searches and their shard tasks are its shard_tasks, and their CPU and memory add to the row's totals.
  • total_latency_millis is the PPL task's running time.
  • The user comes from the query's first child search that has one, because the user is captured per search.
  • A PPL row has no wlm_group_id. WLM manages the searches a PPL query runs, not the query (PPLQueryTask isn't a WorkloadGroupTask), and one query can run searches in several groups. ?wlmGroupId= keeps a PPL row while any of its running searches is in that group.
  • A search whose parent task isn't listed is still reported on its own, as before.

There is no model or wire change: a PPL row is one whose coordinator_task.action is cluster:admin/opensearch/ppl.

The searches nest under the PPL task because the SQL plugin makes them its children (opensearch-project/sql#5888, merged). The PPL task's own CPU and memory, from the PPL engine's threads, show once opensearch-project/sql#5760 merges; until then a PPL row's totals cover its searches only. The dashboards side is opensearch-project/query-insights-dashboards#612.

Known limitations

  • Async PPL queries (wait_for_completion_timeout or keep_alive): a query still running when its wait time passes ends its PPL task, so the searches it runs after that show as separate rows, as before this PR.

Follow-ups

  • Finished queries (use_finished_cache=true) still lists a finished PPL query as its separate searches, each under its search task id. A follow-up will record it under the PPL task's id (nodeId:pplTaskId), so the dashboards can follow a row from live to finished.
  • Show the WLM group of each child search, which needs a new field on the task details.

Testing

  • 7 new unit tests in TransportLiveQueriesActionTests: a PPL query with its searches, a PPL query between searches, a search whose parent isn't listed, the user taken from a child search, filter_by_mode=username, and WLM filtering across searches in different groups. All 658 unit tests pass.
  • The Live Queries REST integration tests pass.
  • On a single node with security and the SQL plugin from feat(ppl): Report completed PPL queries to Query Insights Top N sql#5760, I ran a 30-second PPL join beside a DSL search. The PPL query stayed one row for its whole run with its searches nested under it. It never showed a WLM group, ?wlmGroupId=DEFAULT_WORKLOAD_GROUP kept it only while a search was running, and the DSL row was unchanged.

Issues Resolved

None filed.

Related: #647 (draft) took an earlier approach to Live Queries, with a query source attribute on the record; this PR doesn't need it. #650 changes the same part of TransportLiveQueriesAction, so whichever merges second needs a rebase.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

A PPL query runs as a cluster:admin/opensearch/ppl task whose searches
are its child tasks. Live Queries listed only search tasks, so the PPL
task was filtered out, each of its searches became a separate top-level
row, and the query itself was invisible between searches.

List the PPL task alongside searches and report it as one live query:
its child searches and their shard tasks are its shard_tasks and add to
its totals, and its latency is the PPL task's running time. A PPL task
has no workload group or captured identity of its own, so both come
from its first local child search that has one.

No model or wire change: coordinator_task.action tells PPL rows apart.

Signed-off-by: Kishore Kumaar Natarajan <kkumaarn@amazon.com>
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

(Review updated until commit 14b90c8)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ Recommended focus areas for review

Possible double-counting

collectChildSearches recursively walks the PPL task group and adds every descendant whose action equals SEARCH_ACTION. If a child search itself has nested search coordinator tasks (e.g. cross-cluster or secondary searches started from within the PPL execution), both the outer search and its nested search will be added to shardTasks, and their resource stats will each contribute to the PPL record's totals via collectChildTasks processing of the shard tasks downstream. Consider stopping recursion at the first matching search level, or deduplicating by TaskId.

private static void collectChildSearches(final TaskGroup group, final List<TaskInfo> result) {
    for (TaskGroup child : group.getChildTasks()) {
        if (SEARCH_ACTION.equals(child.getTaskInfo().getAction())) {
            result.add(child.getTaskInfo());
        }
        collectChildSearches(child, result);
    }
}
WLM filter semantics

localWorkloadGroupId only resolves a workload group when the search task is on the local node (returns null otherwise). For a PPL query whose child searches coordinate on remote nodes, the WLM group filter will miss matches and incorrectly exclude the query. The previous code had the same limitation for standalone searches, but the new PPL path makes this more impactful because a PPL query spawning searches on another node will never match any group filter.

private String localWorkloadGroupId(final TaskInfo info) {
    if (!transportService.getLocalNode().getId().equals(info.getTaskId().getNodeId())) {
        return null;
    }
    Task runningTask = transportService.getTaskManager().getTask(info.getTaskId().getId());
    return runningTask instanceof WorkloadGroupTask workloadTask ? workloadTask.getWorkloadGroupId() : null;
}

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Deduplicate task keys before fan-out

The child search keys may include tasks whose node id differs from the PPL
coordinator (since a PPL task's search can be coordinated on another node). The
subsequent targetNodeIds derivation does extract node ids from all keys, so this is
fine, but duplicate taskKeys could inflate the fan-out payload. Consider
deduplicating taskKeys to avoid redundant lookups when the same key appears from
both record id and child list.

src/main/java/org/opensearch/plugin/insights/rules/transport/live_queries/TransportLiveQueriesAction.java [248-252]

 List<String> taskKeys = new ArrayList<>();
 for (LiveQueryRecord record : records) {
     taskKeys.add(record.getQueryId());
     taskKeys.addAll(childSearchKeysByQueryId.getOrDefault(record.getQueryId(), List.of()));
 }
+taskKeys = taskKeys.stream().distinct().toList();
Suggestion importance[1-10]: 2

__

Why: Duplicates are unlikely in practice because queryId is the parent task key and child search keys are distinct child task keys. The suggestion offers only a marginal defensive optimization with minimal impact.

Low

@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.80%. Comparing base (534242a) to head (4a32a01).
⚠️ Report is 29 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #699      +/-   ##
============================================
- Coverage     77.98%   76.80%   -1.18%     
- Complexity      952     1051      +99     
============================================
  Files            87       93       +6     
  Lines          3630     4006     +376     
  Branches        411      493      +82     
============================================
+ Hits           2831     3077     +246     
- Misses          607      720     +113     
- Partials        192      209      +17     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment on lines 134 to 137
String wlmGroupId = localWorkloadGroupId(coordinatorInfo);
for (int i = 0; wlmGroupId == null && i < childSearches.size(); i++) {
wlmGroupId = localWorkloadGroupId(childSearches.get(i));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

WLM doesn't manage the PPL task itself (PPLQueryTask isn't a WorkloadGroupTask). It only manages the searches the PPL query runs, so the PPL row shouldn't show a WLM group. Copying the first child search's group can also be wrong, because one PPL query can run searches in different groups.

Suggest leaving wlm_group_id empty on PPL rows and showing the group on each child search instead. How should ?wlmGroupId= filter PPL rows then? For example, include the row if any of its searches is in that group?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

With the update, a PPL query's row has no WLM group anywhere. WLM only tags searches, so the PPL task itself never gets a group, and each child search is tagged separately.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

?wlmGroupId=X keeps the PPL row while at least one of its running searches is in group X, and hides it between searches.

WLM manages the searches a PPL query runs, not the query itself: the
PPL task is not a WorkloadGroupTask, and WLM tags each search on its
own, so one query can run searches in several groups. Copying the
first search's group onto the PPL row could show the wrong group, and
the row showed none between searches.

Leave wlm_group_id off PPL rows. ?wlmGroupId= keeps a PPL row while
any of its running searches is in that group, so between searches the
filter hides it.

Also note in the class javadoc that an async PPL query still running
when its wait time passes has its later searches listed as separate
live queries, since its PPL task has ended. The main PPL test now
gives the PPL task usage of its own, as the SQL plugin tracks the PPL
engine's threads on it (opensearch-project/sql#5760).

Signed-off-by: Kishore Kumaar Natarajan <kkumaarn@amazon.com>
@github-actions

Copy link
Copy Markdown
Contributor

Persistent review updated to latest commit 14b90c8

@KishoreKicha14
KishoreKicha14 merged commit f4f5545 into opensearch-project:main Oct 30, 2026
19 of 20 checks passed
KishoreKicha14 added a commit to KishoreKicha14/query-insights-dashboards that referenced this pull request Oct 31, 2026
Live Queries leaves wlm_group_id off PPL rows as of
opensearch-project/query-insights#699: WLM manages the searches a PPL
query runs, not the query, so a PPL row has no group of its own.
Remove it from the PPL row in stub_live_queries_ppl.json so the
fixture matches what the API returns.

Signed-off-by: Kishore Kumaar Natarajan <kkumaarn@amazon.com>
KishoreKicha14 added a commit to KishoreKicha14/query-insights-dashboards that referenced this pull request Nov 23, 2026
Live Queries leaves wlm_group_id off PPL rows as of
opensearch-project/query-insights#699: WLM manages the searches a PPL
query runs, not the query, so a PPL row has no group of its own.
Remove it from the PPL row in stub_live_queries_ppl.json so the
fixture matches what the API returns.

Signed-off-by: Kishore Kumaar Natarajan <kkumaarn@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants