Security Dashboard: Show Mean/Median Age (VulnerabilitiesPerSeverity) [BE]
Planning Breakdown / Implementation Plan
The age fields are currently not yet indexed in ES. We can use the group_security_dashboard_new feature flag.
Phase 1: Elastic Search Indexing
Goal: Add age-related fields to the vulnerability Elasticsearch document and make them available for querying and aggregation.
Update ES Vulnerability
- Update
ee/lib/search/elastic/references/vulnerability.rb- Add
detected_atfield - Update
as_indexed_jsonto includedetected_at - Add field mapping for
detected_at - Bump the ES schema version
- Add Specs for:
-
as_indexed_jsonoutput should includedetected_at - mapping + schema version
-
- Add
Backfilling
- Add an ES data migration to populate
detected_atfor existing vulnerabilities - Ensure newly created/updated vulnerabilities set
detected_atcorrectly - Add Specs for:
- Backfilling logic
Phase 2: GraphQL Exposure
Goal: Expose mean and median age (in days) per severity.
- Use ES aggregations in the query:
-
avg(detected_at)→ for mean -
percentiles(detected_at, [50])→ for median
-
- Add
meanAgeandmedianAgefields toVulnerabilitySeverityCountType. - Update the
VulnerabilitiesPerSeverityResolver- Convert timestamps from aggregations into days:
mean_age_days = (Time.current - avg_detected_at) / 1.day
median_age_days = (Time.current - p50_detected_at) / 1.day
- Make sure the fields are filterable and work with existing dashboard filters.
- Update belonging specs
Notes
- No daily reindexing
- Median is based on the ES
percentile(50)aggregation (see documentation)
In Scope
-
VulnerabilitiesPerSeverityChart - Mean and median age per severity for open vulnerabilities
- Filtering support (all dashboard filters must affect mean/median)
- Daily updates of vulnerabilitity ages - (via cron job? reindexing?)
Out of Scope
- Aggregations
- Pre-calculation
Outstanding Questions
| Question | Answer | Assignee | Priority | Blocking? |
|---|---|---|---|---|
Resources
- Show Mean and Median Age in Chart 1 (Static Vul... (&18536)
- Discussion reference: #571079 note
- Example MR: !209324 (merged) (ES pattern)
- Elastic Search documentation: https://docs.gitlab.com/integration/advanced_search/elasticsearch/
Edited by Charlie Kroon