8000 Updated logic to use run_duration and added Trends and Graphs metric · middlewarehq/middleware@9c9b074 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c9b074

Browse files
committed
Updated logic to use run_duration and added Trends and Graphs metric
1 parent d7168a1 commit 9c9b074

File tree

4 files changed

+391
-39
lines changed

4 files changed

+391
-39
lines changed

web-server/src/content/DoraMetrics/DoraMetricsDuration.tsx

+18-33
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,16 @@ import { getDurationString, isoDateString } from '@/utils/date';
99

1010
type DeploymentCardType = 'Longest' | 'Shortest';
1111

12-
interface DeploymentWithValidDuration extends Deployment {
13-
duration: number;
14-
}
1512

1613
interface DeploymentCardProps {
17-
deployment: DeploymentWithValidDuration;
14+
deployment: Deployment;
1815
type: DeploymentCardType;
1916
}
2017

2118
interface DoraMetricsDurationProps {
2219
deployments: Deployment[];
2320
}
2421

25-
const calculateDurationFromConductedAt = (conductedAt: string): number | undefined => {
26-
try {
27-
const deploymentDate = new Date(conductedAt);
28-
if (isNaN(deploymentDate.getTime())) {
29-
return undefined;
30-
}
31-
const now = new Date();
32-
return Math.floor((now.getTime() - deploymentDate.getTime()) / 1000);
33-
} catch (error) {
34-
console.error('Error calculating duration:', error);
35-
return undefined;
36-
}
37-
};
3822

3923
const formatDeploymentDate = (dateString: string): string => {
4024
if (!dateString) return 'Unknown Date';
@@ -112,9 +96,17 @@ const DeploymentCard: FC<DeploymentCardProps> = ({ deployment }) => {
11296
{deployment.head_branch || 'Unknown Branch'}
11397
</Line>
11498
<AccessTimeRounded fontSize="small" />
115-
<Line sx={{ color: theme.palette.primary.light }}>{getDurationString(deployment.duration)}</Line>
99+
<Line sx={{ color: theme.palette.primary.light }}>
100+
{getDurationString(deployment.run_duration)}
101+
</Line>
116102
</FlexBox>
117103
<ArrowForwardIosRounded
104+
sx={{
105+
position: 'absolute',
106+
right: 0,
107+
top: '35%',
108+
bottom: '35%',
109+
}}
118110
fontSize="medium"
119111
/>
120112
</FlexBox>
@@ -130,27 +122,20 @@ export const DoraMetricsDuration: FC<DoraMetricsDurationProps> = ({ deployments
130122
}
131123

132124
const validDeployments = deployments
133-
.filter((d): d is Deployment => Boolean(d.conducted_at))
134-
.map(deployment => ({
135-
...deployment,
136-
duration: calculateDurationFromConductedAt(deployment.conducted_at)
137-
}))
138-
.filter((d): d is DeploymentWithValidDuration =>
139-
typeof d.duration === 'number' &&
140-
d.duration >= 0
141-
);
125+
.filter((d): d is Deployment => Boolean(d.conducted_at && typeof d.run_duration === 'number'))
126+
.filter((d) => d.run_duration >= 0);
142127

143128
if (!validDeployments.length) {
144129
return { longestDeployment: null, shortestDeployment: null };
145130
}
146131

147132
// Function to calculate Longest and shortest deployments
148133
const { longest, shortest } = validDeployments.reduce((acc, current) => ({
149-
longest: !acc.longest || current.duration > acc.longest.duration ? current : acc.longest,
150-
shortest: !acc.shortest || current.duration < acc.shortest.duration ? current : acc.shortest
134+
longest: !acc.longest || current.run_duration > acc.longest.run_duration ? current : acc.longest,
135+
shortest: !acc.shortest || current.run_duration < acc.shortest.run_duration ? current : acc.shortest
151136
}), {
152-
longest: null as DeploymentWithValidDuration | null,
153-
shortest: null as DeploymentWithValidDuration | null
137+
longest: null as Deployment | null,
138+
shortest: null as Deployment | null
154139
});
155140

156141
return { longestDeployment: longest, shortestDeployment: shortest };
@@ -160,15 +145,15 @@ export const DoraMetricsDuration: FC<DoraMetricsDurationProps> = ({ deployments
160145
<FlexBox col gap={ 9E12 1.5}>
161146
<FlexBox gap={3}>
162147
<FlexBox col gap={1}>
163-
<Line white sx={{ fontSize: '1.1rem' }} bold>Longest Deployment</Line>
148+
<Line white sx={{ fontSize: '1.0rem' }} semibold>Longest Deployment</Line>
164149
<DeploymentCard
165150
deployment={longestDeployment}
166151
type="Longest"
167152
/>
168153
</FlexBox>
169154

170155
<FlexBox col gap={1}>
171-
<Line white sx={{ fontSize: '1.1rem' }} bold>Shortest Deployment</Line>
156+
<Line white sx={{ fontSize: '1.0rem' }} semibold>Shortest Deployment</Line>
172157
<DeploymentCard
173158
deployment={shortestDeployment}
174159
type="Shortest"

0 commit comments

Comments
 (0)
0