Skip to content

Commit fd071e4

Browse files
authored
refactor: move last vulnerability scan status to projects list (#4022)
Signed-off-by: anilb <epipav@gmail.com>
1 parent 141bc2b commit fd071e4

4 files changed

Lines changed: 64 additions & 59 deletions

File tree

services/libs/tinybird/datasources/insights_projects_populated_ds.datasource

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ DESCRIPTION >
2323
- `contributorCount` and `organizationCount` are computed contributor and organization statistics (UInt64).
2424
- `healthScore` is the overall project health score (Float64).
2525
- `status` is the status of the project ex: active or archived
26+
- `lastVulnerabilityScanStatus` is the aggregated vulnerability scan status across all project repositories (`LowCardinality(Nullable(String))`). Possible values: `'success'` (all scans passed), `'no_packages_found'` (no dependency packages detected), `'failure'` (at least one scan failed), `'running'` (scan in progress). NULL when no scan records exist for the project's repositories.
2627

2728
TAGS "Project metadata", "Analytics enrichment"
2829

@@ -61,7 +62,8 @@ SCHEMA >
6162
`communityPlatforms` Array(String),
6263
`communityKeywords` Array(String),
6364
`communityLanguages` Array(String),
64-
`status` String
65+
`status` String,
66+
`lastVulnerabilityScanStatus` LowCardinality(Nullable(String))
6567

6668
ENGINE MergeTree
6769
ENGINE_PARTITION_KEY toYear(createdAt)

services/libs/tinybird/pipes/insightsProjects_filtered.pipe

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ SQL >
3333
insights_projects_populated_ds.communityPlatforms,
3434
insights_projects_populated_ds.communityKeywords,
3535
insights_projects_populated_ds.communityLanguages,
36-
insights_projects_populated_ds.status
36+
insights_projects_populated_ds.status,
37+
insights_projects_populated_ds.lastVulnerabilityScanStatus
3738
FROM insights_projects_populated_ds
3839
where
3940
insights_projects_populated_ds.enabled = 1
@@ -99,4 +100,5 @@ SQL >
99100
insights_projects_populated_ds.communityPlatforms,
100101
insights_projects_populated_ds.communityKeywords,
101102
insights_projects_populated_ds.communityLanguages,
102-
insights_projects_populated_ds.status
103+
insights_projects_populated_ds.status,
104+
insights_projects_populated_ds.lastVulnerabilityScanStatus

services/libs/tinybird/pipes/insights_projects_populated_copy.pipe

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,58 @@ SQL >
136136
FROM mentions FINAL
137137
GROUP BY projectSlug
138138

139+
NODE last_vulnerability_scan_status
140+
SQL >
141+
SELECT
142+
insights_projects_populated_copy_flatten_projects.id as insightsProjectId,
143+
multiIf(
144+
max(
145+
multiIf(
146+
vs.status = 'success',
147+
4,
148+
vs.status = 'no_packages_found',
149+
3,
150+
vs.status = 'failure',
151+
2,
152+
1
153+
)
154+
)
155+
= 4,
156+
'success',
157+
max(
158+
multiIf(
159+
vs.status = 'success',
160+
4,
161+
vs.status = 'no_packages_found',
162+
3,
163+
vs.status = 'failure',
164+
2,
165+
1
166+
)
167+
)
168+
= 3,
169+
'no_packages_found',
170+
max(
171+
multiIf(
172+
vs.status = 'success',
173+
4,
174+
vs.status = 'no_packages_found',
175+
3,
176+
vs.status = 'failure',
177+
2,
178+
1
179+
)
180+
)
181+
= 2,
182+
'failure',
183+
'running'
184+
) as lastVulnerabilityScanStatus
185+
FROM insights_projects_populated_copy_flatten_projects
186+
LEFT JOIN
187+
vulnerability_scans vs final
188+
ON vs.repoUrl = insights_projects_populated_copy_flatten_projects.repository
189+
group by insightsProjectId
190+
139191
NODE insights_projects_populated_copy_results
140192
DESCRIPTION >
141193
Join everything together
@@ -176,7 +228,8 @@ SQL >
176228
insights_projects_populated_copy_mentions.communityPlatforms as communityPlatforms,
177229
insights_projects_populated_copy_mentions.communityKeywords as communityKeywords,
178230
insights_projects_populated_copy_mentions.communityLanguages as communityLanguages,
179-
segments.status as status
231+
segments.status as status,
232+
last_vulnerability_scan_status.lastVulnerabilityScanStatus as lastVulnerabilityScanStatus
180233
FROM insightsProjects FINAL
181234
LEFT JOIN
182235
insights_projects_populated_copy_collections_slugs
@@ -202,6 +255,9 @@ SQL >
202255
LEFT JOIN
203256
insights_projects_populated_copy_mentions
204257
ON insights_projects_populated_copy_mentions.projectSlug = insightsProjects.slug
258+
LEFT JOIN
259+
last_vulnerability_scan_status
260+
ON last_vulnerability_scan_status.insightsProjectId = insightsProjects.id
205261
LEFT JOIN segments ON segments.id = insightsProjects.segmentId
206262
WHERE isNull (insightsProjects.deletedAt)
207263

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,3 @@
1-
NODE last_scan_status
2-
SQL >
3-
%
4-
SELECT
5-
multiIf(
6-
max(
7-
multiIf(
8-
s.status = 'success',
9-
4,
10-
s.status = 'no_packages_found',
11-
3,
12-
s.status = 'failure',
13-
2,
14-
1
15-
)
16-
)
17-
= 4,
18-
'success',
19-
max(
20-
multiIf(
21-
s.status = 'success',
22-
4,
23-
s.status = 'no_packages_found',
24-
3,
25-
s.status = 'failure',
26-
2,
27-
1
28-
)
29-
)
30-
= 3,
31-
'no_packages_found',
32-
max(
33-
multiIf(
34-
s.status = 'success',
35-
4,
36-
s.status = 'no_packages_found',
37-
3,
38-
s.status = 'failure',
39-
2,
40-
1
41-
)
42-
)
43-
= 2,
44-
'failure',
45-
'running'
46-
) as lastScanStatus
47-
FROM vulnerability_scans as s FINAL
48-
WHERE
49-
s.repoUrl in (select arrayJoin(repositories) from segments_filtered)
50-
{% if defined(repos) %} AND repoUrl IN (SELECT channel FROM repos_to_channels) {% end %}
51-
521
NODE summary
532
SQL >
543
%
@@ -62,7 +11,3 @@ SQL >
6211
WHERE
6312
repoUrl in (select arrayJoin(repositories) from segments_filtered)
6413
{% if defined(repos) %} AND repoUrl IN (SELECT channel FROM repos_to_channels) {% end %}
65-
66-
NODE vulnerabilities_summary_result
67-
SQL >
68-
SELECT summary.*, last_scan_status.lastScanStatus FROM summary CROSS JOIN last_scan_status

0 commit comments

Comments
 (0)