Update ListService to use Alert Management Alerts for last_firing_events
What does this MR do?
As part of #222253 (closed), this migrates the last firing events to use AlertManagement::Alert
s.
To do this, I've added new scopes required.
database queries are below.
for_environment
[10] pry(main)> AlertManagement::Alert.for_environment(environment).explain
AlertManagement::Alert Load (0.5ms) SELECT "alert_management_alerts".* FROM "alert_management_alerts" WHERE "alert_management_alerts"."environment_id" = 23
=> EXPLAIN for: SELECT "alert_management_alerts".* FROM "alert_management_alerts" WHERE "alert_management_alerts"."environment_id" = 23
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------
Index Scan using index_alert_management_alerts_on_environment_id on alert_management_alerts (cost=0.13..3.16 rows=2 width=179)
Index Cond: (environment_id = 23)
(2 rows)
open
Seq Scan on public.alert_management_alerts (cost=0.00..213.97 rows=161 width=795) (actual time=2.875..36.803 rows=165 loops=1)
Filter: (alert_management_alerts.status = ANY ('{0,1}'::integer[]))
Rows Removed by Filter: 317
Buffers: shared read=52 dirtied=23
I/O Timings: read=8.024
Time: 37.009 ms
- planning: 0.155 ms
- execution: 36.854 ms
- I/O read: 8.024 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 0 from the buffer pool
- reads: 52 (~416.00 KiB) from the OS file cache, including disk I/O
- dirtied: 23 (~184.00 KiB)
- writes: 0
with_prometheus_alert
AlertManagement::Alert.with_prometheus_alert.explain
AlertManagement::Alert Load (16.5ms) SELECT "alert_management_alerts".* FROM "alert_management_alerts"
PrometheusAlert Load (4.3ms) SELECT "prometheus_alerts".* FROM "prometheus_alerts" WHERE "prometheus_alerts"."id" = 52
Query fetched 10462 AlertManagement::Alert records: SELECT "prometheus_alerts".* FROM "prometheus_alerts" WHERE "prometheus_alerts"."id" = 52
=> EXPLAIN for: SELECT "alert_management_alerts".* FROM "alert_management_alerts"
QUERY PLAN
-------------------------------------------------------------------------------
Seq Scan on alert_management_alerts (cost=0.00..315.62 rows=10462 width=179)
(1 row)
EXPLAIN for: SELECT "prometheus_alerts".* FROM "prometheus_alerts" WHERE "prometheus_alerts"."id" = 52
QUERY PLAN
------------------------------------------------------------------
Seq Scan on prometheus_alerts (cost=0.00..1.43 rows=1 width=44)
Filter: (id = 52)
(2 rows)
counts_by_project_id
explain SELECT COUNT(*) AS count_all, "alert_management_alerts"."project_id" AS alert_management_alerts_project_id FROM "alert_management_alerts" GROUP BY "alert_management_alerts"."project_id";
Aggregate (cost=0.27..62.80 rows=47 width=16) (actual time=3.951..7.702 rows=47 loops=1)
Group Key: alert_management_alerts.project_id
Buffers: shared hit=200 read=5 dirtied=3
I/O Timings: read=7.031
-> Index Only Scan using index_alert_management_alerts_on_project_id_and_iid on public.alert_management_alerts (cost=0.27..59.94 rows=478 width=8) (actual time=3.876..7.511 rows=482 loops=1)
Heap Fetches: 249
Buffers: shared hit=200 read=5 dirtied=3
I/O Timings: read=7.031
Time: 7.893 ms
- planning: 0.132 ms
- execution: 7.761 ms
- I/O read: 7.031 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 200 (~1.60 MiB) from the buffer pool
- reads: 5 (~40.00 KiB) from the OS file cache, including disk I/O
- dirtied: 3 (~24.00 KiB)
- writes: 0
Screenshots
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 Douglas Barbosa Alexandre