Commit 0fc4f029 authored by George Koltsov's avatar George Koltsov

Add project import usage pings

- Add usage pings for Project Imports of
  gitlab, gitea, bitbucket server and cloud, manifest
  git types
parent 2e5871f3
...@@ -545,6 +545,8 @@ class Project < ApplicationRecord ...@@ -545,6 +545,8 @@ class Project < ApplicationRecord
preload(:project_feature, :route, namespace: [:route, :owner]) preload(:project_feature, :route, namespace: [:route, :owner])
} }
scope :imported_from, -> (type) { where(import_type: type) }
enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 } enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 }
chronic_duration_attr :build_timeout_human_readable, :build_timeout, 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
...@@ -19839,6 +19839,8 @@ CREATE INDEX index_import_failures_on_project_id_and_correlation_id_value ON pub ...@@ -19839,6 +19839,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_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 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); CREATE INDEX index_insights_on_namespace_id ON public.insights USING btree (namespace_id);
......
...@@ -511,7 +511,17 @@ module Gitlab ...@@ -511,7 +511,17 @@ module Gitlab
events: distinct_count(::Event.where(time_period), :author_id), events: distinct_count(::Event.where(time_period), :author_id),
groups: distinct_count(::GroupMember.where(time_period), :user_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), 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 end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
...@@ -774,6 +784,10 @@ module Gitlab ...@@ -774,6 +784,10 @@ module Gitlab
def deployment_count(relation) def deployment_count(relation)
count relation, start: deployment_minimum_id, finish: deployment_maximum_id count relation, start: deployment_minimum_id, finish: deployment_maximum_id
end 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 end
end end
......
...@@ -194,6 +194,45 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -194,6 +194,45 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
) )
end 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 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