From e95671953d747eed9bda479bd3c1b49d6a3149ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thiago=20Figueir=C3=B3?= <tfigueiro@gitlab.com>
Date: Thu, 27 Jan 2022 21:52:47 +0000
Subject: [PATCH] Remove vulnerability_history feature flag

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79186
https://gitlab.com/gitlab-org/gitlab/-/issues/213625

Changelog: removed
---
 ee/app/models/ee/vulnerability.rb             | 24 --------
 .../development/vulnerability_history.yml     |  8 ---
 ee/spec/models/ee/vulnerability_spec.rb       | 57 -------------------
 3 files changed, 89 deletions(-)
 delete mode 100644 ee/config/feature_flags/development/vulnerability_history.yml

diff --git a/ee/app/models/ee/vulnerability.rb b/ee/app/models/ee/vulnerability.rb
index b5c7f7eb7d17e..10fbcaeb29939 100644
--- a/ee/app/models/ee/vulnerability.rb
+++ b/ee/app/models/ee/vulnerability.rb
@@ -225,30 +225,6 @@ def to_ability_name
         model_name.singular
       end
 
-      def counts_by_day_and_severity(start_date, end_date)
-        return [] unless ::Feature.enabled?(:vulnerability_history, default_enabled: true)
-
-        num_days_of_history = end_date - start_date + 1
-
-        # this clause guards against query timeouts
-        raise TooManyDaysError, "Cannot fetch counts for more than #{MAX_DAYS_OF_HISTORY} days" if num_days_of_history > MAX_DAYS_OF_HISTORY
-
-        quoted_start_date = connection.quote(start_date)
-        quoted_end_date = connection.quote(end_date)
-
-        select(
-          'DATE(calendar.entry) AS day, severity, COUNT(*)'
-        ).from(
-          "generate_series(DATE #{quoted_start_date}, DATE #{quoted_end_date}, INTERVAL '1 day') as calendar(entry)"
-        ).joins(
-          'INNER JOIN vulnerabilities ON vulnerabilities.created_at <= calendar.entry'
-        ).where(
-          '(vulnerabilities.dismissed_at IS NULL OR vulnerabilities.dismissed_at > calendar.entry) AND (vulnerabilities.resolved_at IS NULL OR vulnerabilities.resolved_at > calendar.entry)'
-        ).group(
-          :day, :severity
-        )
-      end
-
       def report_type_order
         report_types
           .sort
diff --git a/ee/config/feature_flags/development/vulnerability_history.yml b/ee/config/feature_flags/development/vulnerability_history.yml
deleted file mode 100644
index c201cda48e109..0000000000000
--- a/ee/config/feature_flags/development/vulnerability_history.yml
+++ /dev/null
@@ -1,8 +0,0 @@
----
-name: vulnerability_history
-introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27052
-rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/213625
-milestone: '13.0'
-type: development
-group: group::threat insights
-default_enabled: true
diff --git a/ee/spec/models/ee/vulnerability_spec.rb b/ee/spec/models/ee/vulnerability_spec.rb
index 5cc78824a90ca..2681b7a615023 100644
--- a/ee/spec/models/ee/vulnerability_spec.rb
+++ b/ee/spec/models/ee/vulnerability_spec.rb
@@ -447,63 +447,6 @@
     end
   end
 
-  describe '.counts_by_day_and_severity' do
-    let(:current_date) { Time.zone.parse('2019-10-31') }
-    let(:from_date) { Date.parse('2019-10-22') }
-    let(:to_date) { Date.parse('2019-10-28') }
-
-    let!(:vulnerability_1) { create(:vulnerability, created_at: 5.days.ago, dismissed_at: Date.current, severity: :critical) }
-    let!(:vulnerability_2) { create(:vulnerability, created_at: 5.days.ago, dismissed_at: 1.day.ago, severity: :high) }
-    let!(:vulnerability_3) { create(:vulnerability, created_at: 4.days.ago, resolved_at: 2.days.ago, severity: :critical) }
-
-    subject(:counts_by_day_and_severity) { ::Vulnerability.counts_by_day_and_severity(from_date, to_date) }
-
-    around do |example|
-      travel_to(current_date) { example.run }
-    end
-
-    context 'when the vulnerability_history feature flag is disabled' do
-      before do
-        stub_feature_flags(vulnerability_history: false)
-      end
-
-      it 'returns an empty array' do
-        expect(counts_by_day_and_severity).to be_empty
-      end
-    end
-
-    context 'when the vulnerability_history feature flag is enabled' do
-      before do
-        stub_feature_flags(vulnerability_history: true)
-      end
-
-      context 'when there are less than 10 days between the from and to dates' do
-        it 'returns the count of unresolved, undismissed vulnerabilities for each severity for each day from the start date to the end date' do
-          expect(counts_by_day_and_severity.order(:day, :severity).to_json).to eq([
-            { 'day' => '2019-10-26', 'severity' => 'high', 'count' => 1, 'id' => nil },
-            { 'day' => '2019-10-26', 'severity' => 'critical', 'count' => 1, 'id' => nil },
-            { 'day' => '2019-10-27', 'severity' => 'high', 'count' => 1, 'id' => nil },
-            { 'day' => '2019-10-27', 'severity' => 'critical', 'count' => 2, 'id' => nil },
-            { 'day' => '2019-10-28', 'severity' => 'high', 'count' => 1, 'id' => nil },
-            { 'day' => '2019-10-28', 'severity' => 'critical', 'count' => 2, 'id' => nil }
-          ].to_json)
-        end
-      end
-
-      context 'when theere are more than 10 days between the from and to dates' do
-        let(:from_date) { 10.days.ago.to_date }
-        let(:to_date) { Date.current }
-
-        it 'raises a TooManyDaysError' do
-          expect { counts_by_day_and_severity }.to raise_error(
-            ::Vulnerability::TooManyDaysError,
-            'Cannot fetch counts for more than 10 days'
-          )
-        end
-      end
-    end
-  end
-
   describe '.active_state_values' do
     let(:expected_values) { ::Vulnerability.states.values_at('detected', 'confirmed') }
 
-- 
GitLab