Commit 1d47a49c authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'kassio/manage-import-metrics' into 'master'

Change Manage Import metrics to total of imports instead of unique users

See merge request gitlab-org/gitlab!51495
parents f192d901 a2343307
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
# redis_usage_data { ::Gitlab::UsageCounters::PodLogs.usage_totals[:total] } # redis_usage_data { ::Gitlab::UsageCounters::PodLogs.usage_totals[:total] }
module Gitlab module Gitlab
class UsageData class UsageData
DEPRECATED_VALUE = -1000
CE_MEMOIZED_VALUES = %i( CE_MEMOIZED_VALUES = %i(
issue_minimum_id issue_minimum_id
issue_maximum_id issue_maximum_id
...@@ -584,26 +586,33 @@ module Gitlab ...@@ -584,26 +586,33 @@ module Gitlab
user_auth_by_provider: distinct_count_user_auth_by_provider(time_period), user_auth_by_provider: distinct_count_user_auth_by_provider(time_period),
unique_users_all_imports: unique_users_all_imports(time_period), unique_users_all_imports: unique_users_all_imports(time_period),
bulk_imports: { bulk_imports: {
gitlab: distinct_count(::BulkImport.where(time_period, source_type: :gitlab), :user_id) gitlab: DEPRECATED_VALUE,
gitlab_v1: count(::BulkImport.where(time_period, source_type: :gitlab))
}, },
project_imports: project_imports(time_period),
issue_imports: issue_imports(time_period),
group_imports: group_imports(time_period),
# Deprecated data to be removed
projects_imported: { projects_imported: {
total: distinct_count(::Project.where(time_period).where.not(import_type: nil), :creator_id), total: DEPRECATED_VALUE,
gitlab_project: projects_imported_count('gitlab_project', time_period), gitlab_project: DEPRECATED_VALUE,
gitlab: projects_imported_count('gitlab', time_period), gitlab: DEPRECATED_VALUE,
github: projects_imported_count('github', time_period), github: DEPRECATED_VALUE,
bitbucket: projects_imported_count('bitbucket', time_period), bitbucket: DEPRECATED_VALUE,
bitbucket_server: projects_imported_count('bitbucket_server', time_period), bitbucket_server: DEPRECATED_VALUE,
gitea: projects_imported_count('gitea', time_period), gitea: DEPRECATED_VALUE,
git: projects_imported_count('git', time_period), git: DEPRECATED_VALUE,
manifest: projects_imported_count('manifest', time_period) manifest: DEPRECATED_VALUE
}, },
issues_imported: { issues_imported: {
jira: distinct_count(::JiraImportState.where(time_period), :user_id), jira: DEPRECATED_VALUE,
fogbugz: projects_imported_count('fogbugz', time_period), fogbugz: DEPRECATED_VALUE,
phabricator: projects_imported_count('phabricator', time_period), phabricator: DEPRECATED_VALUE,
csv: distinct_count(Issues::CsvImport.where(time_period), :user_id) csv: DEPRECATED_VALUE
}, },
groups_imported: distinct_count(::GroupImportState.where(time_period), :user_id) groups_imported: DEPRECATED_VALUE
# End of deprecated keys
} }
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -900,8 +909,38 @@ module Gitlab ...@@ -900,8 +909,38 @@ module Gitlab
count relation, start: deployment_minimum_id, finish: deployment_maximum_id count relation, start: deployment_minimum_id, finish: deployment_maximum_id
end end
def project_imports(time_period)
{
gitlab_project: projects_imported_count('gitlab_project', time_period),
gitlab: projects_imported_count('gitlab', time_period),
github: projects_imported_count('github', time_period),
bitbucket: projects_imported_count('bitbucket', time_period),
bitbucket_server: projects_imported_count('bitbucket_server', time_period),
gitea: projects_imported_count('gitea', time_period),
git: projects_imported_count('git', time_period),
manifest: projects_imported_count('manifest', time_period),
gitlab_migration: count(::BulkImports::Entity.where(time_period).project_entity) # rubocop: disable CodeReuse/ActiveRecord
}
end
def projects_imported_count(from, time_period) def projects_imported_count(from, time_period)
distinct_count(::Project.imported_from(from).where(time_period).where.not(import_type: nil), :creator_id) # rubocop: disable CodeReuse/ActiveRecord count(::Project.imported_from(from).where(time_period).where.not(import_type: nil)) # rubocop: disable CodeReuse/ActiveRecord
end
def issue_imports(time_period)
{
jira: count(::JiraImportState.where(time_period)), # rubocop: disable CodeReuse/ActiveRecord
fogbugz: projects_imported_count('fogbugz', time_period),
phabricator: projects_imported_count('phabricator', time_period),
csv: count(Issues::CsvImport.where(time_period)) # rubocop: disable CodeReuse/ActiveRecord
}
end
def group_imports(time_period)
{
group_import: count(::GroupImportState.where(time_period)), # rubocop: disable CodeReuse/ActiveRecord
gitlab_migration: count(::BulkImports::Entity.where(time_period).group_entity) # rubocop: disable CodeReuse/ActiveRecord
}
end end
# rubocop:disable CodeReuse/ActiveRecord # rubocop:disable CodeReuse/ActiveRecord
......
...@@ -255,8 +255,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -255,8 +255,6 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
create(:bulk_import, user: user)
%w(gitlab_project gitlab github bitbucket bitbucket_server gitea git manifest fogbugz phabricator).each do |type| %w(gitlab_project gitlab github bitbucket bitbucket_server gitea git manifest fogbugz phabricator).each do |type|
create(:project, import_type: type, creator_id: user.id) create(:project, import_type: type, creator_id: user.id)
end end
...@@ -265,72 +263,113 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -265,72 +263,113 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
create(:jira_import_state, :finished, project: jira_project) create(:jira_import_state, :finished, project: jira_project)
create(:issue_csv_import, user: user) create(:issue_csv_import, user: user)
group = create(:group)
group.add_owner(user)
create(:group_import_state, group: group, user: user)
bulk_import = create(:bulk_import, user: user)
create(:bulk_import_entity, :group_entity, bulk_import: bulk_import)
create(:bulk_import_entity, :project_entity, bulk_import: bulk_import)
end end
expect(described_class.usage_activity_by_stage_manage({})).to include( expect(described_class.usage_activity_by_stage_manage({})).to include(
{ {
bulk_imports: { bulk_imports: {
gitlab: 2 gitlab_v1: 2,
gitlab: Gitlab::UsageData::DEPRECATED_VALUE
}, },
projects_imported: { project_imports: {
total: 2,
gitlab_project: 2,
gitlab: 2,
github: 2,
bitbucket: 2, bitbucket: 2,
bitbucket_server: 2, bitbucket_server: 2,
gitea: 2,
git: 2, git: 2,
gitea: 2,
github: 2,
gitlab: 2,
gitlab_migration: 2,
gitlab_project: 2,
manifest: 2 manifest: 2
}, },
issues_imported: { issue_imports: {
jira: 2, jira: 2,
fogbugz: 2, fogbugz: 2,
phabricator: 2, phabricator: 2,
csv: 2 csv: 2
} },
group_imports: {
group_import: 2,
gitlab_migration: 2
},
projects_imported: {
total: Gitlab::UsageData::DEPRECATED_VALUE,
gitlab_project: Gitlab::UsageData::DEPRECATED_VALUE,
gitlab: Gitlab::UsageData::DEPRECATED_VALUE,
github: Gitlab::UsageData::DEPRECATED_VALUE,
bitbucket: Gitlab::UsageData::DEPRECATED_VALUE,
bitbucket_server: Gitlab::UsageData::DEPRECATED_VALUE,
gitea: Gitlab::UsageData::DEPRECATED_VALUE,
git: Gitlab::UsageData::DEPRECATED_VALUE,
manifest: Gitlab::UsageData::DEPRECATED_VALUE
},
issues_imported: {
jira: Gitlab::UsageData::DEPRECATED_VALUE,
fogbugz: Gitlab::UsageData::DEPRECATED_VALUE,
phabricator: Gitlab::UsageData::DEPRECATED_VALUE,
csv: Gitlab::UsageData::DEPRECATED_VALUE
},
groups_imported: Gitlab::UsageData::DEPRECATED_VALUE
} }
) )
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include( expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
{ {
bulk_imports: { bulk_imports: {
gitlab: 1 gitlab_v1: 1,
gitlab: Gitlab::UsageData::DEPRECATED_VALUE
}, },
projects_imported: { project_imports: {
total: 1,
gitlab_project: 1,
gitlab: 1,
github: 1,
bitbucket: 1, bitbucket: 1,
bitbucket_server: 1, bitbucket_server: 1,
gitea: 1,
git: 1, git: 1,
gitea: 1,
github: 1,
gitlab: 1,
gitlab_migration: 1,
gitlab_project: 1,
manifest: 1 manifest: 1
}, },
issues_imported: { issue_imports: {
jira: 1, jira: 1,
fogbugz: 1, fogbugz: 1,
phabricator: 1, phabricator: 1,
csv: 1 csv: 1
} },
group_imports: {
group_import: 1,
gitlab_migration: 1
},
projects_imported: {
total: Gitlab::UsageData::DEPRECATED_VALUE,
gitlab_project: Gitlab::UsageData::DEPRECATED_VALUE,
gitlab: Gitlab::UsageData::DEPRECATED_VALUE,
github: Gitlab::UsageData::DEPRECATED_VALUE,
bitbucket: Gitlab::UsageData::DEPRECATED_VALUE,
bitbucket_server: Gitlab::UsageData::DEPRECATED_VALUE,
gitea: Gitlab::UsageData::DEPRECATED_VALUE,
git: Gitlab::UsageData::DEPRECATED_VALUE,
manifest: Gitlab::UsageData::DEPRECATED_VALUE
},
issues_imported: {
jira: Gitlab::UsageData::DEPRECATED_VALUE,
fogbugz: Gitlab::UsageData::DEPRECATED_VALUE,
phabricator: Gitlab::UsageData::DEPRECATED_VALUE,
csv: Gitlab::UsageData::DEPRECATED_VALUE
},
groups_imported: Gitlab::UsageData::DEPRECATED_VALUE
} }
) )
end 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 def omniauth_providers
[ [
OpenStruct.new(name: 'google_oauth2'), OpenStruct.new(name: 'google_oauth2'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment