Skip to content

Commit c6eb013

Browse files
committed
fix: logs page error messages with trace id
1 parent d95772a commit c6eb013

File tree

2 files changed

+155
-40
lines changed

2 files changed

+155
-40
lines changed

web/src/composables/useLogs.ts

Lines changed: 153 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ const useLogs = () => {
10161016
} catch (e: any) {
10171017
// showErrorNotification("Invalid SQL Syntax");
10181018
console.log(e);
1019-
notificationMsg.value = "An error occurred while constructing the search query.";
1019+
notificationMsg.value =
1020+
"An error occurred while constructing the search query.";
10201021
return "";
10211022
}
10221023
}
@@ -1045,7 +1046,8 @@ const useLogs = () => {
10451046
const parsedSQL: any = fnParsedSQL();
10461047

10471048
if (searchObj.meta.sqlMode && parsedSQL == undefined) {
1048-
searchObj.data.queryResults.error = "Error while search partition. Search query is invalid.";
1049+
searchObj.data.queryResults.error =
1050+
"Error while search partition. Search query is invalid.";
10491051
return;
10501052
}
10511053

@@ -1318,7 +1320,8 @@ const useLogs = () => {
13181320
Math.max(parseInt(currentValue.zo_sql_num, 10), 0),
13191321
0
13201322
);
1321-
partitionDetail.partitionTotal[0] = searchObj.data.queryResults.total;
1323+
partitionDetail.partitionTotal[0] =
1324+
searchObj.data.queryResults.total;
13221325
}
13231326
} else {
13241327
searchObj.data.queryResults.total =
@@ -1457,7 +1460,7 @@ const useLogs = () => {
14571460
isNaN(searchObj.data.datetime.startTime)
14581461
) {
14591462
const queryParams: any = router.currentRoute.value.query;
1460-
let currentPeriod: string = queryParams?.period || "15m";
1463+
const currentPeriod: string = queryParams?.period || "15m";
14611464
const extractedDate: any = extractTimestamps(currentPeriod);
14621465
searchObj.data.datetime.startTime = extractedDate.from;
14631466
searchObj.data.datetime.endTime = extractedDate.to;
@@ -1539,11 +1542,11 @@ const useLogs = () => {
15391542
searchObj.data.histogramQuery.query.sql_mode = "full";
15401543

15411544
// searchObj.data.histogramQuery.query.start_time =
1542-
// queryReq.query.start_time;
1543-
1545+
// queryReq.query.start_time;
1546+
15441547
// searchObj.data.histogramQuery.query.end_time =
15451548
// queryReq.query.end_time;
1546-
1549+
15471550
delete searchObj.data.histogramQuery.query.quick_mode;
15481551
delete searchObj.data.histogramQuery.query.from;
15491552

@@ -1625,7 +1628,7 @@ const useLogs = () => {
16251628
searchObj.data.stream.selectedStream.length <= 1 &&
16261629
searchObj.data.resultGrid.currentPage == 1)
16271630
) {
1628-
if(searchObj.data.queryResults.hits.length > 0) {
1631+
if (searchObj.data.queryResults.hits.length > 0) {
16291632
await getHistogramQueryData(searchObj.data.histogramQuery);
16301633
}
16311634
refreshPartitionPagination(true);
@@ -1647,7 +1650,11 @@ const useLogs = () => {
16471650
if (parsedSQL) {
16481651
aggFlag = hasAggregation(parsedSQL?.columns);
16491652
}
1650-
if (queryReq.query.from == 0 && searchObj.data.queryResults.hits.length > 0 && !aggFlag) {
1653+
if (
1654+
queryReq.query.from == 0 &&
1655+
searchObj.data.queryResults.hits.length > 0 &&
1656+
!aggFlag
1657+
) {
16511658
setTimeout(async () => {
16521659
searchObjDebug["pagecountStartTime"] = performance.now();
16531660
await getPageCount(queryReq);
@@ -1678,7 +1685,7 @@ const useLogs = () => {
16781685
}
16791686
} else {
16801687
searchObj.loading = false;
1681-
if(!notificationMsg.value) {
1688+
if (!notificationMsg.value) {
16821689
notificationMsg.value = "Search query is empty or invalid.";
16831690
}
16841691
}
@@ -1692,7 +1699,9 @@ const useLogs = () => {
16921699
console.log("=================== getQueryData Debug ===================");
16931700
} catch (e: any) {
16941701
searchObj.loading = false;
1695-
showErrorNotification(notificationMsg.value || "Error occurred during the search operation.");
1702+
showErrorNotification(
1703+
notificationMsg.value || "Error occurred during the search operation."
1704+
);
16961705
notificationMsg.value = "";
16971706
}
16981707
};
@@ -1822,11 +1831,21 @@ const useLogs = () => {
18221831
})
18231832
.catch((err) => {
18241833
searchObj.loading = false;
1825-
searchObj.data.errorMsg = "Error while processing search total count request.";
1834+
let trace_id = "";
1835+
searchObj.data.errorMsg = "Error while processing search request.";
18261836
if (err.response != undefined) {
1827-
searchObj.data.errorMsg = err.response.data.error;
1837+
searchObj.data.errorMsg =
1838+
err.response.data.error +
1839+
" TraceID:" +
1840+
err.response.data?.trace_id;
1841+
if (err.response.data.hasOwnProperty("trace_id")) {
1842+
trace_id = err.response.data?.trace_id;
1843+
}
18281844
} else {
1829-
searchObj.data.errorMsg = err.message;
1845+
searchObj.data.errorMsg = err.message + " TraceID:" + err?.trace_id;
1846+
if (err.hasOwnProperty("trace_id")) {
1847+
trace_id = err?.trace_id;
1848+
}
18301849
}
18311850

18321851
const customMessage = logsErrorMessage(err?.response?.data.code);
@@ -1838,9 +1857,19 @@ const useLogs = () => {
18381857

18391858
notificationMsg.value = searchObj.data.errorMsg;
18401859

1841-
if (err?.response?.data?.code == 429) {
1842-
notificationMsg.value = err.response.data.message;
1843-
searchObj.data.errorMsg = err.response.data.message;
1860+
if (err?.request?.status >= 429) {
1861+
notificationMsg.value = err?.response?.data?.message;
1862+
searchObj.data.errorMsg =
1863+
err?.response?.data?.message;
1864+
}
1865+
1866+
if (trace_id) {
1867+
searchObj.data.errorMsg +=
1868+
" <br><span class='text-subtitle1'>TraceID:" +
1869+
trace_id +
1870+
"</span>";
1871+
notificationMsg.value += " TraceID:" + trace_id;
1872+
trace_id = "";
18441873
}
18451874
reject(false);
18461875
});
@@ -2092,11 +2121,24 @@ const useLogs = () => {
20922121
})
20932122
.catch((err) => {
20942123
searchObj.loading = false;
2095-
searchObj.data.errorMsg = "Error while processing search request.";
2124+
let trace_id = "";
2125+
searchObj.data.errorMsg =
2126+
typeof err == "string" && err
2127+
? err
2128+
: "Error while processing histogram request.";
20962129
if (err.response != undefined) {
2097-
searchObj.data.errorMsg = err.response.data.error;
2130+
searchObj.data.errorMsg =
2131+
err.response.data.error +
2132+
" TraceID:" +
2133+
err.response.data?.trace_id;
2134+
if (err.response.data.hasOwnProperty("trace_id")) {
2135+
trace_id = err.response.data?.trace_id;
2136+
}
20982137
} else {
2099-
searchObj.data.errorMsg = err.message;
2138+
searchObj.data.errorMsg = err.message + " TraceID:" + err?.trace_id;
2139+
if (err.hasOwnProperty("trace_id")) {
2140+
trace_id = err?.trace_id;
2141+
}
21002142
}
21012143

21022144
const customMessage = logsErrorMessage(err?.response?.data.code);
@@ -2108,10 +2150,21 @@ const useLogs = () => {
21082150

21092151
notificationMsg.value = searchObj.data.errorMsg;
21102152

2111-
if (err?.response?.data?.code == 429) {
2112-
notificationMsg.value = err.response.data.message;
2113-
searchObj.data.errorMsg = err.response.data.message;
2153+
if (err?.request?.status >= 429) {
2154+
notificationMsg.value = err?.response?.data?.message;
2155+
searchObj.data.errorMsg =
2156+
err?.response?.data?.message;
2157+
}
2158+
2159+
if (trace_id) {
2160+
searchObj.data.errorMsg +=
2161+
" <br><span class='text-subtitle1'>TraceID:" +
2162+
trace_id +
2163+
"</span>";
2164+
notificationMsg.value += " TraceID:" + trace_id;
2165+
trace_id = "";
21142166
}
2167+
21152168
reject(false);
21162169
});
21172170
});
@@ -2194,7 +2247,8 @@ const useLogs = () => {
21942247
searchObj.data.queryResults.aggs = res.data.hits;
21952248
searchObj.data.queryResults.scan_size = res.data.scan_size;
21962249
searchObj.data.queryResults.took += res.data.took;
2197-
searchObj.data.queryResults.result_cache_ratio += res.data.result_cache_ratio;
2250+
searchObj.data.queryResults.result_cache_ratio +=
2251+
res.data.result_cache_ratio;
21982252
// if (hasAggregationFlag) {
21992253
// searchObj.data.queryResults.total = res.data.total;
22002254
// }
@@ -2233,11 +2287,25 @@ const useLogs = () => {
22332287
})
22342288
.catch((err) => {
22352289
searchObj.loadingHistogram = false;
2236-
searchObj.data.errorMsg = "Error while processing histogram request.";
2290+
let trace_id = "";
2291+
searchObj.data.histogram.errorMsg =
2292+
typeof err == "string" && err
2293+
? err
2294+
: "Error while processing histogram request.";
22372295
if (err.response != undefined) {
2238-
searchObj.data.histogram.errorMsg = err.response.data.error;
2296+
searchObj.data.histogram.errorMsg =
2297+
err.response.data.error +
2298+
" TraceID:" +
2299+
err.response.data?.trace_id;
2300+
if (err.response.data.hasOwnProperty("trace_id")) {
2301+
trace_id = err.response.data?.trace_id;
2302+
}
22392303
} else {
2240-
searchObj.data.histogram.errorMsg = err.message;
2304+
searchObj.data.histogram.errorMsg =
2305+
err.message + " TraceID:" + err?.trace_id;
2306+
if (err.hasOwnProperty("trace_id")) {
2307+
trace_id = err?.trace_id;
2308+
}
22412309
}
22422310

22432311
const customMessage = logsErrorMessage(err?.response?.data.code);
@@ -2251,9 +2319,21 @@ const useLogs = () => {
22512319

22522320
notificationMsg.value = searchObj.data.histogram.errorMsg;
22532321

2254-
if (err?.response?.data?.code == 429) {
2255-
notificationMsg.value = err.response.data.message;
2256-
searchObj.data.histogram.errorMsg = err.response.data.message;
2322+
if (err?.request?.status >= 429) {
2323+
notificationMsg.value = err?.response?.data?.message;
2324+
searchObj.data.histogram.errorMsg =
2325+
err?.response?.data?.message;
2326+
searchObj.data.histogram.errorDetail =
2327+
err?.response?.data?.error_detail;
2328+
}
2329+
2330+
if (trace_id) {
2331+
searchObj.data.histogram.errorMsg +=
2332+
" <br><span class='text-subtitle1'>TraceID:" +
2333+
trace_id +
2334+
"</span>";
2335+
notificationMsg.value += " TraceID:" + trace_id;
2336+
trace_id = "";
22572337
}
22582338

22592339
reject(false);
@@ -2869,7 +2949,8 @@ const useLogs = () => {
28692949
function getHistogramTitle() {
28702950
try {
28712951
const currentPage = searchObj.data.resultGrid.currentPage - 1 || 0;
2872-
const startCount = currentPage * searchObj.meta.resultGrid.rowsPerPage + 1;
2952+
const startCount =
2953+
currentPage * searchObj.meta.resultGrid.rowsPerPage + 1;
28732954
let endCount;
28742955

28752956
let totalCount = searchObj.data.queryResults.total || 0;
@@ -2903,10 +2984,17 @@ const useLogs = () => {
29032984
}
29042985

29052986
let plusSign: string = "";
2906-
if(searchObj.data.queryResults.partitionDetail.partitions.length > 1 && searchObj.meta.showHistogram == false) {
2987+
if (
2988+
searchObj.data.queryResults.partitionDetail.partitions.length > 1 &&
2989+
searchObj.meta.showHistogram == false
2990+
) {
29072991
plusSign = "+";
29082992
}
2909-
const scanSizeLabel = (searchObj.data.queryResults.result_cache_ratio !== undefined && searchObj.data.queryResults.result_cache_ratio > 0)? "Delta Scan Size" : "Scan Size";
2993+
const scanSizeLabel =
2994+
searchObj.data.queryResults.result_cache_ratio !== undefined &&
2995+
searchObj.data.queryResults.result_cache_ratio > 0
2996+
? "Delta Scan Size"
2997+
: "Scan Size";
29102998

29112999
const title =
29123000
"Showing " +
@@ -2918,7 +3006,9 @@ const useLogs = () => {
29183006
plusSign +
29193007
" events in " +
29203008
searchObj.data.queryResults.took +
2921-
" ms. (" + scanSizeLabel + ": " +
3009+
" ms. (" +
3010+
scanSizeLabel +
3011+
": " +
29223012
formatSizeFromMB(searchObj.data.queryResults.scan_size) +
29233013
plusSign +
29243014
")";
@@ -3155,17 +3245,42 @@ const useLogs = () => {
31553245
// }, 500);
31563246
})
31573247
.catch((err) => {
3248+
let trace_id = "";
3249+
searchObj.data.errorMsg = "Error while processing search request.";
31583250
if (err.response != undefined) {
3159-
searchObj.data.errorMsg = err.response.data.error;
3251+
searchObj.data.errorMsg =
3252+
err.response.data.error +
3253+
" TraceID:" +
3254+
err.response.data?.trace_id;
3255+
if (err.response.data.hasOwnProperty("trace_id")) {
3256+
trace_id = err.response.data?.trace_id;
3257+
}
31603258
} else {
3161-
searchObj.data.errorMsg = err.message;
3259+
searchObj.data.errorMsg = err.message + " TraceID:" + err?.trace_id;
3260+
if (err.hasOwnProperty("trace_id")) {
3261+
trace_id = err?.trace_id;
3262+
}
31623263
}
31633264

31643265
const customMessage = logsErrorMessage(err.response.data.code);
31653266
searchObj.data.errorCode = err.response.data.code;
31663267
if (customMessage != "") {
31673268
searchObj.data.errorMsg = customMessage;
31683269
}
3270+
3271+
if (err?.request?.status >= 429) {
3272+
notificationMsg.value = err?.response?.data?.message;
3273+
searchObj.data.errorMsg =
3274+
err?.response?.data?.message;
3275+
}
3276+
3277+
if (trace_id) {
3278+
searchObj.data.errorMsg +=
3279+
" <br><span class='text-subtitle1'>TraceID:" +
3280+
trace_id +
3281+
"</span>";
3282+
trace_id = "";
3283+
}
31693284
})
31703285
.finally(() => (searchObj.loading = false));
31713286
} catch (e: any) {
@@ -3175,7 +3290,7 @@ const useLogs = () => {
31753290
};
31763291

31773292
const refreshData = () => {
3178-
try{
3293+
try {
31793294
if (
31803295
searchObj.meta.refreshInterval > 0 &&
31813296
router.currentRoute.value.name == "logs"
@@ -3194,7 +3309,7 @@ const useLogs = () => {
31943309
store.dispatch("setRefreshIntervalID", refreshIntervalID);
31953310

31963311
// only notify if user is in logs page
3197-
if(searchObj.meta.logsVisualizeToggle == "logs"){
3312+
if (searchObj.meta.logsVisualizeToggle == "logs") {
31983313
$q.notify({
31993314
message: `Live mode is enabled. Only top ${searchObj.meta.resultGrid.rowsPerPage} results are shown.`,
32003315
color: "positive",

web/src/plugins/logs/SearchResult.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
111111
><br />
112112
<span v-if="disableMoreErrorDetails">
113113
{{ searchObj.data.histogram.errorMsg }}
114-
{{ searchObj.data.histogram.errorDetail }}
115114
</span>
116115
</h6>
117116
<h6 class="text-center" v-else>
118117
{{ searchObj.data.histogram.errorMsg }}
119-
{{ searchObj.data.histogram.errorDetail }}
120118
</h6>
121119
</div>
122120
<q-virtual-scroll
@@ -467,6 +465,7 @@ import EqualIcon from "../../components/icons/EqualIcon.vue";
467465
import NotEqualIcon from "../../components/icons/NotEqualIcon.vue";
468466
import useLogs from "../../composables/useLogs";
469467
import { convertLogData } from "@/utils/logs/convertLogData";
468+
import SanitizedHtmlRenderer from "@/components/SanitizedHtmlRenderer.vue";
470469
471470
export default defineComponent({
472471
name: "SearchResult",
@@ -479,6 +478,7 @@ export default defineComponent({
479478
ChartRenderer: defineAsyncComponent(
480479
() => import("@/components/dashboards/panels/ChartRenderer.vue")
481480
),
481+
SanitizedHtmlRenderer,
482482
},
483483
emits: [
484484
"update:scroll",

0 commit comments

Comments
 (0)