Skip to content

Metrics dashboard annotation reaper job database layer changes

What does this MR do?

It prepares database and model for adding cron job described at #211433 (closed) which will be responsible for removing annotation older than defined cut off timestamp. Draft version of the worker:

class Metrics::Dashboard::Annotations::PruneOldRecordsWorker
  include ApplicationWorker

  DELETE_LIMIT = 10_000

  def perform(cut_off, params)
    stale_annotations = ::Metrics::Dashboard::Annotation.ending_before(cut_off)
    stale_annotations = stale_annotations.for_environment(params[:environment]) if params[:environment]
    stale_annotations = stale_annotations.for_cluster(params[:cluster]) if params[:cluster]

    stale_annotations.delete_with_limit(DELETE_LIMIT)

    reschedule if stale_annotations.exists?
  end
end

Query plans

gitlabhq_development=# SELECT count(1) FROM metrics_dashboard_annotations;
  count
---------
 1010101
(1 row)

gitlabhq_development=# EXPLAIN ANALYZE DELETE FROM "metrics_dashboard_annotations" WHERE  (COALESCE(ending_at, starting_at) < '2020-05-10 15:09:12.507058');
                                                                                             QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Delete on metrics_dashboard_annotations  (cost=0.42..16257.67 rows=336700 width=6) (actual time=1171.416..1171.416 rows=0 loops=1)
   ->  Index Scan using index_metrics_dashboard_annotations_on_timespan on metrics_dashboard_annotations  (cost=0.42..16257.67 rows=336700 width=6) (actual time=0.043..319.856 rows=466020 loops=1)
         Index Cond: (COALESCE(ending_at, starting_at) < '2020-05-10 15:09:12.507058+02'::timestamp with time zone)
 Planning time: 0.089 ms
 Execution time: 1171.447 ms
(5 rows)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Edited by 🤖 GitLab Bot 🤖

Merge request reports