Commit 0b24f05d authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'georgekoltsov/add-importing-projects-usage-ping' into 'master'

Add project import usage pings

See merge request gitlab-org/gitlab!40130
parents 128b7689 0fc4f029
......@@ -545,6 +545,8 @@ class Project < ApplicationRecord
preload(:project_feature, :route, namespace: [:route, :owner])
}
scope :imported_from, -> (type) { where(import_type: type) }
enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 }
chronic_duration_attr :build_timeout_human_readable, :build_timeout,
......
---
title: Add usage pings for project import using various importers (GitLab, Bitbucket, Gitea, GitHub and more)
merge_request: 40130
author:
type: added
# frozen_string_literal: true
class AddProjectsIndexOnImportTypeCreatorIdCreatedAt < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
INDEX_NAME = 'index_imported_projects_on_import_type_creator_id_created_at'.freeze
disable_ddl_transaction!
def up
add_concurrent_index :projects,
[:import_type, :creator_id, :created_at],
where: 'import_type IS NOT NULL',
name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :projects, INDEX_NAME
end
end
35c37b8dcdca08d48086dc8164c2f6a69f563366ec9bce1f60299978a94de9bc
\ No newline at end of file
......@@ -19884,6 +19884,8 @@ CREATE INDEX index_import_failures_on_project_id_and_correlation_id_value ON pub
CREATE INDEX index_import_failures_on_project_id_not_null ON public.import_failures USING btree (project_id) WHERE (project_id IS NOT NULL);
CREATE INDEX index_imported_projects_on_import_type_creator_id_created_at ON public.projects USING btree (import_type, creator_id, created_at) WHERE (import_type IS NOT NULL);
CREATE UNIQUE INDEX index_index_statuses_on_project_id ON public.index_statuses USING btree (project_id);
CREATE INDEX index_insights_on_namespace_id ON public.insights USING btree (namespace_id);
......
......@@ -513,7 +513,17 @@ module Gitlab
events: distinct_count(::Event.where(time_period), :author_id),
groups: distinct_count(::GroupMember.where(time_period), :user_id),
users_created: count(::User.where(time_period), start: user_minimum_id, finish: user_maximum_id),
omniauth_providers: filtered_omniauth_provider_names.reject { |name| name == 'group_saml' }
omniauth_providers: filtered_omniauth_provider_names.reject { |name| name == 'group_saml' },
projects_imported: {
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)
}
}
end
# rubocop: enable CodeReuse/ActiveRecord
......@@ -788,6 +798,10 @@ module Gitlab
def deployment_count(relation)
count relation, start: deployment_minimum_id, finish: deployment_maximum_id
end
def projects_imported_count(from, time_period)
distinct_count(::Project.imported_from(from).where(time_period), :creator_id) # rubocop: disable CodeReuse/ActiveRecord
end
end
end
end
......
......@@ -194,6 +194,45 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
)
end
it 'includes project imports usage data' do
for_defined_days_back do
user = create(:user)
%w(gitlab_project gitlab github bitbucket bitbucket_server gitea git manifest).each do |type|
create(:project, import_type: type, creator_id: user.id)
end
end
expect(described_class.usage_activity_by_stage_manage({})).to include(
{
projects_imported: {
gitlab_project: 2,
gitlab: 2,
github: 2,
bitbucket: 2,
bitbucket_server: 2,
gitea: 2,
git: 2,
manifest: 2
}
}
)
expect(described_class.usage_activity_by_stage_manage(described_class.last_28_days_time_period)).to include(
{
projects_imported: {
gitlab_project: 1,
gitlab: 1,
github: 1,
bitbucket: 1,
bitbucket_server: 1,
gitea: 1,
git: 1,
manifest: 1
}
}
)
end
def omniauth_providers
[
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