[Feature] Integrate SQL/PPL with query-insights plugin - #5636
[Feature] Integrate SQL/PPL with query-insights plugin#5636KishoreKicha14 wants to merge 4 commits into
Conversation
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit bd9913a.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
PR Reviewer Guide 🔍(Review updated until commit d12593c)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to d12593c Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 06af171
Suggestions up to commit bd9913a
Suggestions up to commit c50c128
Suggestions up to commit dcd396f
Suggestions up to commit c50c128
|
705b115 to
8c958a8
Compare
|
Persistent review updated to latest commit 8c958a8 |
8c958a8 to
1e86aa4
Compare
|
Persistent review updated to latest commit 1e86aa4 |
1e86aa4 to
70cb9db
Compare
|
Persistent review updated to latest commit 70cb9db |
|
Persistent review updated to latest commit a38aeb9 |
42927c2 to
78e60a8
Compare
|
Persistent review updated to latest commit c3e375a |
a38aeb9 to
42927c2
Compare
|
Persistent review updated to latest commit 134b552 |
ansjcy
left a comment
There was a problem hiding this comment.
I need to take a closer look into the core logistics but please make sure you format this PR before submitting.
| Optional<Throwable> calciteFailure) { | ||
| try { | ||
| executePlan(analyze(plan, queryType), PlanContext.emptyPlanContext(), listener); | ||
| org.opensearch.sql.common.utils.QueryPhaseTracker tracker = |
There was a problem hiding this comment.
please do proper import, don't use org.opensearch.sql.common.utils.QueryPhaseTracker..
| // This happens if Calcite fell back to V2 due to some issue, and then V2 also failed. | ||
| // Prefer the Calcite error. | ||
| // https://github.com/opensearch-project/sql/issues/5060 | ||
| // Calcite fell back to V2 which also failed — prefer Calcite error (#5060) |
134b552 to
b100945
Compare
|
Persistent review updated to latest commit b100945 |
b100945 to
4985f3d
Compare
|
Persistent review updated to latest commit 4985f3d |
…racking headers (x-query-source, x-original-query, x-query-execution-id, x-query-phases) to SQL and PPL execution paths so query-insights can identify and track SQL/PPL queries separately from DSL queries. - Add QueryPhaseTracker for tracking parse/analyze/plan phases - Tag thread context with SQL/PPL source headers in transport actions - Add writePhaseHeader() to Calcite execution path for PPL queries - Register all tracking headers as task headers for propagation Signed-off-by: Kishore Kumaar Natarajan <kkumaarn@amazon.com>
4985f3d to
c50c128
Compare
|
Persistent review updated to latest commit c50c128 |
c50c128 to
dcd396f
Compare
|
Persistent review updated to latest commit dcd396f |
dcd396f to
c50c128
Compare
|
Persistent review updated to latest commit c50c128 |
|
Instead of injecting four new request headers, can you add the parent id to the DSL search tasks created by sql/ppl? Then every normal DSL search task will have a reference back to its originating sql/ppl query. Query Insights can simply look up whatever info it needs, like the original request body. The gap right now is that not all DSL search tasks carry the parent PPL/SQL id. PPL v2 was instrumented recently in #5628 ( |
| () -> { | ||
| try { | ||
| QueryPhaseTracker tracker = QueryPhaseTracker.startOrRestore(); | ||
| tracker.beginPhase("analyze"); |
There was a problem hiding this comment.
Is it better to add these phase markers here instead of part of executeStage?
Can possibly rename StageErrorHandler if it's not broad enough to cover all stage-covering monitoring. Same thing with possibly merging the whole queryphasetracker into what we're already using to define these phases.
There was a problem hiding this comment.
did you mean to put this ai review folder in the project root
| PPLQueryRequest transformedRequest = transportRequest.toPPLQueryRequest(); | ||
|
|
||
| // Tag the thread context so query-insights can identify this as a PPL-derived query. | ||
| org.opensearch.common.util.concurrent.ThreadContext threadContext = |
There was a problem hiding this comment.
are these headers correctly getting propagated after a complex thread pool handoff?
That pr is mostly focused on v3, not sure where v2 is from. But other than that, I like this proposal, we should be roughly aligning to the existing stage tracking and thread propagation we already have as part of complex/background thread handoff. Particularly because historically thread propagation is a pain to modify and guard on edge cases, I'd be very in favor of a single component that owns "create an instrumented thread context that runs $LAMBDA and emits the right metrics to the right places." |
…rent task Replace the query-source request headers with parent-task linkage so every DSL search task the SQL/PPL engines spawn references its originating query. query-insights can then look up the coordinator task (and its original request) instead of relying on x-query-* headers, avoiding raw query text on the wire, getTaskHeaders() wiring, and thread-context propagation. - SQL: dispatch execution through a local SqlQueryAction/TransportSqlQueryAction that registers a SqlQueryTask coordinator task (via NodeClient.executeLocally), binds it as the cancellable task, and completes on the REST channel response. Wired into RestSqlAction through a SqlCoordinatorTaskDispatcher seam (legacy module cannot depend on the plugin transport action directly). - PPL v3: propagate the coordinator task to the background prefetch threads in BackgroundSearchScanner so applyParentTask stamps the parent on prefetched DSL searches (previously lost on the sql_background_io pool). - Remove QuerySourceHeaders, QueryPhaseTracker, getTaskHeaders(), and all x-query-* header writes from the SQL/PPL execution paths. Note: SQL coordinator-task lifecycle (task-manager registration visibility, no-leak cleanup, and fallback/cursor/explain behavior) still needs live-cluster integration testing. Unit tests pass and all modules compile. Signed-off-by: Kishore Natarajan <kkumaarn@amazon.com>
|
Persistent review updated to latest commit bd9913a |
- SqlQueryTaskTest: child-cancellation flag and cancellation behavior - TransportSqlQueryRequestTest: createTask type, description text + truncation + null handling, work/channel carriage, validate - TransportSqlQueryActionTest: listener completion on response, cancellable task binding during execution, failure before response, no double completion when work throws after response, single completion on repeated sendResponse - SqlCoordinatorTaskDispatcherTest: PASSTHROUGH runs work with the channel Also apply spotless formatting to the coordinator-task sources. Signed-off-by: Kishore Natarajan <kkumaarn@amazon.com>
|
Persistent review updated to latest commit 06af171 |
Restore the initiating thread's prior cancellable task (or clear it) in a finally block in TransportSqlQueryAction.doExecute so pooled transport workers don't retain a stale task reference. Safe because async workers capture the task synchronously during work.accept before it returns. Expand TransportSqlQueryActionTest to cover the thread-local clear (on both success and failure) and all CompletionSignalingChannel delegation methods. Signed-off-by: Kishore Natarajan <kkumaarn@amazon.com>
|
Persistent review updated to latest commit d12593c |
Description
Propagate SQL/PPL query metadata to OpenSearch's query-insights plugin so that DSL queries generated by the SQL engine are identifiable and traceable back to their originating SQL/PPL statement.
Changes:
Related Issues
Resolves #5677
Check List
--signoffor-s.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.