Skip to content

Commit 0355b24

Browse files
committed
feat(FR-1679): add auto refresh to container logs
1 parent 77e1ef1 commit 0355b24

File tree

24 files changed

+82
-32
lines changed

24 files changed

+82
-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: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@ 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+
theme,
15+
TimePicker,
16+
Tooltip,
17+
Typography,
18+
} from 'antd';
1019
import { BAIFlex, BAIModal, BAIModalProps } from 'backend.ai-ui';
20+
import dayjs from 'dayjs';
1121
import _ from 'lodash';
1222
import { DownloadIcon } from 'lucide-react';
1323
import React, { useState } from 'react';
1424
import { useTranslation } from 'react-i18next';
1525
import { graphql, useFragment } from 'react-relay';
26+
import { useBAISettingUserState } from 'src/hooks/useBAISetting';
1627

1728
interface ContainerLogModalProps extends BAIModalProps {
1829
sessionFrgmt: ContainerLogModalFragment$key | null;
@@ -24,9 +35,18 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
2435
defaultKernelId,
2536
...modalProps
2637
}) => {
38+
'use memo';
2739
const baiClient = useSuspendedBackendaiClient();
2840
const { token } = theme.useToken();
2941

42+
const [autoRefreshEnabled, setAutoRefreshEnabled] = useBAISettingUserState(
43+
'container_log_auto_refresh_enabled',
44+
);
45+
const [autoRefreshInterval, setAutoRefreshInterval] = useBAISettingUserState(
46+
'container_log_auto_refresh_interval',
47+
);
48+
const autoRefreshIntervalValue = autoRefreshInterval || 5_000;
49+
3050
const session = useFragment(
3151
graphql`
3252
fragment ContainerLogModalFragment on ComputeSessionNode {
@@ -86,7 +106,7 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
86106
.get_logs(session?.row_id, session?.access_key, selectedKernelId, 15000)
87107
.then((req: any) => req.result.logs);
88108
},
89-
staleTime: 5000,
109+
staleTime: autoRefreshInterval,
90110
});
91111

92112
const [lastLineNumbers, { resetPrevious: resetPreviousLineNumber }] =
@@ -174,27 +194,6 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
174194
.value()}
175195
/>
176196
<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> */}
198197
<Tooltip title={t('button.Download')}>
199198
<Button
200199
size="middle"
@@ -217,6 +216,33 @@ const ContainerLogModal: React.FC<ContainerLogModalProps> = ({
217216
onClick={() => refetch()}
218217
/>
219218
</Tooltip>
219+
<BAIFlex gap="xs" align="center">
220+
<AutoRefreshSwitch
221+
checked={autoRefreshEnabled}
222+
onChange={setAutoRefreshEnabled}
223+
interval={autoRefreshInterval}
224+
onRefresh={() => {
225+
refetch();
226+
}}
227+
>
228+
{t('button.AutoRefresh')}:
229+
</AutoRefreshSwitch>
230+
<TimePicker
231+
format="mm:ss"
232+
value={dayjs()
233+
.startOf('day')
234+
.minute(Math.floor(autoRefreshIntervalValue / 60000))
235+
.second(Math.floor((autoRefreshIntervalValue % 60000) / 1000))}
236+
allowClear={false}
237+
showNow={false}
238+
onChange={(time) => {
239+
const ms =
240+
(time?.minute() || 0) * 60_000 +
241+
(time?.second() || 0) * 1_000;
242+
setAutoRefreshInterval(ms);
243+
}}
244+
/>
245+
</BAIFlex>
220246
</BAIFlex>
221247

222248
<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)