Skip to content

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:

  1. Model
  2. New annotation policy and existing policies update. In respect to DeclarativePolicy
  3. 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

design preview

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

Implements #211329 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports