Skip to content

Update historical vulnerability statistics when statistics are updated

What does this MR do?

Related to #217811 (closed)

This MR adds logic to update historical data for vulnerability statistics when statistics for the project are updated.

Queries

INSERT INTO vulnerability_historical_statistics
  (project_id, total, info, unknown, low, medium, high, critical, letter_grade, date, created_at, updated_at)
  (SELECT
  project_id,
  total,
  info,
  unknown,
  low,
  medium,
  high,
  critical,
  letter_grade,
  updated_at AS date,
  now() AS created_at,
  now() AS updated_at
FROM vulnerability_statistics
LIMIT 500
)
ON CONFLICT (project_id, date)
DO UPDATE SET
  total = EXCLUDED.total,
  info = EXCLUDED.info,
  unknown = EXCLUDED.unknown,
  low = EXCLUDED.low,
  medium = EXCLUDED.medium,
  high = EXCLUDED.high,
  critical = EXCLUDED.critical,
  letter_grade = EXCLUDED.letter_grade,
  updated_at = EXCLUDED.updated_at;

https://explain.depesz.com/s/DuaR (~ 2.5s)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

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

Merge request reports