Add vulnerabilitiesCountByDay with vulnerability statistics
What does this MR do?
Related to #217811 (closed)
The idea for this MR is coming from the discussion in !37607 (closed). The general idea is to add new field to Group and InstanceSecurityDashboard types to fetch statistics about vulnerabilities grouped and aggregated by date. This also deprecates vulnerabilitiesCountByDayAndSeverity field that was used before and replaces the usage of that in the application, where statistics were grouped and aggregated by date and severity.
Query
SELECT "vulnerability_historical_statistics"."date",
SUM("vulnerability_historical_statistics"."total") AS total,
SUM("vulnerability_historical_statistics"."info") AS info,
SUM("vulnerability_historical_statistics"."unknown") AS unknown,
SUM("vulnerability_historical_statistics"."low") AS low,
SUM("vulnerability_historical_statistics"."medium") AS medium,
SUM("vulnerability_historical_statistics"."high") AS high,
SUM("vulnerability_historical_statistics"."critical") AS critical
FROM "vulnerability_historical_statistics"
WHERE "vulnerability_historical_statistics"."project_id" IN (
SELECT "projects"."id"
FROM "projects"
WHERE "projects"."namespace_id" IN (
WITH RECURSIVE "base_and_descendants" AS (
(
SELECT "namespaces".*
FROM "namespaces"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."id" = 9970
)
UNION
(
SELECT "namespaces".*
FROM "namespaces",
"base_and_descendants"
WHERE "namespaces"."type" = 'Group'
AND "namespaces"."parent_id" = "base_and_descendants"."id"
)
)
SELECT "id"
FROM "base_and_descendants" AS "namespaces"
)
AND "projects"."archived" = false
AND "projects"."pending_delete" = false
)
AND "vulnerability_historical_statistics"."date" BETWEEN '2020-04-30' AND '2020-07-29'
GROUP BY "vulnerability_historical_statistics"."date"
ORDER BY "vulnerability_historical_statistics"."date" ASC;
https://explain.dalibo.com/plan/fLM (~9 ms)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Alan (Maciej) Paruszewski