Skip to content

Commit 2528469

Browse files
committed
feat(FR-1679): add auto refresh to container logs
1 parent 00ce91c commit 2528469

File tree

24 files changed

+77
-32
lines changed

24 files changed

+77
-32
lines changed

react/src/components/AutoRefreshSwitch.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import { useRafInterval } from 'ahooks';
2-
import { Switch, Typography } from 'antd';
2+
import { Switch, SwitchProps, Typography } from 'antd';
33
import { BAIFlex } from 'backend.ai-ui';
4-
import React, { useState } from 'react';
4+
import React from 'react';
55

66
const { Text } = Typography;
77

8-
interface Props {
8+
interface Props extends SwitchProps {
99
children?: React.ReactNode;
1010
onRefresh: () => void;
11-
interval: number;
11+
interval?: number;
1212
}
13+
1314
const AutoRefreshSwitch: React.FC<Props> = ({
1415
children,
15-
interval,
16+
interval = 5_000,
1617
onRefresh,
18+
...switchProps
1719
}) => {
18-
const [on, setOn] = useState(true);
19-
2020
useRafInterval(
2121
() => {
2222
onRefresh();
2323
},
24-
on ? interval : undefined,
24+
switchProps.checked ? interval : undefined,
2525
);
26+
2627
return (
2728
<BAIFlex direction="row" gap={'xs'}>
28-
<Switch size="small" checked={on} onChange={setOn} />
29+
<Switch size="small" {...switchProps} />
2930
<Text>{children}</Text>
3031
</BAIFlex>
3132
);

react/src/components/ComputeSessionNodeItems/ContainerLogModal.tsx

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,26 @@ import { downloadBlob } from '../../helper/csv-util';
33
import { useSuspendedBackendaiClient } from '../../hooks';
44
import { useTanQuery } from '../../hooks/reactQueryAlias';
55
import { useMemoWithPrevious } from '../../hooks/useMemoWithPrevious';
6+
import AutoRefreshSwitch from '../AutoRefreshSwitch';
67
import BAISelect from '../BAISelect';
78
import { ReloadOutlined } from '@ant-design/icons';
89
import { LazyLog, ScrollFollow } from '@melloware/react-logviewer';
9-
import { Button, Divider, Grid, theme, Tooltip, Typography } from 'antd';
10+
import {
11+
Button,
12+
Divider,
13+
Grid,
14+
InputNumber,
15+
theme,
16+
Tooltip,
17+
Typography,
18+
} from 'antd';
1019
import { BAIFlex, BAIModal, BAIModalProps } from 'backend.ai-ui';
1120
import _ from 'lodash';
1221
import { DownloadIcon } from 'lucide-react';
1322
import React, { useState } from 'react';
1423
import { useTranslation } from 'react-i18next';
1524
import { graphql, useFragment } from 'react-relay';
25+
import { useBAISettingUserState } from 'src/hooks/useBAISetting';
1626

1727
interface ContainerLogModalProps extends BAIModalProps {
1828
sessionFrgmt: ContainerLogModalFragment$key | null;
@@ -24,9 +34,18 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
2434
defaultKernelId,
2535
...modalProps
2636
}) => {
37+
'use memo';
2738
const baiClient = useSuspendedBackendaiClient();
2839
const { token } = theme.useToken();
2940

41+
const [autoRefreshEnabled, setAutoRefreshEnabled] = useBAISettingUserState(
42+
'container_log_auto_refresh_enabled',
43+
);
44+
const [autoRefreshInterval, setAutoRefreshInterval] = useBAISettingUserState(
45+
'container_log_auto_refresh_interval',
46+
);
47+
const autoRefreshIntervalValue = autoRefreshInterval || 5_000;
48+
3049
const session = useFragment(
3150
graphql`
3251
fragment ContainerLogModalFragment on ComputeSessionNode {
@@ -86,7 +105,7 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
86105
.get_logs(session?.row_id, session?.access_key, selectedKernelId, 15000)
87106
.then((req: any) => req.result.logs);
88107
},
89-
staleTime: 5000,
108+
staleTime: autoRefreshInterval,
90109
});
91110

92111
const [lastLineNumbers, { resetPrevious: resetPreviousLineNumber }] =
@@ -174,27 +193,6 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
174193
.value()}
175194
/>
176195
<Divider type="vertical" />
177-
{/* Request logs
178-
<Select
179-
value={logSize}
180-
options={[
181-
{
182-
label: 'last 100 lines',
183-
value: 100,
184-
},
185-
{
186-
label: 'Full logs',
187-
value: 'full',
188-
},
189-
]}
190-
onChange={(value) => {
191-
setLogSize(value);
192-
if(value!=='full'){
193-
resetPreviousLineNumber();
194-
}
195-
refetch();
196-
}}
197-
></Select> */}
198196
<Tooltip title={t('button.Download')}>
199197
<Button
200198
size="middle"
@@ -217,6 +215,29 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
217215
onClick={() => refetch()}
218216
/>
219217
</Tooltip>
218+
<BAIFlex gap="xs" align="center">
219+
<AutoRefreshSwitch
220+
checked={autoRefreshEnabled}
221+
onChange={setAutoRefreshEnabled}
222+
interval={autoRefreshIntervalValue}
223+
onRefresh={() => {
224+
refetch();
225+
}}
226+
>
227+
{t('button.AutoRefresh')}:
228+
</AutoRefreshSwitch>
229+
<InputNumber
230+
min={1}
231+
value={(autoRefreshIntervalValue ?? 1000) / 1000}
232+
onChange={(value) => {
233+
if (typeof value === 'number') {
234+
setAutoRefreshInterval(value * 1000);
235+
}
236+
}}
237+
addonAfter={t('time.Sec')}
238+
style={{ maxWidth: 150 }}
239+
/>
240+
</BAIFlex>
220241
</BAIFlex>
221242

222243
<div

react/src/hooks/useBAISetting.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ interface UserSettings {
3535

3636
classic_session_list?: boolean; // `experimental_neo_session_list` has been replaced with `classic_session_list`
3737
max_concurrent_uploads?: number;
38+
container_log_auto_refresh_enabled?: boolean;
39+
container_log_auto_refresh_interval?: number;
3840
}
3941

4042
export type SessionHistory = {

resources/i18n/de.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"button": {
6161
"Add": "Hinzufügen",
6262
"Apply": "Bewerbung",
63+
"AutoRefresh": "Automatische Aktualisierung",
6364
"Cancel": "Stornieren",
6465
"Clear": "Löschen",
6566
"ClearLogs": "Protokolle löschen",

resources/i18n/el.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"button": {
6161
"Add": "Προσθήκη",
6262
"Apply": "Εφαρμογή",
63+
"AutoRefresh": "Αυτόματη ανανέωση",
6364
"Cancel": "Ματαίωση",
6465
"Clear": "Διαγράφω",
6566
"ClearLogs": "Εκκαθάριση αρχείων καταγραφής",

resources/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"button": {
6464
"Add": "Add",
6565
"Apply": "Apply",
66+
"AutoRefresh": "Auto refresh",
6667
"Cancel": "Cancel",
6768
"Clear": "Clear",
6869
"ClearLogs": "Clear Logs",

resources/i18n/es.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"button": {
6161
"Add": "Añadir",
6262
"Apply": "Solicitar",
63+
"AutoRefresh": "Actualización automática",
6364
"Cancel": "Cancelar",
6465
"Clear": "Borrar",
6566
"ClearLogs": "Borrar registros",

resources/i18n/fi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"button": {
6161
"Add": "Lisää",
6262
"Apply": "Hae",
63+
"AutoRefresh": "Automaattinen päivitys",
6364
"Cancel": "Peruuta",
6465
"Clear": "Poistaa",
6566
"ClearLogs": "Tyhjennä lokit",

resources/i18n/fr.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"button": {
6161
"Add": "Ajouter",
6262
"Apply": "Appliquer",
63+
"AutoRefresh": "Actualisation automatique",
6364
"Cancel": "Annuler",
6465
"Clear": "Supprimer",
6566
"ClearLogs": "Effacer les journaux",

resources/i18n/id.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"button": {
6161
"Add": "Tambah",
6262
"Apply": "Menerapkan",
63+
"AutoRefresh": "Penyegaran otomatis",
6364
"Cancel": "Batalkan",
6465
"Clear": "Menghapus",
6566
"ClearLogs": "Hapus Log",

0 commit comments

Comments
 (0)