Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]fix http query_info api return wrong column #43724

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ public void pushProfile(Profile profile) {
}

public List<List<String>> getAllQueries() {
return getQueryInfoByColumnNameList(SummaryProfile.SUMMARY_KEYS);
}

public List<List<String>> getQueryInfoByColumnNameList(List<String> columnNameList) {
List<List<String>> result = Lists.newArrayList();
readLock.lock();
try {
Expand All @@ -231,7 +235,7 @@ public List<List<String>> getAllQueries() {
ProfileElement profileElement = queueIdDeque.poll();
Map<String, String> infoStrings = profileElement.infoStrings;
List<String> row = Lists.newArrayList();
for (String str : SummaryProfile.SUMMARY_KEYS) {
for (String str : columnNameList) {
row.add(infoStrings.get(str));
}
result.add(row);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.doris.common.proc.ProcResult;
import org.apache.doris.common.profile.ProfileManager;
import org.apache.doris.common.profile.ProfileManager.ProfileElement;
import org.apache.doris.common.profile.SummaryProfile;
import org.apache.doris.common.util.NetUtils;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.httpv2.rest.RestBaseController;
Expand Down Expand Up @@ -105,6 +106,18 @@ public class QueryProfileAction extends RestBaseController {
.add(NODE).add(USER).add(DEFAULT_DB).add(SQL_STATEMENT).add(QUERY_TYPE).add(START_TIME).add(END_TIME)
.add(TOTAL).add(QUERY_STATE).build();

// As an old http api, query_info's output schema column is established since 1.2,
// so it can not be changed for compatibility.
// Now query_info api get data from ProfileManager, its column name is different but has the same meaning with
// QUERY_TITLE_NAMES.
// We should keep PROFILE_TITLE_NAMES and QUERY_TITLE_NAMES has the same meaning, and use PROFILE_TITLE_NAMES
// to get data from profile manager.
public static final ImmutableList<String> PROFILE_TITLE_NAMES = new ImmutableList.Builder<String>()
.add(SummaryProfile.PROFILE_ID).add(NODE)
.add(SummaryProfile.USER).add(SummaryProfile.DEFAULT_DB).add(SummaryProfile.SQL_STATEMENT)
.add(SummaryProfile.TASK_TYPE).add(SummaryProfile.START_TIME).add(SummaryProfile.END_TIME)
.add(SummaryProfile.TOTAL_TIME).add(SummaryProfile.TASK_STATE).build();

private List<String> requestAllFe(String httpPath, Map<String, String> arguments, String authorization,
HttpMethod method) {
List<Pair<String, Integer>> frontends = HttpUtils.getFeList();
Expand Down Expand Up @@ -169,14 +182,15 @@ public Object queryInfo(HttpServletRequest request, HttpServletResponse response
return ResponseEntityBuilder.ok(new NodeAction.NodeInfo(QUERY_TITLE_NAMES, queries));
}

Stream<List<String>> queryStream = ProfileManager.getInstance().getAllQueries().stream()
.filter(profile -> profile.get(1).equalsIgnoreCase("Query"));
Stream<List<String>> queryStream = ProfileManager.getInstance()
.getQueryInfoByColumnNameList(PROFILE_TITLE_NAMES).stream()
.filter(profile -> profile.get(5).equalsIgnoreCase("Query"));
queryStream = filterQueriesByUserAndQueryId(queryStream, queryId);
queries = queryStream.collect(Collectors.toList());

// add node information
for (List<String> query : queries) {
query.add(1, NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
query.set(1, NetUtils.getHostPortInAccessibleFormat(Env.getCurrentEnv().getSelfNode().getHost(),
Config.http_port));
}

Expand Down
Loading