Commit 560de38b authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Move package usage data to core

Move package data to core
as prep work for adding extra metrics.
parent d441a318
---
title: Move package usage ping data to core
merge_request: 40032
author:
type: changed
......@@ -174,7 +174,6 @@ module EE
merge_requests_with_required_codeowners: distinct_count(::ApprovalMergeRequestRule.code_owner_approval_required, :merge_request_id),
projects_mirrored_with_pipelines_enabled: count(::Project.mirrored_with_enabled_pipelines),
projects_reporting_ci_cd_back_to_github: count(::GithubService.active),
projects_with_packages: distinct_count(::Packages::Package, :project_id),
projects_with_tracing_enabled: count(ProjectTracingSetting),
status_page_projects: count(::StatusPage::ProjectSetting.enabled),
status_page_issues: count(::Issue.on_status_page, start: issue_minimum_id, finish: issue_maximum_id),
......@@ -266,13 +265,6 @@ module EE
})
end
override :usage_activity_by_stage_package
def usage_activity_by_stage_package(time_period)
super.merge({
projects_with_packages: distinct_count(::Project.with_packages.where(time_period), :creator_id)
})
end
# Omitted because no user, creator or author associated: `boards`, `labels`, `milestones`, `uploads`
# Omitted because too expensive: `epics_deepest_relationship_level`
# Omitted because of encrypted properties: `projects_jira_cloud_active`, `projects_jira_server_active`
......
......@@ -36,10 +36,6 @@ RSpec.describe Gitlab::UsageData do
create(:service, project: projects[1], type: 'JenkinsService', active: true)
create(:jira_service, project: projects[0], issues_enabled: true, project_key: 'GL')
create(:package, project: projects[0])
create(:package, project: projects[0])
create(:package, project: projects[1])
create(:project_tracing_setting, project: projects[0])
create(:operations_feature_flag, project: projects[0])
......@@ -111,7 +107,6 @@ RSpec.describe Gitlab::UsageData do
projects_jira_issuelist_active
projects_mirrored_with_pipelines_enabled
projects_reporting_ci_cd_back_to_github
projects_with_packages
projects_with_prometheus_alerts
projects_with_tracing_enabled
sast_jobs
......@@ -129,7 +124,6 @@ RSpec.describe Gitlab::UsageData do
expect(count_data[:projects_jenkins_active]).to eq(1)
expect(count_data[:projects_with_prometheus_alerts]).to eq(2)
expect(count_data[:projects_with_packages]).to eq(2)
expect(count_data[:feature_flags]).to eq(1)
expect(count_data[:status_page_projects]).to eq(1)
expect(count_data[:status_page_issues]).to eq(1)
......@@ -423,21 +417,6 @@ RSpec.describe Gitlab::UsageData do
end
end
describe 'usage_activity_by_stage_package' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:project, packages: [create(:package)] )
end
expect(described_class.usage_activity_by_stage_package({})).to eq(
projects_with_packages: 2
)
expect(described_class.usage_activity_by_stage_package(described_class.last_28_days_time_period)).to eq(
projects_with_packages: 1
)
end
end
describe 'usage_activity_by_stage_plan' do
it 'includes accurate usage_activity_by_stage data' do
stub_licensed_features(board_assignee_lists: true, board_milestone_lists: true)
......
......@@ -129,6 +129,7 @@ module Gitlab
lfs_objects: count(LfsObject),
milestone_lists: count(List.milestone),
milestones: count(Milestone),
projects_with_packages: distinct_count(::Packages::Package, :project_id),
pages_domains: count(PagesDomain),
pool_repositories: count(PoolRepository),
projects: count(Project),
......@@ -527,9 +528,13 @@ module Gitlab
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_package(time_period)
{}
{
projects_with_packages: distinct_count(::Project.with_packages.where(time_period), :creator_id)
}
end
# rubocop: enable CodeReuse/ActiveRecord
# Omitted because no user, creator or author associated: `boards`, `labels`, `milestones`, `uploads`
# Omitted because too expensive: `epics_deepest_relationship_level`
......
......@@ -94,6 +94,10 @@ FactoryBot.define do
create(:grafana_integration, project: projects[1], enabled: true)
create(:grafana_integration, project: projects[2], enabled: false)
create(:package, project: projects[0])
create(:package, project: projects[0])
create(:package, project: projects[1])
ProjectFeature.first.update_attribute('repository_access_level', 0)
# Create fresh & a month (28-days SMAU) old data
......
......@@ -56,6 +56,21 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
end
end
describe 'usage_activity_by_stage_package' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
create(:project, packages: [create(:package)] )
end
expect(described_class.usage_activity_by_stage_package({})).to eq(
projects_with_packages: 2
)
expect(described_class.usage_activity_by_stage_package(described_class.last_28_days_time_period)).to eq(
projects_with_packages: 1
)
end
end
describe '.usage_activity_by_stage_configure' do
it 'includes accurate usage_activity_by_stage data' do
for_defined_days_back do
......@@ -399,6 +414,8 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
expect(count_data[:snippets]).to eq(6)
expect(count_data[:personal_snippets]).to eq(2)
expect(count_data[:project_snippets]).to eq(4)
expect(count_data[:projects_with_packages]).to eq(2)
end
it 'gathers object store usage correctly' 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