diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 16:54:15 +0300 |
commit | be834a25982746ffd85252ff502df42bb88cb9d5 (patch) | |
tree | b4d6a8ba0931e12fac08f05abea33a3b8ec2c8a2 /spec/lib/gitlab/usage_data_spec.rb | |
parent | ee925a3597f27e92f83a50937a64068109675b3d (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc32
Diffstat (limited to 'spec/lib/gitlab/usage_data_spec.rb')
-rw-r--r-- | spec/lib/gitlab/usage_data_spec.rb | 84 |
1 files changed, 67 insertions, 17 deletions
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb index 6631a0d3cc6..984fd4c08e6 100644 --- a/spec/lib/gitlab/usage_data_spec.rb +++ b/spec/lib/gitlab/usage_data_spec.rb @@ -29,7 +29,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do user_minimum_id user_maximum_id unique_visit_service deployment_minimum_id deployment_maximum_id approval_merge_request_rule_minimum_id - approval_merge_request_rule_maximum_id) + approval_merge_request_rule_maximum_id + auth_providers) values.each do |key| expect(described_class).to receive(:clear_memoization).with(key) end @@ -167,6 +168,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do describe 'usage_activity_by_stage_manage' do it 'includes accurate usage_activity_by_stage data' do + described_class.clear_memoization(:auth_providers) + stub_config( omniauth: { providers: omniauth_providers } @@ -174,21 +177,29 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do for_defined_days_back do user = create(:user) + user2 = create(:user) create(:event, author: user) create(:group_member, user: user) + create(:authentication_event, user: user, provider: :ldapmain, result: :success) + create(:authentication_event, user: user2, provider: :ldapsecondary, result: :success) + create(:authentication_event, user: user2, provider: :group_saml, result: :success) + create(:authentication_event, user: user2, provider: :group_saml, result: :success) + create(:authentication_event, user: user, provider: :group_saml, result: :failed) end expect(described_class.usage_activity_by_stage_manage({})).to include( events: 2, groups: 2, - users_created: 4, - omniauth_providers: ['google_oauth2'] + users_created: 6, + omniauth_providers: ['google_oauth2'], + user_auth_by_provider: { 'group_saml' => 2, 'ldap' => 4 } ) expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include( events: 1, groups: 1, - users_created: 2, - omniauth_providers: ['google_oauth2'] + users_created: 3, + omniauth_providers: ['google_oauth2'], + user_auth_by_provider: { 'group_saml' => 1, 'ldap' => 2 } ) end @@ -244,6 +255,20 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ) end + it 'includes group imports usage data' do + for_defined_days_back do + user = create(:user) + group = create(:group) + group.add_owner(user) + create(:group_import_state, group: group, user: user) + end + + expect(described_class.usage_activity_by_stage_manage({})) + .to include(groups_imported: 2) + expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)) + .to include(groups_imported: 1) + end + def omniauth_providers [ OpenStruct.new(name: 'google_oauth2'), @@ -260,17 +285,20 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do cluster = create(:cluster, user: user) create(:project, creator: user) create(:clusters_applications_prometheus, :installed, cluster: cluster) + create(:project_tracing_setting) end expect(described_class.usage_activity_by_stage_monitor({})).to include( clusters: 2, clusters_applications_prometheus: 2, - operations_dashboard_default_dashboard: 2 + operations_dashboard_default_dashboard: 2, + projects_with_tracing_enabled: 2 ) expect(described_class.usage_activity_by_stage_monitor(described_class.last_28_days_time_period)).to include( clusters: 1, clusters_applications_prometheus: 1, - operations_dashboard_default_dashboard: 1 + operations_dashboard_default_dashboard: 1, + projects_with_tracing_enabled: 1 ) end end @@ -420,6 +448,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do expect(count_data[:projects_inheriting_instance_mattermost_active]).to eq(1) expect(count_data[:projects_with_repositories_enabled]).to eq(3) expect(count_data[:projects_with_error_tracking_enabled]).to eq(1) + expect(count_data[:projects_with_tracing_enabled]).to eq(1) expect(count_data[:projects_with_alerts_service_enabled]).to eq(1) expect(count_data[:projects_with_prometheus_alerts]).to eq(2) expect(count_data[:projects_with_terraform_reports]).to eq(2) @@ -472,8 +501,10 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do expect(count_data[:personal_snippets]).to eq(2) expect(count_data[:project_snippets]).to eq(4) + expect(count_data[:projects_creating_incidents]).to eq(2) expect(count_data[:projects_with_packages]).to eq(2) expect(count_data[:packages]).to eq(4) + expect(count_data[:user_preferences_user_gitpod_enabled]).to eq(1) end it 'gathers object store usage correctly' do @@ -628,6 +659,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do expect(subject[:gitlab_shared_runners_enabled]).to eq(Gitlab.config.gitlab_ci.shared_runners_enabled) expect(subject[:web_ide_clientside_preview_enabled]).to eq(Gitlab::CurrentSettings.web_ide_clientside_preview_enabled?) expect(subject[:grafana_link_enabled]).to eq(Gitlab::CurrentSettings.grafana_enabled?) + expect(subject[:gitpod_enabled]).to eq(Gitlab::CurrentSettings.gitpod_enabled?) end context 'with embedded Prometheus' do @@ -657,6 +689,20 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do expect(subject[:grafana_link_enabled]).to eq(false) end end + + context 'with Gitpod' do + it 'returns true when is enabled' do + stub_application_setting(gitpod_enabled: true) + + expect(subject[:gitpod_enabled]).to eq(true) + end + + it 'returns false when is disabled' do + stub_application_setting(gitpod_enabled: false) + + expect(subject[:gitpod_enabled]).to eq(false) + end + end end describe '.components_usage_data' do @@ -979,7 +1025,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do end end - def for_defined_days_back(days: [29, 2]) + def for_defined_days_back(days: [31, 3]) days.each do |n| Timecop.travel(n.days.ago) do yield @@ -1146,11 +1192,13 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do categories.each do |category| keys = ::Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category(category) + metrics = keys.map { |key| "#{key}_weekly" } + keys.map { |key| "#{key}_monthly" } + if ineligible_total_categories.exclude?(category) - keys.append("#{category}_total_unique_counts_weekly", "#{category}_total_unique_counts_monthly") + metrics.append("#{category}_total_unique_counts_weekly", "#{category}_total_unique_counts_monthly") end - expect(subject[:redis_hll_counters][category].keys).to match_array(keys) + expect(subject[:redis_hll_counters][category].keys).to match_array(metrics) end end end @@ -1169,6 +1217,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do end describe '.snowplow_event_counts' do + let_it_be(:time_period) { { collector_tstamp: 8.days.ago..1.day.ago } } + context 'when self-monitoring project exists' do let_it_be(:project) { create(:project) } @@ -1181,14 +1231,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do stub_feature_flags(product_analytics: project) create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote') - create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote', collector_tstamp: 28.days.ago) + create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote', collector_tstamp: 2.days.ago) + create(:product_analytics_event, project: project, se_category: 'epics', se_action: 'promote', collector_tstamp: 9.days.ago) + + create(:product_analytics_event, project: project, se_category: 'foo', se_action: 'bar', collector_tstamp: 2.days.ago) end it 'returns promoted_issues for the time period' do - expect(described_class.snowplow_event_counts[:promoted_issues]).to eq(2) - expect(described_class.snowplow_event_counts( - time_period: described_class.last_28_days_time_period(column: :collector_tstamp) - )[:promoted_issues]).to eq(1) + expect(described_class.snowplow_event_counts(time_period)[:promoted_issues]).to eq(1) end end @@ -1198,14 +1248,14 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do end it 'returns an empty hash' do - expect(described_class.snowplow_event_counts).to eq({}) + expect(described_class.snowplow_event_counts(time_period)).to eq({}) end end end context 'when self-monitoring project does not exist' do it 'returns an empty hash' do - expect(described_class.snowplow_event_counts).to eq({}) + expect(described_class.snowplow_event_counts(time_period)).to eq({}) end end end |