Skip to content

Commit

Permalink
fix: add traceId logics
Browse files Browse the repository at this point in the history
  • Loading branch information
astandrik committed Jan 27, 2025
1 parent cb9a2e0 commit 65e12bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ interface TraceUrlButtonProps {
isTraceReady?: true;
}

export function TraceButton({traceId, isTraceReady}: TraceUrlButtonProps) {
export const TraceButton = React.memo(function TraceButton({
traceId,
isTraceReady,
}: TraceUrlButtonProps) {
const {traceCheck, traceView} = useClusterBaseInfo();

const checkTraceUrl = traceCheck?.url ? replaceParams(traceCheck.url, {traceId}) : '';
Expand Down Expand Up @@ -47,4 +50,4 @@ export function TraceButton({traceId, isTraceReady}: TraceUrlButtonProps) {
</Button.Icon>
</Button>
);
}
});
24 changes: 16 additions & 8 deletions src/services/api/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {DescribeTopicResult} from '../../types/api/topic';
import type {TEvVDiskStateResponse} from '../../types/api/vdisk';
import type {TUserToken} from '../../types/api/whoami';
import type {QuerySyntax, TransactionMode} from '../../types/store/query';
import type {StreamingChunk} from '../../types/store/streaming';
import {BINARY_DATA_IN_PLAIN_TEXT_DISPLAY} from '../../utils/constants';
import type {Nullable} from '../../utils/typecheckers';
import {parseMultipart} from '../parsers/parseMultipart';
Expand Down Expand Up @@ -387,7 +388,13 @@ export class ViewerAPI extends BaseYdbAPI {
limit_rows?: number;
output_chunk_max_size?: number;
},
{concurrentId, signal, onChunk}: AxiosOptions & {onChunk?: (chunk: any) => void} = {},
{
concurrentId,
signal,
onChunk,
}: AxiosOptions & {
onChunk: (chunk: StreamingChunk) => void;
},
) {
const base64 = !settingsManager.readUserSettingsValue(
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
Expand Down Expand Up @@ -426,26 +433,27 @@ export class ViewerAPI extends BaseYdbAPI {
let mergedChunk = null;

for (const chunk of chunks) {
if (isSessionChunk(chunk) || isQueryResponseChunk(chunk)) {
// First dispatch any accumulated data chunk
if (isSessionChunk(chunk)) {
const traceId = response
.getResponseHeader('traceresponse')
?.split('-')[1];
chunk.meta.trace_id = traceId;
onChunk(chunk);
} else if (isQueryResponseChunk(chunk)) {
if (mergedChunk) {
onChunk?.(mergedChunk);
mergedChunk = null;
}
// Then dispatch control chunk
onChunk?.(chunk);
onChunk(chunk);
} else if (isStreamDataChunk(chunk)) {
if (mergedChunk) {
// Merge rows from subsequent chunks
mergedChunk.result.rows.push(...chunk.result.rows);
} else {
// First data chunk - use as base with columns
mergedChunk = chunk;
}
}
}

// Dispatch any remaining merged chunk
if (mergedChunk) {
onChunk?.(mergedChunk);
}
Expand Down
1 change: 1 addition & 0 deletions src/store/reducers/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const slice = createSlice({

if (isSessionChunk(chunk)) {
state.result.queryId = chunk.meta.query_id;
state.result.data.traceId = chunk.meta.trace_id;
} else if (isStreamDataChunk(chunk)) {
const {
result: {columns, rows},
Expand Down
3 changes: 3 additions & 0 deletions src/types/store/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export interface SessionChunk {
node_id: number;
query_id: string;
session_id: string;

// Custom client-set property.
trace_id?: string;
};
}

Expand Down

0 comments on commit 65e12bc

Please sign in to comment.