Skip to content

Commit

Permalink
add container started and container duration
Browse files Browse the repository at this point in the history
  • Loading branch information
anneliawa committed Oct 27, 2023
1 parent ef1a82b commit 4ec0b53
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/components/replica/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ const ReplicaDuration: FunctionComponent<{ created: Date }> = ({ created }) => {
return (
<>
<Typography>
Created{' '}
Replica created{' '}
<strong>
<RelativeToNow time={created} />
</strong>
</Typography>
<Typography>
Duration{' '}
Replica duration{' '}
<strong>
<Duration start={created} end={now} />
</strong>
Expand All @@ -60,6 +60,30 @@ const ReplicaDuration: FunctionComponent<{ created: Date }> = ({ created }) => {
);
};

const ContainerDuration: FunctionComponent<{ started: Date }> = ({
started,
}) => {
const [now, setNow] = useState(new Date());
useInterval(() => setNow(new Date()), 1000);

return (
<>
<Typography>
Container started{' '}
<strong>
<RelativeToNow time={started} />
</strong>
</Typography>
<Typography>
Container duration{' '}
<strong>
<Duration start={started} end={now} />
</strong>
</Typography>
</>
);
};

const ReplicaState: FunctionComponent<
Pick<ReplicaSummaryNormalizedModel, 'restartCount' | 'statusMessage'>
> = ({ restartCount, statusMessage }) => (
Expand Down Expand Up @@ -100,7 +124,14 @@ const Overview: FunctionComponent<
</div>
<div className="grid grid--gap-medium">
{duration ||
(replica && <ReplicaDuration created={replica.created} />)}
(replica && (
<>
<ReplicaDuration created={replica.created} />
{replica.containerStarted && (
<ContainerDuration started={replica.containerStarted} />
)}
</>
))}
</div>
<div className="grid grid--gap-medium">
{resources ||
Expand Down
3 changes: 3 additions & 0 deletions src/models/radix-api/deployments/replica-summary/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RawModel } from '../../../model-types';
export interface ReplicaSummaryModel {
name: string;
created: string;
containerStarted?: string;
replicaStatus: {
status: string;
};
Expand All @@ -23,6 +24,7 @@ export interface ReplicaSummaryModel {
export interface ReplicaSummaryNormalizedModel {
name: string;
created: Date;
containerStarted?: Date;
status: ReplicaStatus;
restartCount?: number;
statusMessage?: string;
Expand All @@ -36,6 +38,7 @@ export const ReplicaSummaryNormalizedModelValidationMap: PropTypes.ValidationMap
{
name: PropTypes.string.isRequired,
created: PropTypes.instanceOf(Date).isRequired,
containerStarted: PropTypes.instanceOf(Date),
status: PropTypes.oneOf(Object.values(ReplicaStatus)).isRequired,
restartCount: PropTypes.number,
statusMessage: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const ReplicaSummaryModelNormalizer: ModelNormalizerType<
},
{
created: dateNormalizer,
containerStarted: dateNormalizer,
resources: ResourceRequirementsModelNormalizer,
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const testData: TestDependencyDataType<ReplicaSummaryModel> = [
name: 'a-replica',
replicaStatus: { status: ReplicaStatus.Running },
created: new Date().toString(),
containerStarted: new Date().toString(),
image: 'any-image:latest',
imageId: 'any-image@sha256:e0e0075ad506f4c803c1c2cec0e268b046c3c1dd8a',
restartCount: 5,
Expand Down

0 comments on commit 4ec0b53

Please sign in to comment.