From 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 17 Nov 2022 11:33:21 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-6-stable-ee --- spec/lib/gitlab/usage_data_spec.rb | 196 +------------------------------------ 1 file changed, 3 insertions(+), 193 deletions(-) (limited to 'spec/lib/gitlab/usage_data_spec.rb') diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index cb645ae3e53..d8f50fa27bb 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -33,8 +33,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do .not_to include(:merge_requests_users) expect(subject[:usage_activity_by_stage_monthly][:create]) .to include(:merge_requests_users) - expect(subject[:counts_weekly]).to include(:aggregated_metrics) - expect(subject[:counts_monthly]).to include(:aggregated_metrics) end it 'clears memoized values' do @@ -608,13 +606,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do let_it_be(:disabled) { create(:container_expiration_policy, enabled: false) } let_it_be(:enabled) { create(:container_expiration_policy, enabled: true) } - %i[keep_n cadence older_than].each do |attribute| - ContainerExpirationPolicy.send("#{attribute}_options").keys.each do |value| - let_it_be("container_expiration_policy_with_#{attribute}_set_to_#{value}") { create(:container_expiration_policy, attribute => value) } - end + ::ContainerExpirationPolicy.older_than_options.keys.each do |value| + let_it_be("container_expiration_policy_with_older_than_set_to_#{value}") { create(:container_expiration_policy, older_than: value) } end - let_it_be('container_expiration_policy_with_keep_n_set_to_null') { create(:container_expiration_policy, keep_n: nil) } let_it_be('container_expiration_policy_with_older_than_set_to_null') { create(:container_expiration_policy, older_than: nil) } let(:inactive_policies) { ::ContainerExpirationPolicy.where(enabled: false) } @@ -623,27 +618,12 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do subject { described_class.data[:counts] } it 'gathers usage data' do - expect(subject[:projects_with_expiration_policy_enabled]).to eq 19 - - expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_unset]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_1]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_5]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_10]).to eq 13 - expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_25]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_keep_n_set_to_50]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_older_than_unset]).to eq 1 expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_7d]).to eq 1 expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_14d]).to eq 1 expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_30d]).to eq 1 expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_60d]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_90d]).to eq 14 - - expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_1d]).to eq 15 - expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_7d]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_14d]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_1month]).to eq 1 - expect(subject[:projects_with_expiration_policy_enabled_with_cadence_set_to_3month]).to eq 1 + expect(subject[:projects_with_expiration_policy_enabled_with_older_than_set_to_90d]).to eq 2 end end @@ -757,33 +737,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do end end - describe '.usage_data_counters' do - subject { described_class.usage_data_counters } - - it { is_expected.to all(respond_to :totals) } - it { is_expected.to all(respond_to :fallback_totals) } - - describe 'the results of calling #totals on all objects in the array' do - subject { described_class.usage_data_counters.map(&:totals) } - - it { is_expected.to all(be_a Hash) } - it { is_expected.to all(have_attributes(keys: all(be_a Symbol), values: all(be_a Integer))) } - end - - describe 'the results of calling #fallback_totals on all objects in the array' do - subject { described_class.usage_data_counters.map(&:fallback_totals) } - - it { is_expected.to all(be_a Hash) } - it { is_expected.to all(have_attributes(keys: all(be_a Symbol), values: all(eq(-1)))) } - end - - it 'does not have any conflicts' do - all_keys = subject.flat_map { |counter| counter.totals.keys } - - expect(all_keys.size).to eq all_keys.to_set.size - end - end - describe '.license_usage_data' do subject { described_class.license_usage_data } @@ -1107,10 +1060,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do end context 'snowplow stats' do - before do - stub_feature_flags(usage_data_instrumentation: false) - end - it 'gathers snowplow stats' do expect(subject[:settings][:snowplow_enabled]).to eq(Gitlab::CurrentSettings.snowplow_enabled?) expect(subject[:settings][:snowplow_configured_to_gitlab_collector]).to eq(snowplow_gitlab_host?) @@ -1159,20 +1108,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do let(:project) { build(:project) } before do - counter = Gitlab::UsageDataCounters::TrackUniqueEvents - project_type = Event::TARGET_TYPES[:project] - wiki = Event::TARGET_TYPES[:wiki] - design = Event::TARGET_TYPES[:design] - - counter.track_event(event_action: :pushed, event_target: project_type, author_id: 1) - counter.track_event(event_action: :pushed, event_target: project_type, author_id: 1) - counter.track_event(event_action: :pushed, event_target: project_type, author_id: 2) - counter.track_event(event_action: :pushed, event_target: project_type, author_id: 3) - counter.track_event(event_action: :pushed, event_target: project_type, author_id: 4, time: time - 3.days) - counter.track_event(event_action: :created, event_target: wiki, author_id: 3) - counter.track_event(event_action: :created, event_target: design, author_id: 3) - counter.track_event(event_action: :created, event_target: design, author_id: 4) - counter = Gitlab::UsageDataCounters::EditorUniqueCounter counter.track_web_ide_edit_action(author: user1, project: project) @@ -1191,10 +1126,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do it 'returns the distinct count of user actions within the specified time period' do expect(described_class.action_monthly_active_users(time_period)).to eq( { - action_monthly_active_users_design_management: 2, - action_monthly_active_users_project_repo: 3, - action_monthly_active_users_wiki_repo: 1, - action_monthly_active_users_git_write: 4, action_monthly_active_users_web_ide_edit: 2, action_monthly_active_users_sfe_edit: 2, action_monthly_active_users_snippet_editor_edit: 2, @@ -1234,23 +1165,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do end end - describe '.aggregated_metrics_data' do - it 'uses ::Gitlab::Usage::Metrics::Aggregates::Aggregate methods', :aggregate_failures do - expected_payload = { - counts_weekly: { aggregated_metrics: { global_search_gmau: 123 } }, - counts_monthly: { aggregated_metrics: { global_search_gmau: 456 } }, - counts: { aggregate_global_search_gmau: 789 } - } - - expect_next_instance_of(::Gitlab::Usage::Metrics::Aggregates::Aggregate) do |instance| - expect(instance).to receive(:weekly_data).and_return(global_search_gmau: 123) - expect(instance).to receive(:monthly_data).and_return(global_search_gmau: 456) - expect(instance).to receive(:all_time_data).and_return(global_search_gmau: 789) - end - expect(described_class.aggregated_metrics_data).to eq(expected_payload) - end - end - describe '.service_desk_counts' do subject { described_class.send(:service_desk_counts) } @@ -1264,110 +1178,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do end end - describe '.email_campaign_counts' do - subject { described_class.send(:email_campaign_counts) } - - context 'when queries time out' do - before do - allow_any_instance_of(ActiveRecord::Relation).to receive(:count).and_raise(ActiveRecord::StatementInvalid) - allow(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(should_raise_for_dev) - end - - context 'with should_raise_for_dev? true' do - let(:should_raise_for_dev) { true } - - it 'raises an error' do - expect { subject }.to raise_error(ActiveRecord::StatementInvalid) - end - end - - context 'with should_raise_for_dev? false' do - let(:should_raise_for_dev) { false } - - it 'returns -1 for email campaign data' do - expected_data = { - "in_product_marketing_email_create_0_sent" => -1, - "in_product_marketing_email_create_0_cta_clicked" => -1, - "in_product_marketing_email_create_1_sent" => -1, - "in_product_marketing_email_create_1_cta_clicked" => -1, - "in_product_marketing_email_create_2_sent" => -1, - "in_product_marketing_email_create_2_cta_clicked" => -1, - "in_product_marketing_email_team_short_0_sent" => -1, - "in_product_marketing_email_team_short_0_cta_clicked" => -1, - "in_product_marketing_email_trial_short_0_sent" => -1, - "in_product_marketing_email_trial_short_0_cta_clicked" => -1, - "in_product_marketing_email_admin_verify_0_sent" => -1, - "in_product_marketing_email_admin_verify_0_cta_clicked" => -1, - "in_product_marketing_email_verify_0_sent" => -1, - "in_product_marketing_email_verify_0_cta_clicked" => -1, - "in_product_marketing_email_verify_1_sent" => -1, - "in_product_marketing_email_verify_1_cta_clicked" => -1, - "in_product_marketing_email_verify_2_sent" => -1, - "in_product_marketing_email_verify_2_cta_clicked" => -1, - "in_product_marketing_email_trial_0_sent" => -1, - "in_product_marketing_email_trial_0_cta_clicked" => -1, - "in_product_marketing_email_trial_1_sent" => -1, - "in_product_marketing_email_trial_1_cta_clicked" => -1, - "in_product_marketing_email_trial_2_sent" => -1, - "in_product_marketing_email_trial_2_cta_clicked" => -1, - "in_product_marketing_email_team_0_sent" => -1, - "in_product_marketing_email_team_0_cta_clicked" => -1, - "in_product_marketing_email_team_1_sent" => -1, - "in_product_marketing_email_team_1_cta_clicked" => -1, - "in_product_marketing_email_team_2_sent" => -1, - "in_product_marketing_email_team_2_cta_clicked" => -1 - } - - expect(subject).to eq(expected_data) - end - end - end - - context 'when there are entries' do - before do - create(:in_product_marketing_email, track: :create, series: 0, cta_clicked_at: Time.zone.now) - create(:in_product_marketing_email, track: :verify, series: 0) - end - - it 'gathers email campaign data' do - expected_data = { - "in_product_marketing_email_create_0_sent" => 1, - "in_product_marketing_email_create_0_cta_clicked" => 1, - "in_product_marketing_email_create_1_sent" => 0, - "in_product_marketing_email_create_1_cta_clicked" => 0, - "in_product_marketing_email_create_2_sent" => 0, - "in_product_marketing_email_create_2_cta_clicked" => 0, - "in_product_marketing_email_team_short_0_sent" => 0, - "in_product_marketing_email_team_short_0_cta_clicked" => 0, - "in_product_marketing_email_trial_short_0_sent" => 0, - "in_product_marketing_email_trial_short_0_cta_clicked" => 0, - "in_product_marketing_email_admin_verify_0_sent" => 0, - "in_product_marketing_email_admin_verify_0_cta_clicked" => 0, - "in_product_marketing_email_verify_0_sent" => 1, - "in_product_marketing_email_verify_0_cta_clicked" => 0, - "in_product_marketing_email_verify_1_sent" => 0, - "in_product_marketing_email_verify_1_cta_clicked" => 0, - "in_product_marketing_email_verify_2_sent" => 0, - "in_product_marketing_email_verify_2_cta_clicked" => 0, - "in_product_marketing_email_trial_0_sent" => 0, - "in_product_marketing_email_trial_0_cta_clicked" => 0, - "in_product_marketing_email_trial_1_sent" => 0, - "in_product_marketing_email_trial_1_cta_clicked" => 0, - "in_product_marketing_email_trial_2_sent" => 0, - "in_product_marketing_email_trial_2_cta_clicked" => 0, - "in_product_marketing_email_team_0_sent" => 0, - "in_product_marketing_email_team_0_cta_clicked" => 0, - "in_product_marketing_email_team_1_sent" => 0, - "in_product_marketing_email_team_1_cta_clicked" => 0, - "in_product_marketing_email_team_2_sent" => 0, - "in_product_marketing_email_team_2_cta_clicked" => 0 - } - - expect(subject).to eq(expected_data) - end - end - end - describe ".with_duration" do it 'records duration' do expect(::Gitlab::Usage::ServicePing::LegacyMetricTimingDecorator) -- cgit v1.2.3