fix: logs container
This commit is contained in:
@@ -2,6 +2,7 @@ export default {
|
|||||||
'resources.title': 'Resources',
|
'resources.title': 'Resources',
|
||||||
'resources.nodes': 'Workers',
|
'resources.nodes': 'Workers',
|
||||||
'resources.worker': 'Worker',
|
'resources.worker': 'Worker',
|
||||||
|
'resources.container': 'Container',
|
||||||
'resources.button.create': 'Add Worker',
|
'resources.button.create': 'Add Worker',
|
||||||
'resources.button.edit': 'Edit Worker',
|
'resources.button.edit': 'Edit Worker',
|
||||||
'resources.button.edittags': 'Edit Labels',
|
'resources.button.edittags': 'Edit Labels',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
'resources.title': 'リソース',
|
'resources.title': 'リソース',
|
||||||
'resources.nodes': 'ノード',
|
'resources.nodes': 'ノード',
|
||||||
|
'resources.container': 'コンテナ',
|
||||||
'resources.button.create': 'ワーカーを追加',
|
'resources.button.create': 'ワーカーを追加',
|
||||||
'resources.button.edit': 'ワーカーを編集',
|
'resources.button.edit': 'ワーカーを編集',
|
||||||
'resources.button.edittags': 'ラベルを編集',
|
'resources.button.edittags': 'ラベルを編集',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
'resources.title': 'Ресурсы',
|
'resources.title': 'Ресурсы',
|
||||||
'resources.nodes': 'Ноды',
|
'resources.nodes': 'Ноды',
|
||||||
|
'resources.container': 'Контейнер',
|
||||||
'resources.button.create': 'Добавить воркер',
|
'resources.button.create': 'Добавить воркер',
|
||||||
'resources.button.edit': 'Редактировать воркер',
|
'resources.button.edit': 'Редактировать воркер',
|
||||||
'resources.button.edittags': 'Редактировать метки',
|
'resources.button.edittags': 'Редактировать метки',
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export default {
|
|||||||
'resources.title': 'Kaynaklar',
|
'resources.title': 'Kaynaklar',
|
||||||
'resources.nodes': 'İşçi Düğümler',
|
'resources.nodes': 'İşçi Düğümler',
|
||||||
'resources.worker': 'İşçi Düğüm',
|
'resources.worker': 'İşçi Düğüm',
|
||||||
|
'resources.container': 'Konteyner',
|
||||||
'resources.button.create': 'İşçi Düğüm Ekle',
|
'resources.button.create': 'İşçi Düğüm Ekle',
|
||||||
'resources.button.edit': 'İşçi Düğümü Düzenle',
|
'resources.button.edit': 'İşçi Düğümü Düzenle',
|
||||||
'resources.button.edittags': 'Etiketleri Düzenle',
|
'resources.button.edittags': 'Etiketleri Düzenle',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export default {
|
|||||||
'resources.button.update': '更新标签',
|
'resources.button.update': '更新标签',
|
||||||
'resources.nodes': '节点',
|
'resources.nodes': '节点',
|
||||||
'resources.worker': '节点',
|
'resources.worker': '节点',
|
||||||
|
'resources.container': '容器',
|
||||||
'resources.table.hostname': '主机名',
|
'resources.table.hostname': '主机名',
|
||||||
'resources.table.key.tips': '存在相同的 key.',
|
'resources.table.key.tips': '存在相同的 key.',
|
||||||
'resources.form.label': '标签',
|
'resources.form.label': '标签',
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import useSetChunkRequest from '@/hooks/use-chunk-request';
|
|||||||
import { CloseOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
import { CloseOutlined, QuestionCircleOutlined } from '@ant-design/icons';
|
||||||
import { BaseSelect, LogsViewer } from '@gpustack/core-ui';
|
import { BaseSelect, LogsViewer } from '@gpustack/core-ui';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Checkbox, Modal, Tooltip } from 'antd';
|
import { Button, Checkbox, Flex, Modal, Tooltip } from 'antd';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { MODELS_API } from '../apis';
|
import { MODELS_API } from '../apis';
|
||||||
|
|
||||||
@@ -27,7 +28,9 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
const [isDownloading, setIsDownloading] = useState<boolean>(
|
const [isDownloading, setIsDownloading] = useState<boolean>(
|
||||||
status === InstanceStatusMap.Downloading
|
status === InstanceStatusMap.Downloading
|
||||||
);
|
);
|
||||||
const [selectedWorkerID, setSelectedWorkerID] = useState<number | null>(null);
|
const [selectedContainer, setSelectedContainer] = useState<string | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
const [params, setParams] = useState<any>({
|
const [params, setParams] = useState<any>({
|
||||||
follow: true
|
follow: true
|
||||||
});
|
});
|
||||||
@@ -40,10 +43,17 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
|
|
||||||
const currentWorkerCountList = useMemo(() => {
|
const currentWorkerCountList = useMemo(() => {
|
||||||
return (
|
return (
|
||||||
countOptions?.find((option) => option.worker_id === selectedWorkerID)
|
countOptions?.find((option) => option.value === selectedContainer)
|
||||||
?.children || []
|
?.children || []
|
||||||
);
|
);
|
||||||
}, [countOptions, selectedWorkerID]);
|
}, [countOptions, selectedContainer]);
|
||||||
|
|
||||||
|
const filteredCountOptions = useMemo(() => {
|
||||||
|
if (!showPrevious) return countOptions;
|
||||||
|
return countOptions?.filter((option) =>
|
||||||
|
option.children?.some((child) => child.previous)
|
||||||
|
);
|
||||||
|
}, [countOptions, showPrevious]);
|
||||||
|
|
||||||
const handleCancel = useCallback(() => {
|
const handleCancel = useCallback(() => {
|
||||||
logsViewerRef.current?.abort();
|
logsViewerRef.current?.abort();
|
||||||
@@ -88,7 +98,7 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
const cancelOnClose = () => {
|
const cancelOnClose = () => {
|
||||||
logsViewerRef.current?.abort();
|
logsViewerRef.current?.abort();
|
||||||
requestRef.current?.current?.cancel?.();
|
requestRef.current?.current?.cancel?.();
|
||||||
setSelectedWorkerID(null);
|
setSelectedContainer(null);
|
||||||
setShowPrevious(false);
|
setShowPrevious(false);
|
||||||
cancelRequest();
|
cancelRequest();
|
||||||
};
|
};
|
||||||
@@ -103,14 +113,15 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
follow: true,
|
follow: true,
|
||||||
watch: !option.previous,
|
watch: !option.previous,
|
||||||
previous: option.previous,
|
previous: option.previous,
|
||||||
worker_id: option.worker_id
|
worker_id: option.worker_id,
|
||||||
|
container: option.container
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setSelectedWorkerID(option?.worker_id || null);
|
setSelectedContainer(option?.parentValue || null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleWorkerChange = (value: number, option: any) => {
|
const handleContainerChange = (value: string, option: any) => {
|
||||||
setSelectedWorkerID(value);
|
setSelectedContainer(value);
|
||||||
setShowPrevious(false);
|
setShowPrevious(false);
|
||||||
const counts = option?.children || [];
|
const counts = option?.children || [];
|
||||||
const lastItem = counts.find((item: any) => !item.previous);
|
const lastItem = counts.find((item: any) => !item.previous);
|
||||||
@@ -132,8 +143,22 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
handleOnChange(selectItem);
|
handleOnChange(selectItem);
|
||||||
};
|
};
|
||||||
|
|
||||||
const labelRender = (option: any) => {
|
const optionRender = (option: any) => {
|
||||||
return <span style={{ fontWeight: 400 }}>{option.label}</span>;
|
const optionData = option?.data || option;
|
||||||
|
const [container, worker] = optionData.label.split(':');
|
||||||
|
const startAt = optionData.start_at
|
||||||
|
? dayjs(optionData.start_at).format('YYYY-MM-DD HH:mm:ss')
|
||||||
|
: '';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Flex align="center" justify="space-between">
|
||||||
|
<Flex align="center" gap={8}>
|
||||||
|
<span>{container}</span>
|
||||||
|
<span className="text-tertiary">[{worker}]</span>
|
||||||
|
</Flex>
|
||||||
|
{startAt && <span className="text-tertiary">{startAt}</span>}
|
||||||
|
</Flex>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderTitle = () => {
|
const renderTitle = () => {
|
||||||
@@ -189,14 +214,15 @@ const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
marginRight: 8
|
marginRight: 8
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{intl.formatMessage({ id: 'resources.worker' })}
|
{intl.formatMessage({ id: 'resources.container' })}
|
||||||
</span>
|
</span>
|
||||||
}
|
}
|
||||||
options={countOptions}
|
options={filteredCountOptions}
|
||||||
value={selectedWorkerID || undefined}
|
value={selectedContainer || undefined}
|
||||||
labelRender={labelRender}
|
labelRender={optionRender}
|
||||||
onChange={handleWorkerChange}
|
optionRender={optionRender}
|
||||||
style={{ width: 300 }}
|
onChange={handleContainerChange}
|
||||||
|
style={{ width: 360 }}
|
||||||
></BaseSelect>
|
></BaseSelect>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -384,6 +384,8 @@ export interface InstanceRestartCount {
|
|||||||
restarts: {
|
restarts: {
|
||||||
previous: boolean;
|
previous: boolean;
|
||||||
started_at: string;
|
started_at: string;
|
||||||
|
containers: string[];
|
||||||
}[];
|
}[];
|
||||||
|
error?: string | null;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,18 +6,21 @@ import { InstanceRestartCount } from '../config/types';
|
|||||||
|
|
||||||
interface RestartCountOption {
|
interface RestartCountOption {
|
||||||
label: string;
|
label: string;
|
||||||
value: number;
|
value: string;
|
||||||
worker_id: number;
|
worker_id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
container: string;
|
||||||
|
start_at: string;
|
||||||
isParent: boolean;
|
isParent: boolean;
|
||||||
|
isMain: boolean;
|
||||||
children?: {
|
children?: {
|
||||||
value: number;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
start_at: string;
|
start_at: string;
|
||||||
previous: boolean;
|
previous: boolean;
|
||||||
worker_id: number;
|
worker_id: number;
|
||||||
isCurrent: boolean;
|
container: string;
|
||||||
isPrevious: boolean;
|
parentValue: string;
|
||||||
}[];
|
}[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,32 +37,48 @@ export default function useQueryModelInstanceRestartCount() {
|
|||||||
const res = await fetchData(instance_id);
|
const res = await fetchData(instance_id);
|
||||||
|
|
||||||
const list =
|
const list =
|
||||||
res.workers?.map((worker) => {
|
res.workers?.flatMap((worker) => {
|
||||||
return {
|
const containerMap = new Map<string, RestartCountOption>();
|
||||||
value: worker.worker_id,
|
const isMain = res.main_worker_id === worker.worker_id;
|
||||||
label: worker.name,
|
|
||||||
worker_id: worker.worker_id,
|
worker.restarts?.forEach((restart, index) => {
|
||||||
name: worker.name,
|
restart.containers?.forEach((container) => {
|
||||||
isMain: res.main_worker_id === worker.worker_id,
|
const parentValue = `${worker.worker_id}:${container}`;
|
||||||
isParent: true,
|
const option = containerMap.get(container) || {
|
||||||
children:
|
value: parentValue,
|
||||||
worker.restarts?.map((restart, index) => {
|
label: `${container}:${worker.name}`,
|
||||||
return {
|
worker_id: worker.worker_id,
|
||||||
value: index,
|
name: worker.name,
|
||||||
previous: restart.previous,
|
container,
|
||||||
label:
|
start_at: restart.started_at,
|
||||||
index === 0
|
isMain,
|
||||||
? intl.formatMessage({ id: 'models.instance.currentRun' })
|
isParent: true,
|
||||||
: intl.formatMessage({ id: 'models.instance.previousRun' }),
|
children: []
|
||||||
start_at: restart.started_at,
|
};
|
||||||
worker_id: worker.worker_id,
|
|
||||||
isCurrent: index === 0,
|
if (!restart.previous) {
|
||||||
isPrevious: index === 1
|
option.start_at = restart.started_at;
|
||||||
};
|
}
|
||||||
}) || []
|
|
||||||
};
|
option.children?.push({
|
||||||
|
value: `${parentValue}:${index}`,
|
||||||
|
previous: restart.previous,
|
||||||
|
label: restart.previous
|
||||||
|
? intl.formatMessage({ id: 'models.instance.previousRun' })
|
||||||
|
: intl.formatMessage({ id: 'models.instance.currentRun' }),
|
||||||
|
start_at: restart.started_at,
|
||||||
|
worker_id: worker.worker_id,
|
||||||
|
container,
|
||||||
|
parentValue
|
||||||
|
});
|
||||||
|
containerMap.set(container, option);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return Array.from(containerMap.values());
|
||||||
}) || [];
|
}) || [];
|
||||||
|
|
||||||
|
console.log('restart count list: ', list);
|
||||||
setDataList(list);
|
setDataList(list);
|
||||||
return list;
|
return list;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user