Repository navigation
Conversation
Add RunningQueryRegistry, which tracks the queries that are executing on a process along with their identity, start time, and datasources. Queries are registered when execution starts, and removed when logs and metrics are emitted, in QueryLifecycle. Implement SqlEngine#getQueries for the native engine, so that GET /druid/v2/sql/queries and sys.queries report queries that are running on the native engine. Users without READ permission on the STATE resource only see their own queries, without identity details. Register the NativeQueryInfo Jackson subtype in SqlModule, and document the GET /druid/v2/sql/queries endpoint and the native engine rows of sys.queries.
QueryLifecycle-driven identity filtering now follows the same shape as DartSqlEngine: build the full list, then filter it for callers without READ permission on the STATE resource.
Remove equals, hashCode, and toString from RunningQueryRegistry.Entry and NativeQueryInfo, which are not needed by the API, and use a Comparator for the registry snapshot. Add tests for a query without an ID, for unregistering unknown IDs, and for callers that have no identity or no authenticator.
dkhwangbo
force-pushed
the
list-running-native-queries
branch
from
November 26, 2026 08:31
1888148 to
0bd2b95
Compare
Add druid.server.http.enableRunningQueryText, which makes the running query registry keep the SQL text and the native query of each running query, and return them from the running queries API and sys.queries. The setting is disabled by default because query text can include sensitive information. The SQL layer passes the SQL text to QueryLifecycle, and the native query is serialized when the query is registered. Use generic test identities instead of personal ones.
dkhwangbo
force-pushed
the
list-running-native-queries
branch
from
November 26, 2026 08:57
e55553b to
ec1910c
Compare
Include enableRunningQueryText in ServerConfig equals, hashCode, and toString, and thread it through the all-args constructor and the copies that CliIndexerServerModule makes, so that EqualsVerifier and config dumps see it. Stop serializing native queries when they are registered. The registry now keeps a reference to the running query and NativeSqlEngine serializes it when the list is read, so processes that do not serve the API do no extra work. Clarify in the configuration docs that the list is served by the Broker and that SQL text is captured only for queries submitted through the SQL layer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #18047.
Description
GET /druid/v2/sql/queriesand thesys.queriestable already report currently running queries, but only for the Dart engine (#17140, #18923). The native engine has no registry of in-flight queries, soSqlEngine#getQueriesreturns an empty list for it.This patch adds native engine support.
Added
RunningQueryRegistryA new server-module singleton tracks the queries that are executing on a process: query ID,
sqlQueryId(when the query came in through SQL), query type, datasources, identity, authenticator, and start time.Registered and unregistered by
QueryLifecycleQueries are added in
execute()and removed inemitLogsAndMetrics(). Every completion path goes throughemitLogsAndMetrics: the streaming response pusher (success, error, and 304) and therunSimplesequence wrapper. Queries that fail authorization or blocklisting never start, so they are never registered.Captured query text behind a flag
Setting
druid.server.http.enableRunningQueryTextmakes the registry keep the SQL text of SQL queries and a reference to the native query, and return them assqlandnativeQueryin the API and insys.queries. The native query is serialized when the list is read, so processes that do not serve the API do no extra work. The setting is disabled by default because query text can include sensitive information.Implemented
NativeSqlEngine#getQueriesRegistry entries are mapped to
NativeQueryInfo. Users with READ permission on theSTATEresource see all running queries, including identity details. Other users see only their own queries, with identity and authenticator omitted. This follows the same rules asDartSqlEngine#isOwnQuery.SqlModuleregisters theNativeQueryInfoJackson subtype ("engine": "native").The list is per-process: the native engine does not contact other servers, so
selfOnlyhas no effect, and completed queries are not retained, soincludeCompletehas no effect. Both behaviors are documented.Design notes
QueryScheduler? It already tracks query IDs inqueryFuturesandqueryDatasources, but those maps are documented as racy, are only populated on some code paths (CachingClusteredClientregisters only in the parallel-merge branch), and are cleared when the last result future completes, which can happen before the response has been fully written. They also carry no identity or start time. A registry driven byQueryLifecyclegives one complete lifecycle for every query that actually starts executing.sqlornativeQueryfields. When it is on, the SQL layer passes the SQL text throughQueryLifecycle, and the registry serializes the native query. Users still need permission to see the queries themselves: without READ permission on theSTATEresource, users only see their own queries.Release note
GET /druid/v2/sql/queriesandsys.queriesnow include queries that are running on the native engine, with their query type, datasources, identity, and start time. Previously, both only reported Dart queries.Testing
RunningQueryRegistryTest(including query text capture and serialization failure),NativeSqlEngineTest(mapping, authorization filtering, JSON serialization throughSqlModule),QueryLifecycleTest#testRunSimple_registersRunningQuery.SqlResourceTest#testListRunningQueries(STATE READ users see all queries; other users see only their own).NativeSqlEngineRunningQueriesTestruns a real SQL query throughSqlResourcewith the real planner and segment walker, and verifies that the query, its SQL text, and its native query are reported while it executes, and that it is gone afterwards.druid-server:RunningQueryRegistryTest,QueryLifecycleTest,QueryResourceTest,PerSegmentTimeoutInjectionTest(76 tests).druid-sql:NativeSqlEngineTest,NativeSqlEngineRunningQueriesTest,SqlResourceTest,SystemSchemaTest#testQueriesTable(72 tests).druid-serveranddruid-sql.