From 724e4ae298e1d5a56d2be6980cfe933325355c61 Mon Sep 17 00:00:00 2001
From: Jonas Larsen <jlarsen@gitlab.com>
Date: Mon, 19 Feb 2024 03:00:29 +0000
Subject: [PATCH] Remove "AND" operator - postgres_hll and redis_hll

---
 .../aggregates/sources/postgres_hll.rb        |  1 -
 .../metrics/aggregates/sources/redis_hll.rb   |  2 --
 .../aggregates/sources/postgres_hll_spec.rb   | 26 -------------------
 .../aggregates/sources/redis_hll_spec.rb      | 26 -------------------
 .../aggregated_metric_spec.rb                 |  4 ---
 5 files changed, 59 deletions(-)

diff --git a/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll.rb b/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll.rb
index 88677f6a90c75..551eb2b5a6d72 100644
--- a/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll.rb
+++ b/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll.rb
@@ -6,7 +6,6 @@ module Metrics
       module Aggregates
         module Sources
           class PostgresHll
-            extend Calculations::Intersection
             class << self
               def calculate_metrics_union(metric_names:, start_date:, end_date:, recorded_at:, property_name:) # rubocop:disable Lint/UnusedMethodArgument -- property_name is used only for RedisHLL source
                 time_period = start_date && end_date ? (start_date..end_date) : nil
diff --git a/lib/gitlab/usage/metrics/aggregates/sources/redis_hll.rb b/lib/gitlab/usage/metrics/aggregates/sources/redis_hll.rb
index d60396152a9a1..9353f29007b49 100644
--- a/lib/gitlab/usage/metrics/aggregates/sources/redis_hll.rb
+++ b/lib/gitlab/usage/metrics/aggregates/sources/redis_hll.rb
@@ -6,8 +6,6 @@ module Metrics
       module Aggregates
         module Sources
           class RedisHll
-            extend Calculations::Intersection
-
             def self.calculate_metrics_union(metric_names:, start_date:, end_date:, property_name:, recorded_at: nil)
               union = Gitlab::UsageDataCounters::HLLRedisCounter.calculate_events_union(
                 event_names: metric_names,
diff --git a/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb b/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb
index 7ee32a8ee30ac..366e9f0bc1565 100644
--- a/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb
+++ b/spec/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll_spec.rb
@@ -59,32 +59,6 @@
         end
       end
     end
-
-    describe '.calculate_metrics_intersections' do
-      subject(:calculate_metrics_intersections) do
-        described_class.calculate_metrics_intersections(metric_names: metric_names, start_date: start_date, end_date: end_date, recorded_at: recorded_at, property_name: property_name)
-      end
-
-      it 'returns the number of common events in the intersection of all metrics' do
-        expect(calculate_metrics_intersections.round(2)).to be_within(error_rate).percent_of(1)
-      end
-
-      context 'when there is no aggregated data saved' do
-        let(:metric_names) { [metric_1, 'i do not have any records'] }
-
-        it 'raises error when union data is missing' do
-          expect { calculate_metrics_intersections }.to raise_error Gitlab::Usage::Metrics::Aggregates::Sources::UnionNotAvailable
-        end
-      end
-
-      context 'when there is only one metric defined in aggregate' do
-        let(:metric_names) { [metric_1] }
-
-        it 'returns the number of common/unique events for the intersection of that metric' do
-          expect(calculate_metrics_intersections.round(2)).to be_within(error_rate).percent_of(2)
-        end
-      end
-    end
   end
 
   describe '.save_aggregated_metrics' do
diff --git a/spec/lib/gitlab/usage/metrics/aggregates/sources/redis_hll_spec.rb b/spec/lib/gitlab/usage/metrics/aggregates/sources/redis_hll_spec.rb
index e499ff0bc7058..310137653a932 100644
--- a/spec/lib/gitlab/usage/metrics/aggregates/sources/redis_hll_spec.rb
+++ b/spec/lib/gitlab/usage/metrics/aggregates/sources/redis_hll_spec.rb
@@ -28,30 +28,4 @@
       expect { calculate_metrics_union }.to raise_error Gitlab::Usage::Metrics::Aggregates::Sources::UnionNotAvailable
     end
   end
-
-  describe '.calculate_metrics_intersections' do
-    subject(:calculate_metrics_intersections) do
-      described_class.calculate_metrics_intersections(metric_names: event_names, start_date: start_date, end_date: end_date, recorded_at: recorded_at, property_name: property_name)
-    end
-
-    it 'uses values returned by union to compute the intersection' do
-      event_names.each do |event|
-        expect(Gitlab::Usage::Metrics::Aggregates::Sources::RedisHll).to receive(:calculate_metrics_union)
-                                                              .with(metric_names: event, start_date: start_date, end_date: end_date, recorded_at: recorded_at, property_name: property_name)
-                                                              .and_return(5)
-      end
-
-      expect(described_class).to receive(:calculate_metrics_union)
-                                                              .with(metric_names: event_names, start_date: start_date, end_date: end_date, recorded_at: recorded_at, property_name: property_name)
-                                                              .and_return(2)
-
-      expect(calculate_metrics_intersections).to eq(8)
-    end
-
-    it 'raises error if union is < 0' do
-      allow(described_class).to receive(:calculate_metrics_union).and_raise(Gitlab::Usage::Metrics::Aggregates::Sources::UnionNotAvailable)
-
-      expect { calculate_metrics_intersections }.to raise_error(Gitlab::Usage::Metrics::Aggregates::Sources::UnionNotAvailable)
-    end
-  end
 end
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/aggregated_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/aggregated_metric_spec.rb
index 5cb08c1a3c40e..c3eddce4004ca 100644
--- a/spec/lib/gitlab/usage/metrics/instrumentations/aggregated_metric_spec.rb
+++ b/spec/lib/gitlab/usage/metrics/instrumentations/aggregated_metric_spec.rb
@@ -44,16 +44,12 @@
   end
 
   where(:data_source, :time_frame, :operator, :attribute, :expected_value, :property_name_flag_enabled) do
-    'redis_hll' | '28d' | 'AND' | 'user_id'    | 2   | true
     'redis_hll' | '28d' | 'OR'  | 'user_id'    | 3   | true
     'redis_hll' | '28d' | 'OR'  | 'user_id'    | 4   | false
     'redis_hll' | '28d' | 'OR'  | 'project_id' | 4   | false
-    'redis_hll' | '7d'  | 'AND' | 'user_id'    | 1   | true
     'redis_hll' | '7d'  | 'OR'  | 'user_id'    | 2   | true
     'redis_hll' | '7d'  | 'OR'  | 'project_id' | 1   | true
-    'redis_hll' | '7d'  | 'AND' | 'project_id' | 0   | true
     'database'  | '7d'  | 'OR'  | 'user_id'    | 3.0 | true
-    'database'  | '7d'  | 'AND' | 'user_id'    | 1.0 | true
   end
 
   with_them do
-- 
GitLab