Skip to content

Commit b6128c3

Browse files
committed
fix: add traceId logics
1 parent f245097 commit b6128c3

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/containers/Tenant/Query/QueryResult/components/TraceButton/TraceButton.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ interface TraceUrlButtonProps {
1313
isTraceReady?: true;
1414
}
1515

16-
export function TraceButton({traceId, isTraceReady}: TraceUrlButtonProps) {
16+
export const TraceButton = React.memo(function TraceButton({
17+
traceId,
18+
isTraceReady,
19+
}: TraceUrlButtonProps) {
1720
const {traceCheck, traceView} = useClusterBaseInfo();
1821

1922
const checkTraceUrl = traceCheck?.url ? replaceParams(traceCheck.url, {traceId}) : '';
@@ -47,4 +50,4 @@ export function TraceButton({traceId, isTraceReady}: TraceUrlButtonProps) {
4750
</Button.Icon>
4851
</Button>
4952
);
50-
}
53+
});

src/services/api/viewer.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import type {DescribeTopicResult} from '../../types/api/topic';
3838
import type {TEvVDiskStateResponse} from '../../types/api/vdisk';
3939
import type {TUserToken} from '../../types/api/whoami';
4040
import type {QuerySyntax, TransactionMode} from '../../types/store/query';
41+
import type {StreamingChunk} from '../../types/store/streaming';
4142
import {BINARY_DATA_IN_PLAIN_TEXT_DISPLAY} from '../../utils/constants';
4243
import type {Nullable} from '../../utils/typecheckers';
4344
import {parseMultipart} from '../parsers/parseMultipart';
@@ -387,7 +388,13 @@ export class ViewerAPI extends BaseYdbAPI {
387388
limit_rows?: number;
388389
output_chunk_max_size?: number;
389390
},
390-
{concurrentId, signal, onChunk}: AxiosOptions & {onChunk?: (chunk: any) => void} = {},
391+
{
392+
concurrentId,
393+
signal,
394+
onChunk,
395+
}: AxiosOptions & {
396+
onChunk: (chunk: StreamingChunk) => void;
397+
},
391398
) {
392399
const base64 = !settingsManager.readUserSettingsValue(
393400
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
@@ -426,26 +433,27 @@ export class ViewerAPI extends BaseYdbAPI {
426433
let mergedChunk = null;
427434

428435
for (const chunk of chunks) {
429-
if (isSessionChunk(chunk) || isQueryResponseChunk(chunk)) {
430-
// First dispatch any accumulated data chunk
436+
if (isSessionChunk(chunk)) {
437+
const traceId = response
438+
.getResponseHeader('traceresponse')
439+
?.split('-')[1];
440+
chunk.meta.trace_id = traceId;
441+
onChunk(chunk);
442+
} else if (isQueryResponseChunk(chunk)) {
431443
if (mergedChunk) {
432444
onChunk?.(mergedChunk);
433445
mergedChunk = null;
434446
}
435-
// Then dispatch control chunk
436-
onChunk?.(chunk);
447+
onChunk(chunk);
437448
} else if (isStreamDataChunk(chunk)) {
438449
if (mergedChunk) {
439-
// Merge rows from subsequent chunks
440450
mergedChunk.result.rows.push(...chunk.result.rows);
441451
} else {
442-
// First data chunk - use as base with columns
443452
mergedChunk = chunk;
444453
}
445454
}
446455
}
447456

448-
// Dispatch any remaining merged chunk
449457
if (mergedChunk) {
450458
onChunk?.(mergedChunk);
451459
}

src/store/reducers/query/query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ const slice = createSlice({
144144

145145
if (isSessionChunk(chunk)) {
146146
state.result.queryId = chunk.meta.query_id;
147+
state.result.data.traceId = chunk.meta.trace_id;
147148
} else if (isStreamDataChunk(chunk)) {
148149
const {
149150
result: {columns, rows},

src/types/store/streaming.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export interface SessionChunk {
66
node_id: number;
77
query_id: string;
88
session_id: string;
9+
10+
// Custom client-set property.
11+
trace_id?: string;
912
};
1013
}
1114

0 commit comments

Comments
 (0)