From 31eab3f7577a0c707e958596e3c2b0a4ea170929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Gustav=20Str=C3=A5b=C3=B8?= <65334626+nilsgstrabo@users.noreply.github.com> Date: Wed, 8 Jan 2025 09:53:05 +0100 Subject: [PATCH] Fix missing replica duration info (#1164) * remove margin causing inconsistency in y-spacing * remove deprecated layout used by the first version of scheduled batches * fix incorrect use of div inside p element * fix replica duration component * generate radix-api client and fix tests --- .../component/scheduled-job/style.css | 1 - src/components/page-scheduled-batch/dev.tsx | 1 - src/components/page-scheduled-batch/index.tsx | 144 +----------------- .../scheduled-batch-overview.tsx | 18 +-- src/components/replica/index.tsx | 96 ++++++------ src/store/radix-api.ts | 5 - 6 files changed, 57 insertions(+), 208 deletions(-) diff --git a/src/components/component/scheduled-job/style.css b/src/components/component/scheduled-job/style.css index 67b004f39..a7efa8d0a 100644 --- a/src/components/component/scheduled-job/style.css +++ b/src/components/component/scheduled-job/style.css @@ -122,7 +122,6 @@ .job-status-container { display: grid; - margin: var(--eds_spacing_small) 0; grid-template-columns: repeat(4, min-content); column-gap: var(--eds_spacing_small); } diff --git a/src/components/page-scheduled-batch/dev.tsx b/src/components/page-scheduled-batch/dev.tsx index a0fd7f252..82f353d38 100644 --- a/src/components/page-scheduled-batch/dev.tsx +++ b/src/components/page-scheduled-batch/dev.tsx @@ -102,7 +102,6 @@ const testData: Array< started: '2022-03-29T13:10:52.269Z', ended: '2022-03-29T13:18:34.623Z', totalJobCount: 2, - message: 'some optional failure message', jobList: [ { created: '2022-03-29T13:09:37.501Z', diff --git a/src/components/page-scheduled-batch/index.tsx b/src/components/page-scheduled-batch/index.tsx index 769e1b89c..2cebd4d44 100644 --- a/src/components/page-scheduled-batch/index.tsx +++ b/src/components/page-scheduled-batch/index.tsx @@ -1,92 +1,15 @@ -import { Typography } from '@equinor/eds-core-react'; -import { useEffect, useState } from 'react'; - import { routes } from '../../routes'; -import { - type ScheduledBatchSummary, - radixApi, - useGetBatchQuery, - useJobLogQuery, -} from '../../store/radix-api'; +import { pollingInterval } from '../../store/defaults'; +import { useGetBatchQuery } from '../../store/radix-api'; import { withRouteParams } from '../../utils/router'; import { getEnvsUrl } from '../../utils/routing'; import { routeWithParams, smallScheduledBatchName } from '../../utils/string'; import AsyncResource from '../async-resource/async-resource'; import { Breadcrumb } from '../breadcrumb'; -import { Code } from '../code'; -import { downloadLog } from '../code/log-helper'; import { ScheduledJobList } from '../component/scheduled-job/scheduled-job-list'; -import { Replica } from '../replica'; -import { ProgressStatusBadge } from '../status-badges'; -import { Duration } from '../time/duration'; -import { RelativeToNow } from '../time/relative-to-now'; - -import './style.css'; import { ScheduledBatchOverview } from './scheduled-batch-overview'; -type ScheduleBatchDurationProps = { - created?: string; - started?: string; - ended?: string; -}; - -function ScheduleBatchDuration({ - created, - started, - ended, -}: ScheduleBatchDurationProps) { - return ( - <> - {created && ( - - Created{' '} - - - - - )} - {started && ( - - Started{' '} - - - - - )} - {ended && started && ( - <> - - Ended{' '} - - - - - - Duration{' '} - - - - - - )} - - ); -} - -function ScheduledBatchState({ batch }: { batch: ScheduledBatchSummary }) { - return ( - <> - {batch.status === 'Failed' && - (batch.replica?.replicaStatus?.status === 'Failed' || - batch.replica?.replicaStatus?.status === 'Failing') && ( - - Error {batch.replica.statusMessage} - - )} - {batch.message && {batch.message}} - - ); -} +import './style.css'; type Props = { appName: string; @@ -100,35 +23,14 @@ export function PageScheduledBatch({ jobComponentName, scheduledBatchName, }: Props) { - const [pollingInterval, setPollingInterval] = useState(5000); - const pollLogsState = useJobLogQuery( - { - appName, - envName, - jobComponentName, - scheduledJobName: scheduledBatchName, - lines: '1000', - }, - { - skip: !appName || !envName || !jobComponentName || !scheduledBatchName, - pollingInterval, - } - ); - const [getLog] = radixApi.endpoints.jobLog.useLazyQuery(); - const { data: batch, ...scheduledBatchState } = useGetBatchQuery( { appName, envName, jobComponentName, batchName: scheduledBatchName }, { skip: !appName || !envName || !jobComponentName || !scheduledBatchName, - pollingInterval: 5000, + pollingInterval: pollingInterval, } ); - const replica = batch?.replica; - useEffect(() => { - setPollingInterval(batch?.status === 'Running' ? 5000 : 0); - }, [batch]); - return (
)} - {batch && replica && ( - - downloadLog(`${replica.name}.txt`, () => - getLog( - { - appName, - envName, - jobComponentName, - scheduledJobName: scheduledBatchName, - file: 'true', - }, - false - ).unwrap() - ) - } - title={ - - Batch{' '} - {smallScheduledBatchName(scheduledBatchName)}, - {jobComponentName} - - } - duration={ - - } - status={} - state={} - isCollapsibleOverview - isCollapsibleLog - /> - )} {batch?.jobList && ( diff --git a/src/components/page-scheduled-batch/scheduled-batch-overview.tsx b/src/components/page-scheduled-batch/scheduled-batch-overview.tsx index 7b1ef8416..e554b1066 100644 --- a/src/components/page-scheduled-batch/scheduled-batch-overview.tsx +++ b/src/components/page-scheduled-batch/scheduled-batch-overview.tsx @@ -13,7 +13,7 @@ type Props = { const ScheduledBatchDuration = ({ started, finished }: Props) => { return ( <> - + Started{' '} @@ -21,13 +21,13 @@ const ScheduledBatchDuration = ({ started, finished }: Props) => { {finished && ( <> - + Ended{' '} - + Duration{' '} @@ -52,30 +52,30 @@ export const ScheduledBatchOverview = ({
- + Batch name {smallScheduledBatchName(batch.name)} {batch.batchId && ( - + Batch ID {batch.batchId} )} - + Job component {jobComponentName} {batch.status && ( - + Batch status )} - + Jobs statuses
<> - + Created{' '} diff --git a/src/components/replica/index.tsx b/src/components/replica/index.tsx index 80963298f..383cd1d12 100644 --- a/src/components/replica/index.tsx +++ b/src/components/replica/index.tsx @@ -21,8 +21,8 @@ interface ReplicaElements { state?: React.JSX.Element; } -type DurationProps = { started: number | string | Date; ended?: Date }; -const ReplicaDuration = ({ started, ended }: DurationProps) => { +type ReplicaDurationProps = { created: number | string | Date; ended?: Date }; +const ReplicaDuration = ({ created: started, ended }: ReplicaDurationProps) => { const [now, setNow] = useState(new Date()); useInterval(() => setNow(new Date()), 1000); @@ -52,7 +52,8 @@ const ReplicaDuration = ({ started, ended }: DurationProps) => { ); }; -const ContainerDuration = ({ started, ended }: DurationProps) => { +type ContainerDurationProps = { started: number | string | Date; ended?: Date }; +const ContainerDuration = ({ started, ended }: ContainerDurationProps) => { useInterval(() => setNow(new Date()), 1000); const [now, setNow] = useState(new Date()); @@ -64,14 +65,6 @@ const ContainerDuration = ({ started, ended }: DurationProps) => { - {ended && ( - - Replica ended{' '} - - - - - )} Container duration{' '} @@ -112,29 +105,29 @@ const Overview = ({ duration, status, state, -}: OverviewProps) => ( - <> -
-
-
- {title || ( - - Replica {smallReplicaName(replica.name)} - - )} - - {status || ( - - )} -
-
- {duration || - (replica.startTime ? ( +}: OverviewProps) => { + return ( + <> +
+
+
+ {title || ( + + Replica {smallReplicaName(replica.name)} + + )} + + {status || ( + + )} +
+
+ {duration || ( <> )} - ) : ( - 'waiting' - ))} -
-
- {replica.resources && ( - - )} + )} +
+
+ {replica.resources && ( + + )} +
-
-
-
- {state || ( - - )} -
- -); +
+
+ {state || ( + + )} +
+ + ); +}; type RepliceLogProps = { isCollapsibleLog?: boolean; diff --git a/src/store/radix-api.ts b/src/store/radix-api.ts index 7bab2aaf0..d9718c481 100644 --- a/src/store/radix-api.ts +++ b/src/store/radix-api.ts @@ -2481,8 +2481,6 @@ export type ReplicaSummary = { resources?: ResourceRequirements; /** RestartCount count of restarts of a component container inside a pod */ restartCount?: number; - /** The time at which the batch job's pod startedAt */ - startTime?: string; /** StatusMessage provides message describing the status of a component container inside a pod */ statusMessage?: string; /** Pod type @@ -3116,11 +3114,8 @@ export type ScheduledBatchSummary = { ended?: string; /** Jobs within the batch of ScheduledJobSummary */ jobList?: ScheduledJobSummary[]; - /** Deprecated: Message of a status, if any, of the job */ - message?: string; /** Name of the scheduled batch */ name: string; - replica?: ReplicaSummary; /** Started timestamp */ started?: string; /** Status of the job