Commit 03994ffb authored by Alper Akgun's avatar Alper Akgun

Move create stage usage activity to CE

Also updates the usage ping documentation
parent 87d6abca
---
title: Move create stage usage activity to CE
merge_request: 36086
author:
type: changed
...@@ -647,7 +647,21 @@ appear to be associated to any of the services running, since they all appear to ...@@ -647,7 +647,21 @@ appear to be associated to any of the services running, since they all appear to
| `projects_slack_notifications_active` | `usage_activity_by_stage` | `configure` | | EE | Unique projects with Slack service enabled | | `projects_slack_notifications_active` | `usage_activity_by_stage` | `configure` | | EE | Unique projects with Slack service enabled |
| `projects_slack_slash_active` | `usage_activity_by_stage` | `configure` | | EE | Unique projects with Slack '/' commands enabled | | `projects_slack_slash_active` | `usage_activity_by_stage` | `configure` | | EE | Unique projects with Slack '/' commands enabled |
| `projects_with_prometheus_alerts` | `usage_activity_by_stage` | `configure` | | EE | Projects with Prometheus enabled and no alerts | | `projects_with_prometheus_alerts` | `usage_activity_by_stage` | `configure` | | EE | Projects with Prometheus enabled and no alerts |
| `deploy_keys` | `usage_activity_by_stage` | `create` | | | | | `deploy_keys` | `usage_activity_by_stage` | `create` | | CE+EE | |
| `keys` | `usage_activity_by_stage` | `create` | | CE+EE | |
| `merge_requests` | `usage_activity_by_stage` | `create` | | CE+EE | |
| `projects_with_disable_overriding_approvers_per_merge_request` | `usage_activity_by_stage` | `create` | | CE+EE | |
| `projects_without_disable_overriding_approvers_per_merge_request` | `usage_activity_by_stage` | `create` | | CE+EE | |
| `remote_mirrors` | `usage_activity_by_stage` | `create` | | CE+EE | |
| `snippets` | `usage_activity_by_stage` | `create` | | CE+EE | |
| `merge_requests_users` | `usage_activity_by_stage_monthly` | `create` | | CE+EE | Unique count of users who used a merge request |
| `projects_enforcing_code_owner_approval` | `usage_activity_by_stage` | `create` | | EE | |
| `merge_requests_with_optional_codeowners` | `usage_activity_by_stage` | `create` | | EE | |
| `merge_requests_with_required_codeowners` | `usage_activity_by_stage` | `create` | | EE | |
| `projects_imported_from_github` | `usage_activity_by_stage` | `create` | | EE | |
| `projects_with_repositories_enabled` | `usage_activity_by_stage` | `create` | | EE | |
| `protected_branches` | `usage_activity_by_stage` | `create` | | EE | |
| `suggestions` | `usage_activity_by_stage` | `create` | | EE | |
| `clusters` | `usage_activity_by_stage` | `monitor` | | CE+EE | | | `clusters` | `usage_activity_by_stage` | `monitor` | | CE+EE | |
| `clusters_applications_prometheus` | `usage_activity_by_stage` | `monitor` | | CE+EE | | | `clusters_applications_prometheus` | `usage_activity_by_stage` | `monitor` | | CE+EE | |
| `operations_dashboard_default_dashboard` | `usage_activity_by_stage` | `monitor` | | CE+EE | | | `operations_dashboard_default_dashboard` | `usage_activity_by_stage` | `monitor` | | CE+EE | |
...@@ -667,7 +681,6 @@ appear to be associated to any of the services running, since they all appear to ...@@ -667,7 +681,6 @@ appear to be associated to any of the services running, since they all appear to
| `ldap_group_sync_enabled` | `usage_activity_by_stage` | `manage` | | EE | | | `ldap_group_sync_enabled` | `usage_activity_by_stage` | `manage` | | EE | |
| `ldap_admin_sync_enabled` | `usage_activity_by_stage` | `manage` | | EE | | | `ldap_admin_sync_enabled` | `usage_activity_by_stage` | `manage` | | EE | |
| `group_saml_enabled` | `usage_activity_by_stage` | `manage` | | EE | | | `group_saml_enabled` | `usage_activity_by_stage` | `manage` | | EE | |
| `keys` | `usage_activity_by_stage` | `create` | | | |
| `projects_jira_dvcs_server_active` | `usage_activity_by_stage` | `plan` | | | | | `projects_jira_dvcs_server_active` | `usage_activity_by_stage` | `plan` | | | |
| `service_desk_enabled_projects` | `usage_activity_by_stage` | `plan` | | | | | `service_desk_enabled_projects` | `usage_activity_by_stage` | `plan` | | | |
| `service_desk_issues` | `usage_activity_by_stage` | `plan` | | | | | `service_desk_issues` | `usage_activity_by_stage` | `plan` | | | |
......
...@@ -210,22 +210,15 @@ module EE ...@@ -210,22 +210,15 @@ module EE
override :usage_activity_by_stage_create override :usage_activity_by_stage_create
def usage_activity_by_stage_create(time_period) def usage_activity_by_stage_create(time_period)
super.merge({ super.merge({
deploy_keys: distinct_count(::DeployKey.where(time_period), :user_id),
keys: distinct_count(::Key.regular_keys.where(time_period), :user_id),
merge_requests: distinct_count(::MergeRequest.where(time_period), :author_id),
projects_enforcing_code_owner_approval: distinct_count(::Project.requiring_code_owner_approval.where(time_period), :creator_id), projects_enforcing_code_owner_approval: distinct_count(::Project.requiring_code_owner_approval.where(time_period), :creator_id),
merge_requests_with_optional_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_optional.where(time_period), :merge_request_id), merge_requests_with_optional_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_optional.where(time_period), :merge_request_id),
merge_requests_with_required_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_required.where(time_period), :merge_request_id), merge_requests_with_required_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_required.where(time_period), :merge_request_id),
projects_with_disable_overriding_approvers_per_merge_request: count(::Project.where(time_period.merge(disable_overriding_approvers_per_merge_request: true))),
projects_without_disable_overriding_approvers_per_merge_request: count(::Project.where(time_period.merge(disable_overriding_approvers_per_merge_request: [false, nil]))),
projects_imported_from_github: distinct_count(::Project.github_imported.where(time_period), :creator_id), projects_imported_from_github: distinct_count(::Project.github_imported.where(time_period), :creator_id),
projects_with_repositories_enabled: distinct_count(::Project.with_repositories_enabled.where(time_period), projects_with_repositories_enabled: distinct_count(::Project.with_repositories_enabled.where(time_period),
:creator_id, :creator_id,
start: user_minimum_id, start: user_minimum_id,
finish: user_maximum_id), finish: user_maximum_id),
protected_branches: distinct_count(::Project.with_protected_branches.where(time_period), :creator_id, start: user_minimum_id, finish: user_maximum_id), protected_branches: distinct_count(::Project.with_protected_branches.where(time_period), :creator_id, start: user_minimum_id, finish: user_maximum_id),
remote_mirrors: distinct_count(::Project.with_remote_mirrors.where(time_period), :creator_id),
snippets: distinct_count(::Snippet.where(time_period), :author_id),
suggestions: distinct_count(::Note.with_suggestions.where(time_period), suggestions: distinct_count(::Note.with_suggestions.where(time_period),
:author_id, :author_id,
start: user_minimum_id, start: user_minimum_id,
......
...@@ -307,16 +307,12 @@ RSpec.describe Gitlab::UsageData do ...@@ -307,16 +307,12 @@ RSpec.describe Gitlab::UsageData do
for_defined_days_back do for_defined_days_back do
user = create(:user) user = create(:user)
project = create(:project, :repository_private, :github_imported, project = create(:project, :repository_private, :github_imported,
:test_repo, :remote_mirror, creator: user) :test_repo, creator: user)
merge_request = create(:merge_request, source_project: project) merge_request = create(:merge_request, source_project: project)
create(:deploy_key, user: user)
create(:key, user: user)
create(:project, creator: user) create(:project, creator: user)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: true) create(:project, creator: user, disable_overriding_approvers_per_merge_request: true)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: false) create(:project, creator: user, disable_overriding_approvers_per_merge_request: false)
create(:protected_branch, project: project) create(:protected_branch, project: project)
create(:remote_mirror, project: project)
create(:snippet, author: user)
create(:suggestion, note: create(:note, project: project)) create(:suggestion, note: create(:note, project: project))
create(:code_owner_rule, merge_request: merge_request, approvals_required: 3) create(:code_owner_rule, merge_request: merge_request, approvals_required: 3)
create(:code_owner_rule, merge_request: merge_request, approvals_required: 7) create(:code_owner_rule, merge_request: merge_request, approvals_required: 7)
...@@ -324,37 +320,22 @@ RSpec.describe Gitlab::UsageData do ...@@ -324,37 +320,22 @@ RSpec.describe Gitlab::UsageData do
create_list(:code_owner_rule, 2) create_list(:code_owner_rule, 2)
end end
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to eq( expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to include(
deploy_keys: 2,
keys: 2,
merge_requests: 12,
projects_enforcing_code_owner_approval: 0, projects_enforcing_code_owner_approval: 0,
merge_requests_with_optional_codeowners: 4, merge_requests_with_optional_codeowners: 4,
merge_requests_with_required_codeowners: 8, merge_requests_with_required_codeowners: 8,
projects_with_disable_overriding_approvers_per_merge_request: 2,
projects_without_disable_overriding_approvers_per_merge_request: 16,
projects_imported_from_github: 2, projects_imported_from_github: 2,
projects_with_repositories_enabled: 12, projects_with_repositories_enabled: 12,
protected_branches: 2, protected_branches: 2,
remote_mirrors: 2,
snippets: 2,
suggestions: 2 suggestions: 2
) )
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to eq( expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to include(
deploy_keys: 1,
keys: 1,
merge_requests: 6,
projects_enforcing_code_owner_approval: 0, projects_enforcing_code_owner_approval: 0,
merge_requests_users: 0,
merge_requests_with_optional_codeowners: 2, merge_requests_with_optional_codeowners: 2,
merge_requests_with_required_codeowners: 4, merge_requests_with_required_codeowners: 4,
projects_with_disable_overriding_approvers_per_merge_request: 1,
projects_without_disable_overriding_approvers_per_merge_request: 8,
projects_imported_from_github: 1, projects_imported_from_github: 1,
projects_with_repositories_enabled: 6, projects_with_repositories_enabled: 6,
protected_branches: 1, protected_branches: 1,
remote_mirrors: 1,
snippets: 1,
suggestions: 1 suggestions: 1
) )
end end
......
...@@ -478,11 +478,21 @@ module Gitlab ...@@ -478,11 +478,21 @@ module Gitlab
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_create(time_period) def usage_activity_by_stage_create(time_period)
{}.tap do |h| {
deploy_keys: distinct_count(::DeployKey.where(time_period), :user_id),
keys: distinct_count(::Key.regular_keys.where(time_period), :user_id),
merge_requests: distinct_count(::MergeRequest.where(time_period), :author_id),
projects_with_disable_overriding_approvers_per_merge_request: count(::Project.where(time_period.merge(disable_overriding_approvers_per_merge_request: true))),
projects_without_disable_overriding_approvers_per_merge_request: count(::Project.where(time_period.merge(disable_overriding_approvers_per_merge_request: [false, nil]))),
remote_mirrors: distinct_count(::Project.with_remote_mirrors.where(time_period), :creator_id),
snippets: distinct_count(::Snippet.where(time_period), :author_id)
}.tap do |h|
h[:merge_requests_users] = merge_requests_users(time_period) if time_period.present? h[:merge_requests_users] = merge_requests_users(time_period) if time_period.present?
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links` # Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links`
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
......
...@@ -174,6 +174,40 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do ...@@ -174,6 +174,40 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
:merge_requests_users :merge_requests_users
) )
end end
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
user = create(:user)
project = create(:project, :repository_private,
:test_repo, :remote_mirror, creator: user)
create(:merge_request, source_project: project)
create(:deploy_key, user: user)
create(:key, user: user)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: true)
create(:project, creator: user, disable_overriding_approvers_per_merge_request: false)
create(:remote_mirror, project: project)
create(:snippet, author: user)
end
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to include(
deploy_keys: 2,
keys: 2,
merge_requests: 2,
projects_with_disable_overriding_approvers_per_merge_request: 2,
projects_without_disable_overriding_approvers_per_merge_request: 4,
remote_mirrors: 2,
snippets: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to include(
deploy_keys: 1,
keys: 1,
merge_requests: 1,
projects_with_disable_overriding_approvers_per_merge_request: 1,
projects_without_disable_overriding_approvers_per_merge_request: 2,
remote_mirrors: 1,
snippets: 1
)
end
end end
context 'for monitor' do context 'for monitor' do
......
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