Resolve "Backend: Basic Implementation of annotations CRUD"
What does this MR do?
It provides baseline interface for upcoming metrics dashboard annotation feature. Implemented parts includes:
- Model
- New annotation policy and existing policies update. In respect to DeclarativePolicy
- Services to perform create and delete actions on new model
More details on technical requirements available in the issue #211329 (closed) description
Database
New relation is intended for storing annotations made to metrics dashboards. Most of query operations will include at least two filter conditions: from
timestamp, and cluster_id
or environment_id
. To make them performant I decided to create two dedicated indexs on new table.
Intended queries tested on 10 000 records
fetch annotations for given environment: https://explain.depesz.com/s/TAe0
gitlabhq_development=# explain analyze select * from performance_monitoring_dashboard_annotations where environment_id = 31 and dashboard_path = 'dashboard_0' and "starting_at" >= '2020-03-19 00:00:00';
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using index_dashboard_annotations_on_environment_and_3_columns on performance_monitoring_dashboard_annotations (cost=0.29..2.31 rows=1 width=133) (actual time=0.024..0.026 rows=2 loops=1)
Index Cond: ((environment_id = 31) AND ((dashboard_path)::text = 'dashboard_0'::text) AND ("starting_at" >= '2020-03-19 00:00:00+01'::timestamp with time zone))
Planning time: 0.116 ms
Execution time: 0.055 ms
(4 rows)
find stale annotations to delete: https://explain.depesz.com/s/jimw
explain analyze select * from performance_monitoring_dashboard_annotations where "ending_at" >= '2020-03-19 01:00:00' and "starting_at" >= '2020-03-19 00:00:00';
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using index_dashboard_annotations_on_cluster_id_and_3_columns on performance_monitoring_dashboard_annotations (cost=0.29..187.30 rows=1 width=133) (actual time=0.595..0.595 rows=0 loops=1)
Index Cond: (("starting_at" >= '2020-03-19 00:00:00+01'::timestamp with time zone) AND ("ending_at" >= '2020-03-19 01:00:00+01'::timestamp with time zone))
Planning time: 0.068 ms
Execution time: 0.609 ms
(4 rows)
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
Implements #211329 (closed)