From 7eec7da11634e99f6573b8e596c42c967303cc3b Mon Sep 17 00:00:00 2001
From: Ankit Panchal <apanchal@gitlab.com>
Date: Tue, 9 Apr 2024 04:09:08 +0000
Subject: [PATCH] Migrate status_page_incident published/unpublished to
 internal events

---
 .rubocop_todo/rspec/feature_category.yml        |  1 -
 .../events/status_page_incident_published.yml   | 17 +++++++++++++++++
 .../events/status_page_incident_unpublished.yml | 17 +++++++++++++++++
 .../status_page/mark_for_publication_service.rb |  7 +++++--
 .../status_page/unpublish_details_service.rb    |  6 ++++--
 ...216180502_status_page_incident_publishes.yml | 14 ++++++--------
 ...6180504_status_page_incident_unpublishes.yml | 14 ++++++--------
 ee/lib/ee/gitlab/usage_data_counters.rb         |  1 -
 .../usage_data_counters/incident_counter.rb     | 12 ------------
 .../incident_counter_spec.rb                    | 10 ----------
 .../mark_for_publication_service_spec.rb        |  6 ++----
 .../unpublish_details_service_spec.rb           |  6 ++++--
 .../total_counter_redis_key_overrides.yml       |  2 ++
 13 files changed, 63 insertions(+), 50 deletions(-)
 create mode 100644 config/events/status_page_incident_published.yml
 create mode 100644 config/events/status_page_incident_unpublished.yml
 delete mode 100644 ee/lib/gitlab/status_page/usage_data_counters/incident_counter.rb
 delete mode 100644 ee/spec/lib/gitlab/status_page/usage_data_counters/incident_counter_spec.rb

diff --git a/.rubocop_todo/rspec/feature_category.yml b/.rubocop_todo/rspec/feature_category.yml
index d04314b4f4fd..7f62eee9bec6 100644
--- a/.rubocop_todo/rspec/feature_category.yml
+++ b/.rubocop_todo/rspec/feature_category.yml
@@ -838,7 +838,6 @@ RSpec/FeatureCategory:
     - 'ee/spec/lib/gitlab/status_page/storage/s3_client_spec.rb'
     - 'ee/spec/lib/gitlab/status_page/storage/s3_multipart_upload_spec.rb'
     - 'ee/spec/lib/gitlab/status_page/storage_spec.rb'
-    - 'ee/spec/lib/gitlab/status_page/usage_data_counters/incident_counter_spec.rb'
     - 'ee/spec/lib/gitlab/status_page_spec.rb'
     - 'ee/spec/lib/gitlab/subscription_portal/client_spec.rb'
     - 'ee/spec/lib/gitlab/template/custom_templates_spec.rb'
diff --git a/config/events/status_page_incident_published.yml b/config/events/status_page_incident_published.yml
new file mode 100644
index 000000000000..19b5cd2f0ce7
--- /dev/null
+++ b/config/events/status_page_incident_published.yml
@@ -0,0 +1,17 @@
+---
+description: Tracks usages of publish operation
+internal_events: true
+action: status_page_incident_published
+identifiers:
+  - project
+  - user
+  - namespace
+product_section: ops
+product_stage: monitor
+product_group: respond
+milestone: '16.11'
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/146160
+distributions:
+  - ee
+tiers:
+  - ultimate
diff --git a/config/events/status_page_incident_unpublished.yml b/config/events/status_page_incident_unpublished.yml
new file mode 100644
index 000000000000..98c19130f846
--- /dev/null
+++ b/config/events/status_page_incident_unpublished.yml
@@ -0,0 +1,17 @@
+---
+description: Tracks usages of unpublish operation
+internal_events: true
+action: status_page_incident_unpublished
+identifiers:
+  - project
+  - user
+  - namespace
+product_section: ops
+product_stage: monitor
+product_group: respond
+milestone: '16.11'
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/146160
+distributions:
+  - ee
+tiers:
+  - ultimate
diff --git a/ee/app/services/status_page/mark_for_publication_service.rb b/ee/app/services/status_page/mark_for_publication_service.rb
index 56657b00bab0..0466fd5764c1 100644
--- a/ee/app/services/status_page/mark_for_publication_service.rb
+++ b/ee/app/services/status_page/mark_for_publication_service.rb
@@ -44,8 +44,11 @@ def add_system_note
     end
 
     def track_incident
-      ::Gitlab::StatusPage::UsageDataCounters::IncidentCounter.count(:publishes)
-
+      Gitlab::InternalEvents.track_event(
+        'status_page_incident_published',
+        project: project,
+        user: user
+      )
       PublishedIncident.track(issue)
     end
 
diff --git a/ee/app/services/status_page/unpublish_details_service.rb b/ee/app/services/status_page/unpublish_details_service.rb
index fb3698f4c0f9..c51a30252632 100644
--- a/ee/app/services/status_page/unpublish_details_service.rb
+++ b/ee/app/services/status_page/unpublish_details_service.rb
@@ -14,8 +14,10 @@ class UnpublishDetailsService < PublishBaseService
 
     def process(issue)
       PublishedIncident.untrack(issue)
-      ::Gitlab::StatusPage::UsageDataCounters::IncidentCounter.count(:unpublishes)
-
+      Gitlab::InternalEvents.track_event(
+        'status_page_incident_unpublished',
+        project: project
+      )
       # Delete the incident prior to deleting images to avoid broken links
       json_key = json_object_key(issue)
       delete_object(json_key)
diff --git a/ee/config/metrics/counts_all/20210216180502_status_page_incident_publishes.yml b/ee/config/metrics/counts_all/20210216180502_status_page_incident_publishes.yml
index 47170e4c9add..3600e4d49ea0 100644
--- a/ee/config/metrics/counts_all/20210216180502_status_page_incident_publishes.yml
+++ b/ee/config/metrics/counts_all/20210216180502_status_page_incident_publishes.yml
@@ -8,14 +8,12 @@ product_group: respond
 value_type: number
 status: active
 time_frame: all
-data_source: redis
-instrumentation_class: RedisMetric
-options:
-  prefix: status_page_incident
-  event: publishes
+data_source: internal_events
+events:
+  - name: status_page_incident_published
 distribution:
-- ee
+  - ee
 tier:
-- ultimate
+  - ultimate
 performance_indicator_type: []
-milestone: "<13.9"
+milestone: '<13.9'
diff --git a/ee/config/metrics/counts_all/20210216180504_status_page_incident_unpublishes.yml b/ee/config/metrics/counts_all/20210216180504_status_page_incident_unpublishes.yml
index 7025561d723a..a024d9e00b96 100644
--- a/ee/config/metrics/counts_all/20210216180504_status_page_incident_unpublishes.yml
+++ b/ee/config/metrics/counts_all/20210216180504_status_page_incident_unpublishes.yml
@@ -8,14 +8,12 @@ product_group: respond
 value_type: number
 status: active
 time_frame: all
-data_source: redis
-instrumentation_class: RedisMetric
-options:
-  prefix: status_page_incident
-  event: unpublishes
+data_source: internal_events
+events:
+  - name: status_page_incident_unpublished
 distribution:
-- ee
+  - ee
 tier:
-- ultimate
+  - ultimate
 performance_indicator_type: []
-milestone: "<13.9"
+milestone: '<13.9'
diff --git a/ee/lib/ee/gitlab/usage_data_counters.rb b/ee/lib/ee/gitlab/usage_data_counters.rb
index 179e6889d0e4..410c436d8e4e 100644
--- a/ee/lib/ee/gitlab/usage_data_counters.rb
+++ b/ee/lib/ee/gitlab/usage_data_counters.rb
@@ -11,7 +11,6 @@ module UsageDataCounters
         override :counters
         def counters
           super + [
-            ::Gitlab::StatusPage::UsageDataCounters::IncidentCounter,
             ::Gitlab::UsageDataCounters::LicenseTestingCounter
           ]
         end
diff --git a/ee/lib/gitlab/status_page/usage_data_counters/incident_counter.rb b/ee/lib/gitlab/status_page/usage_data_counters/incident_counter.rb
deleted file mode 100644
index 52c59a3ffd4e..000000000000
--- a/ee/lib/gitlab/status_page/usage_data_counters/incident_counter.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
-  module StatusPage
-    module UsageDataCounters
-      class IncidentCounter < ::Gitlab::UsageDataCounters::BaseCounter
-        KNOWN_EVENTS = %w[publishes unpublishes].freeze
-        PREFIX = 'status_page_incident'
-      end
-    end
-  end
-end
diff --git a/ee/spec/lib/gitlab/status_page/usage_data_counters/incident_counter_spec.rb b/ee/spec/lib/gitlab/status_page/usage_data_counters/incident_counter_spec.rb
deleted file mode 100644
index 7df8ecc4b33b..000000000000
--- a/ee/spec/lib/gitlab/status_page/usage_data_counters/incident_counter_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-RSpec.describe Gitlab::StatusPage::UsageDataCounters::IncidentCounter do
-  it_behaves_like 'a redis usage counter', 'StatusPage::IncidentCounter', :publishes
-  it_behaves_like 'a redis usage counter', 'StatusPage::IncidentCounter', :unpublishes
-
-  it_behaves_like 'a redis usage counter with totals', :status_page_incident, publishes: 7, unpublishes: 2
-end
diff --git a/ee/spec/services/status_page/mark_for_publication_service_spec.rb b/ee/spec/services/status_page/mark_for_publication_service_spec.rb
index c47b9bd5ab77..c85437a3eecb 100644
--- a/ee/spec/services/status_page/mark_for_publication_service_spec.rb
+++ b/ee/spec/services/status_page/mark_for_publication_service_spec.rb
@@ -55,10 +55,8 @@
         specify { expect { subject }.to change { issue.notes.count }.by(1) }
         specify { expect(subject).to be_success }
 
-        it 'increments the publish counter' do
-          expect(Gitlab::StatusPage::UsageDataCounters::IncidentCounter).to receive(:count).with(:publishes).once
-
-          subject
+        it_behaves_like 'internal event tracking' do
+          let(:event) { 'status_page_incident_published' }
         end
       end
 
diff --git a/ee/spec/services/status_page/unpublish_details_service_spec.rb b/ee/spec/services/status_page/unpublish_details_service_spec.rb
index f25b044934b9..30fdb510960f 100644
--- a/ee/spec/services/status_page/unpublish_details_service_spec.rb
+++ b/ee/spec/services/status_page/unpublish_details_service_spec.rb
@@ -53,10 +53,12 @@
 
       it 'untracks the issue' do
         expect(StatusPage::PublishedIncident).to receive(:untrack).with(issue)
-        expect(Gitlab::StatusPage::UsageDataCounters::IncidentCounter).to receive(:count).with(:unpublishes).once
-
         result
       end
+
+      it_behaves_like 'internal event tracking' do
+        let(:event) { 'status_page_incident_unpublished' }
+      end
     end
 
     context 'when delete fails due to exception' do
diff --git a/lib/gitlab/usage_data_counters/total_counter_redis_key_overrides.yml b/lib/gitlab/usage_data_counters/total_counter_redis_key_overrides.yml
index b8662b8573aa..7cf3ed0d829d 100644
--- a/lib/gitlab/usage_data_counters/total_counter_redis_key_overrides.yml
+++ b/lib/gitlab/usage_data_counters/total_counter_redis_key_overrides.yml
@@ -12,3 +12,5 @@
 '{event_counters}_usage_data_download_payload_clicked': USAGE_SERVICE_USAGE_DATA_DOWNLOAD_PAYLOAD_CLICK
 '{event_counters}_value_streams_dashboard_viewed': USAGE_VALUE_STREAMS_DASHBOARD_VIEWS
 '{event_counters}_web_ide_viewed': WEB_IDE_VIEWS_COUNT
+'{event_counters}_status_page_incident_published': USAGE_STATUS_PAGE_INCIDENT_PUBLISHES
+'{event_counters}_status_page_incident_unpublished': USAGE_STATUS_PAGE_INCIDENT_UNPUBLISHES
-- 
GitLab