Skip to content

Commit 52b3a8a

Browse files
authored
[BugFix] Fix query profile API to return a unified JSON format (#67077)
Signed-off-by: zhaohehuhu <[email protected]>
1 parent 5b244bd commit 52b3a8a

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

fe/fe-core/src/main/java/com/starrocks/http/rest/v2/ProfileActionV2.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
package com.starrocks.http.rest.v2;
1616

17+
import com.google.gson.reflect.TypeToken;
1718
import com.starrocks.common.util.ProfileManager;
1819
import com.starrocks.http.ActionController;
1920
import com.starrocks.http.BaseRequest;
2021
import com.starrocks.http.BaseResponse;
2122
import com.starrocks.http.IllegalArgException;
2223
import com.starrocks.http.rest.RestBaseAction;
24+
import com.starrocks.persist.gson.GsonUtils;
2325
import io.netty.handler.codec.http.HttpMethod;
2426
import io.netty.handler.codec.http.HttpResponseStatus;
2527

@@ -66,10 +68,18 @@ protected void executeWithoutPassword(BaseRequest request, BaseResponse response
6668
// If the query profile is not found in the local fe's ProfileManager,
6769
// we will query other frontend nodes to get the query profile.
6870
String queryPath = String.format(QUERY_PLAN_URI, queryId);
69-
List<String> profileList = fetchResultFromOtherFrontendNodes(queryPath, authorization, HttpMethod.GET, false);
71+
List<String> profileList =
72+
fetchResultFromOtherFrontendNodes(queryPath, authorization, HttpMethod.GET, false);
7073
for (String profile : profileList) {
7174
if (profile != null) {
72-
sendSuccessResponse(response, profile, request);
75+
RestBaseResultV2<String> queryProfileResult = GsonUtils.GSON.fromJson(
76+
profile,
77+
new TypeToken<RestBaseResultV2<String>>() {
78+
}.getType());
79+
if (queryProfileResult == null || queryProfileResult.getResult() == null) {
80+
continue;
81+
}
82+
sendSuccessResponse(response, queryProfileResult.getResult(), request);
7383
return;
7484
}
7585
}

fe/fe-core/src/test/java/com/starrocks/http/rest/v2/ProfileActionV2Test.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414

1515
package com.starrocks.http.rest.v2;
1616

17+
import com.google.common.reflect.TypeToken;
18+
import com.google.gson.JsonElement;
19+
import com.google.gson.JsonSyntaxException;
1720
import com.starrocks.common.Pair;
1821
import com.starrocks.common.util.ProfileManager;
1922
import com.starrocks.ha.FrontendNodeType;
2023
import com.starrocks.http.StarRocksHttpTestCase;
24+
import com.starrocks.http.rest.ActionStatus;
2125
import com.starrocks.http.rest.RestBaseAction;
26+
import com.starrocks.persist.gson.GsonUtils;
2227
import com.starrocks.server.GlobalStateMgr;
2328
import com.starrocks.system.Frontend;
2429
import mockit.Expectations;
@@ -164,7 +169,15 @@ public String getProfile(String queryId) {
164169
.build();
165170
Response response = networkClient.newCall(request).execute();
166171
String respStr = response.body().string();
167-
Assertions.assertEquals(response.code(), 200);
168-
Assertions.assertTrue(respStr.contains("Query ID: eaff21d2-3734-11ee-909f-8e20563011de"));
172+
RestBaseResultV2<String> queryProfileResult = GsonUtils.GSON.fromJson(
173+
respStr,
174+
new TypeToken<RestBaseResultV2<String>>() {
175+
}.getType());
176+
Assertions.assertEquals(queryProfileResult.getStatus(), ActionStatus.OK);
177+
Assertions.assertTrue(queryProfileResult.getResult().contains("Query ID: eaff21d2-3734-11ee-909f-8e20563011de"));
178+
Assertions.assertThrows(
179+
JsonSyntaxException.class,
180+
() -> GsonUtils.GSON.fromJson(queryProfileResult.getResult(), JsonElement.class),
181+
"Query profile should be plain text, not a JSON object");
169182
}
170183
}

0 commit comments

Comments
 (0)