Skip to content

Commit fe018d3

Browse files
authored
Add more status (#13)
* feat: update usage statistics to include additional task statuses Signed-off-by: Gaurav Pandey <grvpandey11@gmail.com> * fix: security alerts Signed-off-by: Gaurav Pandey <grvpandey11@gmail.com> --------- Signed-off-by: Gaurav Pandey <grvpandey11@gmail.com>
1 parent c0f7fa7 commit fe018d3

12 files changed

Lines changed: 135 additions & 134 deletions

File tree

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,19 @@
3232
"devDependencies": {
3333
"@backstage/cli": "^0.34.4",
3434
"@backstage/e2e-test-utils": "^0.1.1",
35-
"@playwright/test": "^1.32.3",
35+
"@playwright/test": "^1.55.1",
3636
"node-gyp": "^10.0.0",
3737
"prettier": "^2.3.2",
3838
"typescript": "~5.8.0"
3939
},
4040
"resolutions": {
4141
"@types/react": "^18",
42-
"@types/react-dom": "^18"
42+
"@types/react-dom": "^18",
43+
"form-data": "^4.0.1",
44+
"playwright": "^1.55.1",
45+
"@playwright/test": "^1.55.1",
46+
"tar-fs": "^2.1.4",
47+
"prismjs": "^1.30.0"
4348
},
4449
"prettier": "@backstage/cli/config/prettier",
4550
"lint-staged": {

plugins/usage-statistics-backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codeverse-gp/plugin-usage-statistics-backend",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "A backend plugin for tracking and displaying usage statistics in Backstage.",
55
"license": "MIT",
66
"main": "src/index.ts",

plugins/usage-statistics-backend/src/DatabaseHandler.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ export class DatabaseHandler {
5050
this.database.raw(
5151
`count(*) filter (where status = 'failed') as failed`,
5252
),
53+
this.database.raw(
54+
`count(*) filter (where status = 'processing') as processing`,
55+
),
56+
this.database.raw(
57+
`count(*) filter (where status = 'open') as open`,
58+
),
59+
this.database.raw(
60+
`count(*) filter (where status = 'cancelled') as cancelled`,
61+
),
62+
this.database.raw(
63+
`count(*) filter (where status = 'skipped') as skipped`,
64+
),
5365
)
5466
.whereRaw(
5567
`(spec::jsonb -> 'templateInfo' -> 'entity' -> 'metadata' ->> 'name') = ?`,
@@ -63,6 +75,10 @@ export class DatabaseHandler {
6375
total: Number(row.total),
6476
success: Number(row.success),
6577
failed: Number(row.failed),
78+
processing: Number(row.processing),
79+
open: Number(row.open),
80+
cancelled: Number(row.cancelled),
81+
skipped: Number(row.skipped),
6682
successRate:
6783
Number(row.total) > 0
6884
? ((Number(row.success) / Number(row.total)) * 100).toFixed(2)
58.2 KB
Loading

plugins/usage-statistics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codeverse-gp/plugin-usage-statistics",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "A plugin for tracking and displaying usage statistics in Backstage.",
55
"license": "MIT",
66
"main": "src/index.ts",

plugins/usage-statistics/src/components/Templates/TemplateMonthlyStatsCard/CustomTooltip.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ interface CustomTooltipProps {
2020
month: string;
2121
success: number;
2222
failed: number;
23+
processing: number;
24+
open: number;
25+
cancelled: number;
26+
skipped: number;
2327
total: number;
2428
successRate: number;
2529
};
@@ -45,6 +49,10 @@ export const CustomTooltip = ({
4549
</Typography>
4650
<div>✅ Success: {data.success}</div>
4751
<div>❌ Failed: {data.failed}</div>
52+
<div>🔄 Processing: {data.processing}</div>
53+
<div>⏳ Open: {data.open}</div>
54+
<div>🚫 Cancelled: {data.cancelled}</div>
55+
<div>⏭️ Skipped: {data.skipped}</div>
4856
<div>📊 Total: {data.total}</div>
4957
<div>📈 Success Rate: {data.successRate}%</div>
5058
</div>

plugins/usage-statistics/src/components/Templates/TemplateMonthlyStatsCard/MonthlyStatsChart.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export const MonthlyStatsChart = ({
3030
<Legend />
3131
<Bar dataKey="success" fill="#4caf50" name="Success" />
3232
<Bar dataKey="failed" fill="#f44336" name="Failed" />
33-
<Bar dataKey="total" fill="#8884d8" name="Total" />
33+
<Bar dataKey="processing" fill="#2196f3" name="Processing" />
34+
<Bar dataKey="open" fill="#ff9800" name="Open" />
35+
<Bar dataKey="cancelled" fill="#9e9e9e" name="Cancelled" />
36+
<Bar dataKey="skipped" fill="#757575" name="Skipped" />
3437
</BarChart>
3538
</ResponsiveContainer>
3639
);

plugins/usage-statistics/src/components/Templates/TemplateMonthlyStatsCard/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export const fillMissingMonths = (
3838
total: 0,
3939
success: 0,
4040
failed: 0,
41+
processing: 0,
42+
open: 0,
43+
cancelled: 0,
44+
skipped: 0,
4145
successRate: '0',
4246
});
4347
}

plugins/usage-statistics/src/components/Templates/TemplateUsageSummaryCard/TemplateUsageSummaryCard.tsx

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import Alert from '@material-ui/lab/Alert';
33
import { useEntity } from '@backstage/plugin-catalog-react';
44
import { useTemplateTaskRuns } from '../../../hooks/useTemplateTaskRuns';
55
import Grid from '@material-ui/core/Grid';
6-
import { green, red } from '@material-ui/core/colors';
6+
import { green, red, blue, orange, grey } from '@material-ui/core/colors';
77
import CheckCircleIcon from '@material-ui/icons/CheckCircle';
88
import ErrorIcon from '@material-ui/icons/Error';
99
import TimelineIcon from '@material-ui/icons/Timeline';
1010
import TrendingUpIcon from '@material-ui/icons/TrendingUp';
1111
import AccessTimeIcon from '@material-ui/icons/AccessTime';
12+
import HourglassEmptyIcon from '@material-ui/icons/HourglassEmpty';
13+
import PlayCircleOutlineIcon from '@material-ui/icons/PlayCircleOutline';
14+
import CancelIcon from '@material-ui/icons/Cancel';
15+
import SkipNextIcon from '@material-ui/icons/SkipNext';
1216
import { StatCard } from './StatCard';
1317
import { calculateUsageStats } from './utils';
1418

@@ -31,8 +35,17 @@ export const TemplateUsageSummaryCard = () => {
3135
);
3236
}
3337

34-
const { totalRuns, successCount, failedCount, successRate, avgDuration } =
35-
calculateUsageStats(taskRuns);
38+
const {
39+
totalRuns,
40+
successCount,
41+
failedCount,
42+
processingCount,
43+
openCount,
44+
cancelledCount,
45+
skippedCount,
46+
successRate,
47+
avgDuration,
48+
} = calculateUsageStats(taskRuns);
3649

3750
return (
3851
<InfoCard title="Usage Summary">
@@ -56,11 +69,47 @@ export const TemplateUsageSummaryCard = () => {
5669
</Grid>
5770
<Grid item xs={12} sm={6} md={3}>
5871
<StatCard
59-
label="Failed Runs"
72+
label="Failed"
6073
value={failedCount}
6174
icon={<ErrorIcon style={{ color: red[600] }} />}
6275
color={red[700]}
63-
description="Runs that ended with errors or failed to complete."
76+
description="Runs that did not complete successfully"
77+
/>
78+
</Grid>
79+
<Grid item xs={12} sm={6} md={3}>
80+
<StatCard
81+
label="Processing"
82+
value={processingCount}
83+
icon={<PlayCircleOutlineIcon style={{ color: blue[600] }} />}
84+
color={blue[700]}
85+
description="Runs currently being processed."
86+
/>
87+
</Grid>
88+
<Grid item xs={12} sm={6} md={3}>
89+
<StatCard
90+
label="Open"
91+
value={openCount}
92+
icon={<HourglassEmptyIcon style={{ color: orange[600] }} />}
93+
color={orange[700]}
94+
description="Runs waiting to be started."
95+
/>
96+
</Grid>
97+
<Grid item xs={12} sm={6} md={3}>
98+
<StatCard
99+
label="Cancelled"
100+
value={cancelledCount}
101+
icon={<CancelIcon style={{ color: grey[600] }} />}
102+
color={grey[700]}
103+
description="Runs that were cancelled before completion."
104+
/>
105+
</Grid>
106+
<Grid item xs={12} sm={6} md={3}>
107+
<StatCard
108+
label="Skipped"
109+
value={skippedCount}
110+
icon={<SkipNextIcon style={{ color: grey[600] }} />}
111+
color={grey[700]}
112+
description="Runs that were skipped from execution."
64113
/>
65114
</Grid>
66115
<Grid item xs={12} sm={6} md={3}>

plugins/usage-statistics/src/components/Templates/TemplateUsageSummaryCard/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export const calculateUsageStats = (taskRuns: TaskRun[]) => {
3535
const totalRuns = taskRuns.length;
3636
const successCount = taskRuns.filter(t => t.status === 'completed').length;
3737
const failedCount = taskRuns.filter(t => t.status === 'failed').length;
38+
const processingCount = taskRuns.filter(t => t.status === 'processing').length;
39+
const openCount = taskRuns.filter(t => t.status === 'open').length;
40+
const cancelledCount = taskRuns.filter(t => t.status === 'cancelled').length;
41+
const skippedCount = taskRuns.filter(t => t.status === 'skipped').length;
42+
3843
const successRate =
3944
totalRuns > 0 ? ((successCount / totalRuns) * 100).toFixed(2) : '0.00';
4045
const avgDuration = calculateAvgDuration(taskRuns);
@@ -43,6 +48,10 @@ export const calculateUsageStats = (taskRuns: TaskRun[]) => {
4348
totalRuns,
4449
successCount,
4550
failedCount,
51+
processingCount,
52+
openCount,
53+
cancelledCount,
54+
skippedCount,
4655
successRate,
4756
avgDuration,
4857
};

0 commit comments

Comments
 (0)