diff options
Diffstat (limited to 'spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb b/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb index 10e336e9235..8be0769a379 100644 --- a/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb +++ b/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb @@ -58,6 +58,50 @@ RSpec.describe Gitlab::Usage::Metrics::Aggregates::Aggregate, :clean_gitlab_redi end end + # EE version has validation that doesn't allow undefined events + # On CE, we detect EE events as undefined + context 'when configuration includes undefined events', unless: Gitlab.ee? do + let(:number_of_days) { 28 } + + before do + allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:known_event?).with('event3').and_return(false) + end + + where(:operator, :datasource, :expected_method, :expected_events) do + 'AND' | 'redis_hll' | :calculate_metrics_intersections | %w[event1 event2] + 'AND' | 'database' | :calculate_metrics_intersections | %w[event1 event2 event3] + 'OR' | 'redis_hll' | :calculate_metrics_union | %w[event1 event2] + 'OR' | 'database' | :calculate_metrics_union | %w[event1 event2 event3] + end + + with_them do + let(:time_frame) { "#{number_of_days}d" } + let(:start_date) { number_of_days.days.ago.to_date } + let(:params) { { start_date: start_date, end_date: end_date, recorded_at: recorded_at } } + let(:aggregate) do + { + source: datasource, + operator: operator, + events: %w[event1 event2 event3] + } + end + + subject(:calculate_count_for_aggregation) do + described_class + .new(recorded_at) + .calculate_count_for_aggregation(aggregation: aggregate, time_frame: time_frame) + end + + it 'returns the number of unique events for aggregation', :aggregate_failures do + expect(namespace::SOURCES[datasource]) + .to receive(expected_method) + .with(params.merge(metric_names: expected_events)) + .and_return(5) + expect(calculate_count_for_aggregation).to eq(5) + end + end + end + context 'with invalid configuration' do where(:time_frame, :operator, :datasource, :expected_error) do '28d' | 'SUM' | 'redis_hll' | namespace::UnknownAggregationOperator |