This is an automated email from the ASF dual-hosted git repository.
hello-stephen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 73d75e67f85 [fix](fe) Fix query profile ownership filtering and SQL
retrieval (#71280)
73d75e67f85 is described below
commit 73d75e67f85ebe079fd0c4678af8136d9036b5fa
Author: yiguolei <[email protected]>
AuthorDate: Thu Dec 3 15:17:22 2026 +0800
[fix](fe) Fix query profile ownership filtering and SQL retrieval (#71280)
### Background
The FE v2 query APIs read retained profiles from ProfileManager. The
query list uses a legacy HTTP column order, while the SQL endpoint reads
the summary column order. Ordinary users are restricted to their own
profiles; built-in root/admin users can view all profiles.
### What problem does this PR solve?
Issue Number: None
Related PR: #19219 (introduced the summary layout used by the SQL
endpoint), #43724 (introduced the current query_info layout)
PR Type: Bugfix
Problem Summary:
Both layouts were passed to a filter that treated column 1 as the owner.
That column is an unfilled node field in query_info and the task type in
the SQL endpoint. The SQL endpoint also returned column 3 (end time)
instead of SQL. Resolve fields using each endpoint's column names so
ownership filtering and SQL retrieval use the intended values. Most of
the diff adds regression unit tests.
### Details
- **Frequency:** Deterministic when affected retained profiles are
accessed; no concurrency is required.
- **Root cause:** Profile column order changed without updating
consumers that used fixed numeric indexes.
- **Why existing tests missed it:** QueryProfileActionTest covered
current-query column normalization, not retained-profile ownership
filtering or SQL retrieval.
- **Fix:** Pass the source column names into the shared filter, resolve
User and Profile ID once, and reject a schema missing either field.
Resolve SQL, task type, and node positions by name as well. A missing
owner does not match an ordinary caller.
- **Other paths and branches:** Both local endpoints are fixed together;
all-node requests invoke those local endpoints. The HTTP column order
and existing root/admin policy are preserved. No release-branch backport
is included.
- **Behavior change:** Ordinary users can retrieve their own retained
query records, other users' records remain filtered, and authorized SQL
requests return SQL rather than an end timestamp.
### Testing
- Passed `git diff --check` locally and inspected the final diff.
- Added parameterized unit tests for ordinary users, a username matching
the Query task type, root/admin, own and foreign records, nonexistent
IDs, null node fields, empty profiles, and missing owners.
- Added simulated two-FE forwarding tests that exercise the local
handlers and check forwarded credentials and aggregation. These do not
start real FE servers.
- Ran `bash run-fe-ut.sh --run
org.apache.doris.httpv2.rest.manager.QueryProfileActionTest` on an
isolated Linux development checkout with JDK 17: **14 tests, 0 failures,
0 errors, 0 skipped; BUILD SUCCESS; exit status 0**. Both forwarding
parameterizations passed.
- The tested source was `cf2e559dad2579f412dc6159d6b89925c89c40de` plus
the Jackson response-serialization test fix now included in this PR.
Local and remote test-file SHA-256 matched
(`f6d1aec0507dee72e493b29ce1b2297d006fdcfc896d09517bf45331e76d590a`).
- The forwarding fixture uses Jackson to model HTTP response
serialization; the persistence Gson omits unannotated response fields.
The fixture also asserts that the serialized response contains a data
object.
- Validation was scoped to this test class; the full FEUT suite and real
multi-FE HTTP integration were not run.
### Release note
Fix FE v2 query profile APIs to filter records by their actual owner and
return the query SQL instead of its end time, while preserving the
existing response format.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Ready; targeted FEUT passed. Full-suite and
real multi-FE integration coverage are outside this validation scope.
### AI Disclosure
- Tool: OpenAI Codex (GPT-6)
- Generated: Implementation, unit tests, and this PR description.
- Human review: Pending review of the generated diff.
---
.../httpv2/rest/manager/QueryProfileAction.java | 26 ++-
.../rest/manager/QueryProfileActionTest.java | 188 +++++++++++++++++++++
2 files changed, 206 insertions(+), 8 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
index ed3b6a49659..72d2ee304da 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/manager/QueryProfileAction.java
@@ -43,6 +43,7 @@ import org.apache.doris.service.FrontendOptions;
import org.apache.doris.thrift.TQueryStatistics;
import org.apache.doris.thrift.TStatusCode;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -188,15 +189,17 @@ public class QueryProfileAction extends
RestBaseController {
return ResponseEntityBuilder.ok(new
NodeAction.NodeInfo(QUERY_TITLE_NAMES, queries));
}
+ int taskTypeIndex =
PROFILE_TITLE_NAMES.indexOf(SummaryProfile.TASK_TYPE);
Stream<List<String>> queryStream = ProfileManager.getInstance()
.getQueryInfoByColumnNameList(PROFILE_TITLE_NAMES).stream()
- .filter(profile -> profile.get(5).equalsIgnoreCase("Query"));
- queryStream = filterQueriesByUserAndQueryId(queryStream, queryId);
+ .filter(profile ->
profile.get(taskTypeIndex).equalsIgnoreCase("Query"));
+ queryStream = filterQueriesByUserAndQueryId(queryStream, queryId,
PROFILE_TITLE_NAMES);
queries = queryStream.collect(Collectors.toList());
// add node information
+ int nodeIndex = PROFILE_TITLE_NAMES.indexOf(NODE);
for (List<String> query : queries) {
- query.set(1,
NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
+ query.set(nodeIndex,
NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
HttpURLUtil.getHttpPort()));
}
@@ -270,25 +273,32 @@ public class QueryProfileAction extends
RestBaseController {
}
} else {
Stream<List<String>> queryStream =
ProfileManager.getInstance().getAllQueries().stream();
- queryStream = filterQueriesByUserAndQueryId(queryStream, queryId);
+ queryStream = filterQueriesByUserAndQueryId(queryStream, queryId,
SummaryProfile.SUMMARY_KEYS);
List<List<String>> queries =
queryStream.collect(Collectors.toList());
if (!queries.isEmpty()) {
- querySql.put("sql", queries.get(0).get(3));
+ int sqlIndex =
SummaryProfile.SUMMARY_KEYS.indexOf(SummaryProfile.SQL_STATEMENT);
+ querySql.put("sql", queries.get(0).get(sqlIndex));
}
}
return ResponseEntityBuilder.ok(querySql);
}
- private Stream<List<String>>
filterQueriesByUserAndQueryId(Stream<List<String>> queryStream, String queryId)
{
+ private Stream<List<String>>
filterQueriesByUserAndQueryId(Stream<List<String>> queryStream, String queryId,
+ List<String> columnNames) {
+ // query_info and sql use different column orders. Resolve ownership
from the supplied schema.
+ int userIndex = columnNames.indexOf(SummaryProfile.USER);
+ int queryIdIndex = columnNames.indexOf(SummaryProfile.PROFILE_ID);
+ Preconditions.checkArgument(userIndex >= 0 && queryIdIndex >= 0,
+ "Profile columns must contain User and Profile ID");
// filter by user
// Only admin or root user can see all profile.
// Common user can only review the query of their own.
String user =
ConnectContext.get().getCurrentUserIdentity().getQualifiedUser();
if (!user.equalsIgnoreCase(Auth.ADMIN_USER) &&
!user.equalsIgnoreCase(Auth.ROOT_USER)) {
- queryStream = queryStream.filter(q -> q.get(1).equals(user));
+ queryStream = queryStream.filter(q ->
user.equals(q.get(userIndex)));
}
if (!Strings.isNullOrEmpty(queryId)) {
- queryStream = queryStream.filter(query ->
query.get(0).equals(queryId));
+ queryStream = queryStream.filter(query ->
queryId.equals(query.get(queryIdIndex)));
}
return queryStream;
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/manager/QueryProfileActionTest.java
b/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/manager/QueryProfileActionTest.java
index b3fb240979b..44001f6a985 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/manager/QueryProfileActionTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/httpv2/rest/manager/QueryProfileActionTest.java
@@ -17,17 +17,205 @@
package org.apache.doris.httpv2.rest.manager;
+import org.apache.doris.analysis.UserIdentity;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.Pair;
import org.apache.doris.common.proc.CurrentQueryStatisticsProcDir;
+import org.apache.doris.common.profile.ProfileManager;
+import org.apache.doris.common.profile.SummaryProfile;
+import org.apache.doris.common.util.HttpURLUtil;
import org.apache.doris.common.util.QueryStatisticsFormatter;
+import org.apache.doris.httpv2.entity.ResponseBody;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.system.SystemInfoService.HostInfo;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+import org.springframework.http.ResponseEntity;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
class QueryProfileActionTest {
+ private QueryProfileAction action;
+ private HttpServletRequest request;
+ private HttpServletResponse response;
+
+ @BeforeEach
+ void setUp() {
+ action = Mockito.spy(new QueryProfileAction());
+ request = Mockito.mock(HttpServletRequest.class);
+ response = Mockito.mock(HttpServletResponse.class);
+ Mockito.doReturn(null).when(action).executeCheckPassword(request,
response);
+ }
+
+ @AfterEach
+ void tearDown() {
+ ConnectContext.remove();
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"alice", "Query", "root", "admin"})
+ void filtersQueryInfoByOwnerBeforeFillingNode(String user) {
+ setUser(user);
+ List<String> own = profileRow(QueryProfileAction.PROFILE_TITLE_NAMES,
"own-id", user);
+ List<String> other =
profileRow(QueryProfileAction.PROFILE_TITLE_NAMES, "other-id", "bob");
+ List<String> load = profileRow(QueryProfileAction.PROFILE_TITLE_NAMES,
"load-id", user);
+
load.set(QueryProfileAction.PROFILE_TITLE_NAMES.indexOf(SummaryProfile.TASK_TYPE),
"Load");
+ ProfileManager manager = Mockito.mock(ProfileManager.class);
+
Mockito.when(manager.getQueryInfoByColumnNameList(QueryProfileAction.PROFILE_TITLE_NAMES))
+ .thenReturn(List.of(own, other, load));
+ Env env = Mockito.mock(Env.class);
+ Mockito.when(env.getSelfNode()).thenReturn(new HostInfo("127.0.0.1",
9010));
+ try (MockedStatic<ProfileManager> managers =
Mockito.mockStatic(ProfileManager.class);
+ MockedStatic<Env> environments =
Mockito.mockStatic(Env.class)) {
+ managers.when(ProfileManager::getInstance).thenReturn(manager);
+ environments.when(Env::getCurrentEnv).thenReturn(env);
+ NodeAction.NodeInfo result = (NodeAction.NodeInfo)
data(action.queryInfo(request, response,
+ null, null, false));
+ Assertions.assertEquals(QueryProfileAction.QUERY_TITLE_NAMES,
result.getColumnNames());
+ boolean admin = user.equals("root") || user.equals("admin");
+ Assertions.assertEquals(admin ? List.of(own, other) :
List.of(own), result.getRows());
+ Assertions.assertEquals("127.0.0.1:" + HttpURLUtil.getHttpPort(),
own.get(1));
+ Assertions.assertEquals(user, own.get(2));
+ Assertions.assertEquals("select 'own-id'", own.get(4));
+
+ NodeAction.NodeInfo byId = (NodeAction.NodeInfo)
data(action.queryInfo(request, response,
+ "other-id", null, false));
+ Assertions.assertEquals(admin ? List.of(other) : List.of(),
byId.getRows());
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(strings = {"alice", "Query", "root", "admin"})
+ void returnsSqlOnlyForAuthorizedQuery(String user) {
+ setUser(user);
+ ProfileManager manager = Mockito.mock(ProfileManager.class);
+ Mockito.when(manager.getAllQueries()).thenReturn(List.of(
+ profileRow(SummaryProfile.SUMMARY_KEYS, "other-id", "bob"),
+ profileRow(SummaryProfile.SUMMARY_KEYS, "own-id", user)));
+ try (MockedStatic<ProfileManager> managers =
Mockito.mockStatic(ProfileManager.class)) {
+ managers.when(ProfileManager::getInstance).thenReturn(manager);
+ Assertions.assertEquals(Map.of("sql", "select 'own-id'"),
+ data(action.queryInfo(request, response, "own-id",
false)));
+ boolean admin = user.equals("root") || user.equals("admin");
+ Assertions.assertEquals(admin ? Map.of("sql", "select 'other-id'")
: Map.of(),
+ data(action.queryInfo(request, response, "other-id",
false)));
+ Assertions.assertEquals(Map.of(), data(action.queryInfo(request,
response, "missing-id", false)));
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void handlesEmptyProfilesAndMissingOwner(boolean missingOwner) {
+ setUser("alice");
+ ProfileManager manager = Mockito.mock(ProfileManager.class);
+ Mockito.when(manager.getAllQueries()).thenReturn(missingOwner
+ ? List.of(profileRow(SummaryProfile.SUMMARY_KEYS, "query-id",
null)) : List.of());
+
Mockito.when(manager.getQueryInfoByColumnNameList(QueryProfileAction.PROFILE_TITLE_NAMES))
+ .thenReturn(missingOwner
+ ?
List.of(profileRow(QueryProfileAction.PROFILE_TITLE_NAMES, "query-id", null)) :
List.of());
+ try (MockedStatic<ProfileManager> managers =
Mockito.mockStatic(ProfileManager.class)) {
+ managers.when(ProfileManager::getInstance).thenReturn(manager);
+ Assertions.assertEquals(Map.of(), data(action.queryInfo(request,
response, "query-id", false)));
+ NodeAction.NodeInfo result = (NodeAction.NodeInfo)
data(action.queryInfo(request, response,
+ null, null, false));
+ Assertions.assertTrue(result.getRows().isEmpty());
+ }
+ }
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void forwardsCredentialsAndAggregatesLocalResults(boolean sqlEndpoint)
throws Exception {
+ setUser("Query");
+ ObjectMapper objectMapper = new ObjectMapper();
+ String authorization = "Basic synthetic-test-credential";
+
Mockito.when(request.getHeader(NodeAction.AUTHORIZATION)).thenReturn(authorization);
+ ProfileManager manager = Mockito.mock(ProfileManager.class);
+ Mockito.when(manager.getAllQueries()).thenReturn(List.of(
+ profileRow(SummaryProfile.SUMMARY_KEYS, "other-id", "bob"),
+ profileRow(SummaryProfile.SUMMARY_KEYS, "own-id", "Query")));
+
Mockito.when(manager.getQueryInfoByColumnNameList(QueryProfileAction.PROFILE_TITLE_NAMES))
+ .thenAnswer(invocation -> List.of(
+ profileRow(QueryProfileAction.PROFILE_TITLE_NAMES,
"other-id", "bob"),
+ profileRow(QueryProfileAction.PROFILE_TITLE_NAMES,
"own-id", "Query")));
+ Env env = Mockito.mock(Env.class);
+ Mockito.when(env.getSelfNode()).thenReturn(new HostInfo("127.0.0.1",
9010));
+ try (MockedStatic<ProfileManager> managers =
Mockito.mockStatic(ProfileManager.class);
+ MockedStatic<Env> environments = Mockito.mockStatic(Env.class);
+ MockedStatic<HttpUtils> http =
Mockito.mockStatic(HttpUtils.class)) {
+ managers.when(ProfileManager::getInstance).thenReturn(manager);
+ environments.when(Env::getCurrentEnv).thenReturn(env);
+ http.when(() -> HttpUtils.concatUrl(Mockito.any(),
Mockito.anyString(), Mockito.anyMap()))
+ .thenCallRealMethod();
+ http.when(() ->
HttpUtils.parseResponse(Mockito.anyString())).thenCallRealMethod();
+ http.when(HttpUtils::getFeList).thenReturn(List.of(
+ Pair.of("127.0.0.1", 8030), Pair.of("127.0.0.2", 8030)));
+ http.when(() -> HttpUtils.doGet(Mockito.anyString(),
Mockito.anyMap())).thenAnswer(invocation -> {
+ String url = invocation.getArgument(0);
+ Assertions.assertTrue(url.contains("is_all_node=false"));
+ Assertions.assertEquals(Map.of(NodeAction.AUTHORIZATION,
authorization), invocation.getArgument(1));
+ // Simulate each FE's local handler, including its ownership
filter.
+ Object local = sqlEndpoint ? action.queryInfo(request,
response, "own-id", false)
+ : action.queryInfo(request, response, null, null,
false);
+ // HTTP response bodies use Jackson. The persistence Gson
excludes their unannotated fields.
+ String json =
objectMapper.writeValueAsString(((ResponseEntity<?>) local).getBody());
+
Assertions.assertTrue(objectMapper.readTree(json).path("data").isObject());
+ return json;
+ });
+ if (sqlEndpoint) {
+ Assertions.assertEquals(Map.of("sql", "select 'own-id'"),
+ data(action.queryInfo(request, response, "own-id",
true)));
+ } else {
+ NodeAction.NodeInfo result = (NodeAction.NodeInfo)
data(action.queryInfo(request, response,
+ null, null, true));
+ Assertions.assertEquals(2, result.getRows().size());
+ for (List<String> row : result.getRows()) {
+ Assertions.assertEquals("own-id", row.get(0));
+ Assertions.assertEquals("Query", row.get(2));
+ }
+ }
+ http.verify(() -> HttpUtils.doGet(Mockito.anyString(),
Mockito.anyMap()), Mockito.times(2));
+ }
+ }
+
+ private static void setUser(String user) {
+ ConnectContext context = new ConnectContext();
+
context.setCurrentUserIdentity(UserIdentity.createAnalyzedUserIdentWithIp(user,
"%"));
+ context.setThreadLocalInfo();
+ }
+
+ private static Object data(Object result) {
+ ResponseBody<?> body = (ResponseBody<?>) ((ResponseEntity<?>)
result).getBody();
+ Assertions.assertNotNull(body);
+ Assertions.assertEquals(0, body.getCode());
+ return body.getData();
+ }
+
+ private static List<String> profileRow(List<String> columns, String id,
String user) {
+ List<String> row =
Lists.newArrayList(Collections.nCopies(columns.size(), "N/A"));
+ row.set(columns.indexOf(SummaryProfile.PROFILE_ID), id);
+ row.set(columns.indexOf(SummaryProfile.USER), user);
+ row.set(columns.indexOf(SummaryProfile.TASK_TYPE), "Query");
+ row.set(columns.indexOf(SummaryProfile.SQL_STATEMENT), "select '" + id
+ "'");
+ row.set(columns.indexOf(SummaryProfile.END_TIME), "2026-12-02
12:00:00");
+ if (columns.contains(QueryProfileAction.NODE)) {
+ row.set(columns.indexOf(QueryProfileAction.NODE), null);
+ }
+ return row;
+ }
+
@Test
void normalizesCurrentQueryRowsFromOldAndNewFrontends() {
List<String> currentTitles =
Lists.newArrayList(CurrentQueryStatisticsProcDir.TITLE_NAMES);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]