diff --git a/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll.rb b/lib/gitlab/usage/metrics/aggregates/sources/postgres_hll.rb index 88677f6a90c755e02fb18b53a5f4c14ec18c91ac..551eb2b5a6d72871535890642abda7cde4040ac8 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 d60396152a9a1c53fcf81f0b622279912f30f83d..9353f29007b491c18e5e64885d12721bcdbab45f 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 7ee32a8ee30ac23a87bf0c4f6d3022f584718985..366e9f0bc156553fbdc3371ca1c6b5e97c9bbb72 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 e499ff0bc70586b707f77802c26248c1a28bf283..310137653a9323be21524ab9069be1550ed7020c 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 5cb08c1a3c40e10c3df615302e452c4d995eb6b2..c3eddce4004ca21c2111ca86f56b3b85735210fe 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