This is an automated email from the ASF dual-hosted git repository.
yiguolei 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 061b28b32e [Fix](profile) fix /rest/v1/query_profile action. (#15981)
061b28b32e is described below
commit 061b28b32e4fff41cdfdb25e0435d3bb0abe1639
Author: wxy <[email protected]>
AuthorDate: Tue Jan 17 20:21:48 2023 +0800
[Fix](profile) fix /rest/v1/query_profile action. (#15981)
Co-authored-by: [email protected] <[email protected]>
---
.../apache/doris/common/util/ProfileManager.java | 4 +-
.../httpv2/controller/QueryProfileController.java | 47 +++++++++++++++-------
2 files changed, 35 insertions(+), 16 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
index ae945c543e..cd868d1ae6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/ProfileManager.java
@@ -32,8 +32,8 @@ import org.apache.commons.lang3.tuple.Triple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
@@ -85,7 +85,7 @@ public class ProfileManager {
LOAD,
}
- public static final ArrayList<String> PROFILE_HEADERS = new ArrayList(
+ public static final List<String> PROFILE_HEADERS =
Collections.unmodifiableList(
Arrays.asList(JOB_ID, QUERY_ID, USER, DEFAULT_DB, SQL_STATEMENT,
QUERY_TYPE,
START_TIME, END_TIME, TOTAL_TIME, QUERY_STATE, TRACE_ID));
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/QueryProfileController.java
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/QueryProfileController.java
index 1b349aad02..45178a860c 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/QueryProfileController.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/QueryProfileController.java
@@ -41,13 +41,14 @@ import java.util.Map;
public class QueryProfileController extends BaseController {
private static final Logger LOG =
LogManager.getLogger(QueryProfileController.class);
- private static final String QUERY_ID = "query_id";
+ private static final String ID = "id";
+ private static final String DETAIL_COL = "Detail";
- @RequestMapping(path = "/query_profile/{" + QUERY_ID + "}", method =
RequestMethod.GET)
- public Object profile(@PathVariable(value = QUERY_ID) String queryId) {
- String profile = ProfileManager.getInstance().getProfile(queryId);
+ @RequestMapping(path = "/query_profile/{" + ID + "}", method =
RequestMethod.GET)
+ public Object profile(@PathVariable(value = ID) String id) {
+ String profile = ProfileManager.getInstance().getProfile(id);
if (profile == null) {
- return ResponseEntityBuilder.okWithCommonError("Query " + queryId
+ " does not exist");
+ return ResponseEntityBuilder.okWithCommonError("ID " + id + " does
not exist");
}
profile = profile.replaceAll("\n", "</br>");
profile = profile.replaceAll(" ", " ");
@@ -65,33 +66,51 @@ public class QueryProfileController extends BaseController {
private void addFinishedQueryInfo(Map<String, Object> result) {
List<List<String>> finishedQueries =
ProfileManager.getInstance().getAllQueries();
- List<String> columnHeaders = ProfileManager.PROFILE_HEADERS;
- int queryIdIndex = 0; // the first column is 'Query ID' by default
+ List<String> columnHeaders =
Lists.newLinkedList(ProfileManager.PROFILE_HEADERS);
+ int jobIdIndex = -1;
+ int queryIdIndex = -1;
+ int queryTypeIndex = -1;
for (int i = 0; i < columnHeaders.size(); ++i) {
+ if (columnHeaders.get(i).equals(ProfileManager.JOB_ID)) {
+ jobIdIndex = i;
+ continue;
+ }
if (columnHeaders.get(i).equals(ProfileManager.QUERY_ID)) {
queryIdIndex = i;
- break;
+ continue;
+ }
+ if (columnHeaders.get(i).equals(ProfileManager.QUERY_TYPE)) {
+ queryTypeIndex = i;
+ continue;
}
}
+ // set href as the first column
+ columnHeaders.add(0, DETAIL_COL);
result.put("column_names", columnHeaders);
- result.put("href_column", Lists.newArrayList(ProfileManager.QUERY_ID));
+ result.put("href_column", Lists.newArrayList(DETAIL_COL));
List<Map<String, Object>> list = Lists.newArrayList();
result.put("rows", list);
for (List<String> row : finishedQueries) {
- String queryId = row.get(queryIdIndex);
+ List<String> realRow = Lists.newLinkedList(row);
+
+ String queryType = realRow.get(queryTypeIndex);
+ String id = "Query".equals(queryType) ? realRow.get(queryIdIndex)
: realRow.get(jobIdIndex);
+
+ realRow.add(0, id);
Map<String, Object> rowMap = new HashMap<>();
- for (int i = 0; i < row.size(); ++i) {
- rowMap.put(columnHeaders.get(i), row.get(i));
+ for (int i = 0; i < realRow.size(); ++i) {
+ rowMap.put(columnHeaders.get(i), realRow.get(i));
}
// add hyper link
- if (Strings.isNullOrEmpty(queryId)) {
+ if (Strings.isNullOrEmpty(id)) {
rowMap.put("__hrefPaths",
Lists.newArrayList("/query_profile/-1"));
} else {
- rowMap.put("__hrefPaths", Lists.newArrayList("/query_profile/"
+ queryId));
+ rowMap.put("__hrefPaths", Lists.newArrayList("/query_profile/"
+ id));
}
+
list.add(rowMap);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]