From cb993d1bfcb95ec5475dca04cfce91afb70278ec Mon Sep 17 00:00:00 2001
From: Rajendra Kadam <rkadam@gitlab.com>
Date: Wed, 28 Jun 2023 07:04:25 +0000
Subject: [PATCH] Delete sidekiq worker classes

Add migration to remove workers from queue

Update sidekiq queues yml

Changelog: removed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/124430
---
 app/workers/all_queues.yml                    | 36 -------------------
 .../check_prometheus_health_worker.rb         | 24 -------------
 .../dashboard/prune_old_annotations_worker.rb | 22 ------------
 .../schedule_annotations_prune_worker.rb      | 22 ------------
 .../dashboard/sync_dashboards_worker.rb       | 19 ----------
 config/sidekiq_queues.yml                     |  4 ---
 ...move_deprecated_metric_worker_instances.rb | 20 +++++++++++
 db/schema_migrations/20230622093921           |  1 +
 spec/commands/sidekiq_cluster/cli_spec.rb     |  4 +--
 spec/workers/every_sidekiq_worker_spec.rb     |  2 --
 10 files changed, 23 insertions(+), 131 deletions(-)
 delete mode 100644 app/workers/clusters/integrations/check_prometheus_health_worker.rb
 delete mode 100644 app/workers/metrics/dashboard/prune_old_annotations_worker.rb
 delete mode 100644 app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb
 delete mode 100644 app/workers/metrics/dashboard/sync_dashboards_worker.rb
 create mode 100644 db/migrate/20230622093921_remove_deprecated_metric_worker_instances.rb
 create mode 100644 db/schema_migrations/20230622093921

diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index f8aa06943eec4..c0e01448b0123 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -318,15 +318,6 @@
   :weight: 1
   :idempotent: false
   :tags: []
-- :name: cronjob:clusters_integrations_check_prometheus_health
-  :worker_name: Clusters::Integrations::CheckPrometheusHealthWorker
-  :feature_category: :incident_management
-  :has_external_dependencies: true
-  :urgency: :low
-  :resource_boundary: :unknown
-  :weight: 1
-  :idempotent: true
-  :tags: []
 - :name: cronjob:container_expiration_policy
   :worker_name: ContainerExpirationPolicyWorker
   :feature_category: :container_registry
@@ -561,15 +552,6 @@
   :weight: 1
   :idempotent: false
   :tags: []
-- :name: cronjob:metrics_dashboard_schedule_annotations_prune
-  :worker_name: Metrics::Dashboard::ScheduleAnnotationsPruneWorker
-  :feature_category: :metrics
-  :has_external_dependencies: false
-  :urgency: :low
-  :resource_boundary: :unknown
-  :weight: 1
-  :idempotent: true
-  :tags: []
 - :name: cronjob:metrics_global_metrics_update
   :worker_name: Metrics::GlobalMetricsUpdateWorker
   :feature_category: :metrics
@@ -3072,24 +3054,6 @@
   :weight: 1
   :idempotent: true
   :tags: []
-- :name: metrics_dashboard_prune_old_annotations
-  :worker_name: Metrics::Dashboard::PruneOldAnnotationsWorker
-  :feature_category: :metrics
-  :has_external_dependencies: false
-  :urgency: :low
-  :resource_boundary: :unknown
-  :weight: 1
-  :idempotent: true
-  :tags: []
-- :name: metrics_dashboard_sync_dashboards
-  :worker_name: Metrics::Dashboard::SyncDashboardsWorker
-  :feature_category: :metrics
-  :has_external_dependencies: false
-  :urgency: :low
-  :resource_boundary: :unknown
-  :weight: 1
-  :idempotent: true
-  :tags: []
 - :name: migrate_external_diffs
   :worker_name: MigrateExternalDiffsWorker
   :feature_category: :code_review_workflow
diff --git a/app/workers/clusters/integrations/check_prometheus_health_worker.rb b/app/workers/clusters/integrations/check_prometheus_health_worker.rb
deleted file mode 100644
index b65b3424c3a4d..0000000000000
--- a/app/workers/clusters/integrations/check_prometheus_health_worker.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-module Clusters
-  module Integrations
-    class CheckPrometheusHealthWorker
-      include ApplicationWorker
-
-      data_consistency :always
-
-      # rubocop:disable Scalability/CronWorkerContext
-      # This worker does not perform work scoped to a context
-      include CronjobQueue
-      # rubocop:enable Scalability/CronWorkerContext
-
-      feature_category :incident_management
-      urgency :low
-
-      idempotent!
-      worker_has_external_dependencies!
-
-      def perform; end
-    end
-  end
-end
diff --git a/app/workers/metrics/dashboard/prune_old_annotations_worker.rb b/app/workers/metrics/dashboard/prune_old_annotations_worker.rb
deleted file mode 100644
index 5b34f85606dcb..0000000000000
--- a/app/workers/metrics/dashboard/prune_old_annotations_worker.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-module Metrics
-  module Dashboard
-    class PruneOldAnnotationsWorker
-      include ApplicationWorker
-
-      data_consistency :always
-
-      sidekiq_options retry: 3
-
-      DELETE_LIMIT = 10_000
-      DEFAULT_CUT_OFF_PERIOD = 2.weeks
-
-      feature_category :metrics
-
-      idempotent! # in the scope of 24 hours
-
-      def perform; end
-    end
-  end
-end
diff --git a/app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb b/app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb
deleted file mode 100644
index fe002ffa4a0a7..0000000000000
--- a/app/workers/metrics/dashboard/schedule_annotations_prune_worker.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# frozen_string_literal: true
-
-module Metrics
-  module Dashboard
-    class ScheduleAnnotationsPruneWorker
-      include ApplicationWorker
-
-      data_consistency :always
-
-      # rubocop:disable Scalability/CronWorkerContext
-      # This worker does not perform work scoped to a context
-      include CronjobQueue
-      # rubocop:enable Scalability/CronWorkerContext
-
-      feature_category :metrics
-
-      idempotent! # PruneOldAnnotationsWorker worker is idempotent in the scope of 24 hours
-
-      def perform; end
-    end
-  end
-end
diff --git a/app/workers/metrics/dashboard/sync_dashboards_worker.rb b/app/workers/metrics/dashboard/sync_dashboards_worker.rb
deleted file mode 100644
index 668542e51a5ca..0000000000000
--- a/app/workers/metrics/dashboard/sync_dashboards_worker.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-module Metrics
-  module Dashboard
-    class SyncDashboardsWorker
-      include ApplicationWorker
-
-      data_consistency :always
-
-      sidekiq_options retry: 3
-
-      feature_category :metrics
-
-      idempotent!
-
-      def perform(project_id); end
-    end
-  end
-end
diff --git a/config/sidekiq_queues.yml b/config/sidekiq_queues.yml
index dc0b77ef99a90..2e643f8e977a4 100644
--- a/config/sidekiq_queues.yml
+++ b/config/sidekiq_queues.yml
@@ -373,10 +373,6 @@
   - 1
 - - merge_requests_update_head_pipeline
   - 1
-- - metrics_dashboard_prune_old_annotations
-  - 1
-- - metrics_dashboard_sync_dashboards
-  - 1
 - - migrate_external_diffs
   - 1
 - - ml_experiment_tracking_associate_ml_candidate_to_package
diff --git a/db/migrate/20230622093921_remove_deprecated_metric_worker_instances.rb b/db/migrate/20230622093921_remove_deprecated_metric_worker_instances.rb
new file mode 100644
index 0000000000000..ac2bc02ec3f28
--- /dev/null
+++ b/db/migrate/20230622093921_remove_deprecated_metric_worker_instances.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+class RemoveDeprecatedMetricWorkerInstances < Gitlab::Database::Migration[2.1]
+  DEPRECATED_JOB_CLASSES = %w[
+    Clusters::Integrations::CheckPrometheusHealthWorker
+    Metrics::Dashboard::PruneOldAnnotationsWorker
+    Metrics::Dashboard::ScheduleAnnotationsPruneWorker
+    Metrics::Dashboard::SyncDashboardsWorker
+  ]
+
+  disable_ddl_transaction!
+
+  def up
+    sidekiq_remove_jobs(job_klasses: DEPRECATED_JOB_CLASSES)
+  end
+
+  def down
+    # This migration removes any instances of deprecated workers and cannot be undone.
+  end
+end
diff --git a/db/schema_migrations/20230622093921 b/db/schema_migrations/20230622093921
new file mode 100644
index 0000000000000..696104cce80f1
--- /dev/null
+++ b/db/schema_migrations/20230622093921
@@ -0,0 +1 @@
+1947fe30ac91f67fc863879e4adbc46dbe6ef84c9daa7de8133a81a15eb0e6ce
\ No newline at end of file
diff --git a/spec/commands/sidekiq_cluster/cli_spec.rb b/spec/commands/sidekiq_cluster/cli_spec.rb
index 085be1ceac2e4..a63e7158c2a26 100644
--- a/spec/commands/sidekiq_cluster/cli_spec.rb
+++ b/spec/commands/sidekiq_cluster/cli_spec.rb
@@ -247,13 +247,13 @@
           expected_workers =
             if Gitlab.ee?
               [
-                %w[cronjob:clusters_integrations_check_prometheus_health incident_management_close_incident status_page_publish] + described_class::DEFAULT_QUEUES,
+                %w[incident_management_close_incident status_page_publish] + described_class::DEFAULT_QUEUES,
                 %w[bulk_imports_pipeline bulk_imports_relation_export project_export projects_import_export_parallel_project_export projects_import_export_relation_export repository_import project_template_export] +
                   described_class::DEFAULT_QUEUES
               ]
             else
               [
-                %w[cronjob:clusters_integrations_check_prometheus_health incident_management_close_incident] + described_class::DEFAULT_QUEUES,
+                %w[incident_management_close_incident] + described_class::DEFAULT_QUEUES,
                 %w[bulk_imports_pipeline bulk_imports_relation_export project_export projects_import_export_parallel_project_export projects_import_export_relation_export repository_import] +
                   described_class::DEFAULT_QUEUES
               ]
diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb
index cf1667cb0ff36..710845e507342 100644
--- a/spec/workers/every_sidekiq_worker_spec.rb
+++ b/spec/workers/every_sidekiq_worker_spec.rb
@@ -366,8 +366,6 @@
         'MergeRequests::SyncCodeOwnerApprovalRulesWorker' => 3,
         'MergeTrains::RefreshWorker' => 3,
         'MergeWorker' => 3,
-        'Metrics::Dashboard::PruneOldAnnotationsWorker' => 3,
-        'Metrics::Dashboard::SyncDashboardsWorker' => 3,
         'MigrateExternalDiffsWorker' => 3,
         'Onboarding::IssueCreatedWorker' => 3,
         'Onboarding::PipelineCreatedWorker' => 3,
-- 
GitLab