Commit be5c1838 authored by Alper Akgun's avatar Alper Akgun Committed by Mayra Cabrera

Usage activity by stage for past month

Adds a version of usage activity by stage by time period in usage data
by created_at date time
parent 9d990969
---
title: Time period for usage activity by stage in usage data
merge_request: 24431
author:
type: added
......@@ -22,7 +22,13 @@ module EE
return super if (::Feature.disabled?(:usage_ping_batch_counter) && ::Gitlab.com?) ||
::Feature.disabled?(:usage_activity_by_stage, default_enabled: true)
super.merge(usage_activity_by_stage)
if ::Feature.disabled?(:usage_activity_by_stage_monthly)
super.merge(usage_activity_by_stage)
else
time_period = { created_at: 28.days.ago..Time.current }
usage_activity_by_stage_monthly = usage_activity_by_stage(:usage_activity_by_stage_monthly, time_period)
super.merge(usage_activity_by_stage).merge(usage_activity_by_stage_monthly)
end
end
override :features_usage_data
......@@ -168,143 +174,144 @@ module EE
end
# Source: https://gitlab.com/gitlab-data/analytics/blob/master/transform/snowflake-dbt/data/ping_metrics_to_stage_mapping_data.csv
def usage_activity_by_stage
def usage_activity_by_stage(key = :usage_activity_by_stage, time_period = {})
{
usage_activity_by_stage: {
configure: usage_activity_by_stage_configure,
create: usage_activity_by_stage_create,
manage: usage_activity_by_stage_manage,
monitor: usage_activity_by_stage_monitor,
package: usage_activity_by_stage_package,
plan: usage_activity_by_stage_plan,
release: usage_activity_by_stage_release,
secure: usage_activity_by_stage_secure,
verify: usage_activity_by_stage_verify
key => {
configure: usage_activity_by_stage_configure(time_period),
create: usage_activity_by_stage_create(time_period),
manage: usage_activity_by_stage_manage(time_period),
monitor: usage_activity_by_stage_monitor(time_period),
package: usage_activity_by_stage_package(time_period),
plan: usage_activity_by_stage_plan(time_period),
release: usage_activity_by_stage_release(time_period),
secure: usage_activity_by_stage_secure(time_period),
verify: usage_activity_by_stage_verify(time_period)
}
}
end
# Omitted because no user, creator or author associated: `auto_devops_disabled`, `auto_devops_enabled`
# Omitted because not in use anymore: `gcp_clusters`, `gcp_clusters_disabled`, `gcp_clusters_enabled`
def usage_activity_by_stage_configure
# rubocop: disable CodeReuse/ActiveRecord
def usage_activity_by_stage_configure(time_period)
{
clusters_applications_cert_managers: ::Clusters::Applications::CertManager.distinct_by_user,
clusters_applications_helm: ::Clusters::Applications::Helm.distinct_by_user,
clusters_applications_ingress: ::Clusters::Applications::Ingress.distinct_by_user,
clusters_applications_knative: ::Clusters::Applications::Knative.distinct_by_user,
clusters_disabled: distinct_count(::Clusters::Cluster.disabled, :user_id),
clusters_enabled: distinct_count(::Clusters::Cluster.enabled, :user_id),
clusters_platforms_gke: distinct_count(::Clusters::Cluster.gcp_installed.enabled, :user_id),
clusters_platforms_eks: distinct_count(::Clusters::Cluster.aws_installed.enabled, :user_id),
clusters_platforms_user: distinct_count(::Clusters::Cluster.user_provided.enabled, :user_id),
group_clusters_disabled: distinct_count(::Clusters::Cluster.disabled.group_type, :user_id),
group_clusters_enabled: distinct_count(::Clusters::Cluster.enabled.group_type, :user_id),
project_clusters_disabled: distinct_count(::Clusters::Cluster.disabled.project_type, :user_id),
project_clusters_enabled: distinct_count(::Clusters::Cluster.enabled.project_type, :user_id),
projects_slack_notifications_active: distinct_count(::Project.with_slack_service, :creator_id),
projects_slack_slash_active: distinct_count(::Project.with_slack_slash_commands_service, :creator_id),
projects_with_prometheus_alerts: distinct_count(::Project.with_prometheus_service, :creator_id)
clusters_applications_cert_managers: ::Clusters::Applications::CertManager.where(time_period).distinct_by_user,
clusters_applications_helm: ::Clusters::Applications::Helm.where(time_period).distinct_by_user,
clusters_applications_ingress: ::Clusters::Applications::Ingress.where(time_period).distinct_by_user,
clusters_applications_knative: ::Clusters::Applications::Knative.where(time_period).distinct_by_user,
clusters_disabled: distinct_count(::Clusters::Cluster.disabled.where(time_period), :user_id),
clusters_enabled: distinct_count(::Clusters::Cluster.enabled.where(time_period), :user_id),
clusters_platforms_gke: distinct_count(::Clusters::Cluster.gcp_installed.enabled.where(time_period), :user_id),
clusters_platforms_eks: distinct_count(::Clusters::Cluster.aws_installed.enabled.where(time_period), :user_id),
clusters_platforms_user: distinct_count(::Clusters::Cluster.user_provided.enabled.where(time_period), :user_id),
group_clusters_disabled: distinct_count(::Clusters::Cluster.disabled.group_type.where(time_period), :user_id),
group_clusters_enabled: distinct_count(::Clusters::Cluster.enabled.group_type.where(time_period), :user_id),
project_clusters_disabled: distinct_count(::Clusters::Cluster.disabled.project_type.where(time_period), :user_id),
project_clusters_enabled: distinct_count(::Clusters::Cluster.enabled.project_type.where(time_period), :user_id),
projects_slack_notifications_active: distinct_count(::Project.with_slack_service.where(time_period), :creator_id),
projects_slack_slash_active: distinct_count(::Project.with_slack_slash_commands_service.where(time_period), :creator_id),
projects_with_prometheus_alerts: distinct_count(::Project.with_prometheus_service.where(time_period), :creator_id)
}
end
# Omitted because no user, creator or author associated: `lfs_objects`, `pool_repositories`, `web_hooks`
def usage_activity_by_stage_create
def usage_activity_by_stage_create(time_period)
{
deploy_keys: distinct_count(::DeployKey, :user_id),
keys: distinct_count(::Key.regular_keys, :user_id),
merge_requests: distinct_count(::MergeRequest, :author_id),
projects_enforcing_code_owner_approval: distinct_count(::Project.requiring_code_owner_approval, :creator_id),
projects_imported_from_github: distinct_count(::Project.github_imported, :creator_id),
projects_with_repositories_enabled: distinct_count(::Project.with_repositories_enabled, :creator_id),
protected_branches: distinct_count(::Project.with_protected_branches, :creator_id),
remote_mirrors: distinct_count(::Project.with_remote_mirrors, :creator_id),
snippets: distinct_count(::Snippet, :author_id),
suggestions: distinct_count(::Note.with_suggestions, :author_id)
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_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), :creator_id),
protected_branches: distinct_count(::Project.with_protected_branches.where(time_period), :creator_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), :author_id)
}
end
# Omitted because no user, creator or author associated: `campaigns_imported_from_github`, `ldap_group_links`
def usage_activity_by_stage_manage
def usage_activity_by_stage_manage(time_period)
{
events: distinct_count(::Event, :author_id),
groups: distinct_count(::GroupMember, :user_id),
ldap_keys: distinct_count(::LDAPKey, :user_id),
ldap_users: distinct_count(::GroupMember.of_ldap_type, :user_id)
events: distinct_count(::Event.where(time_period), :author_id),
groups: distinct_count(::GroupMember.where(time_period), :user_id),
ldap_keys: distinct_count(::LDAPKey.where(time_period), :user_id),
ldap_users: distinct_count(::GroupMember.of_ldap_type.where(time_period), :user_id)
}
end
def usage_activity_by_stage_monitor
def usage_activity_by_stage_monitor(time_period)
{
clusters: distinct_count(::Clusters::Cluster, :user_id),
clusters_applications_prometheus: ::Clusters::Applications::Prometheus.distinct_by_user,
operations_dashboard_default_dashboard: count(::User.active.with_dashboard('operations')),
operations_dashboard_users_with_projects_added: count(UsersOpsDashboardProject.distinct_users(::User.active), batch: false),
projects_prometheus_active: distinct_count(::Project.with_active_prometheus_service, :creator_id),
projects_with_error_tracking_enabled: distinct_count(::Project.with_enabled_error_tracking, :creator_id),
projects_with_tracing_enabled: distinct_count(::Project.with_tracing_enabled, :creator_id)
clusters: distinct_count(::Clusters::Cluster.where(time_period), :user_id),
clusters_applications_prometheus: ::Clusters::Applications::Prometheus.where(time_period).distinct_by_user,
operations_dashboard_default_dashboard: count(::User.active.with_dashboard('operations').where(time_period)),
operations_dashboard_users_with_projects_added: count(UsersOpsDashboardProject.distinct_users(::User.active).where(time_period), batch: false),
projects_prometheus_active: distinct_count(::Project.with_active_prometheus_service.where(time_period), :creator_id),
projects_with_error_tracking_enabled: distinct_count(::Project.with_enabled_error_tracking.where(time_period), :creator_id),
projects_with_tracing_enabled: distinct_count(::Project.with_tracing_enabled.where(time_period), :creator_id)
}
end
def usage_activity_by_stage_package
def usage_activity_by_stage_package(time_period)
{
projects_with_packages: distinct_count(::Project.with_packages, :creator_id)
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`
def usage_activity_by_stage_plan
def usage_activity_by_stage_plan(time_period)
{
assignee_lists: distinct_count(::List.assignee, :user_id),
epics: distinct_count(::Epic, :author_id),
issues: distinct_count(::Issue, :author_id),
label_lists: distinct_count(::List.label, :user_id),
milestone_lists: distinct_count(::List.milestone, :user_id),
notes: distinct_count(::Note, :author_id),
projects: distinct_count(::Project, :creator_id),
projects_jira_active: distinct_count(::Project.with_active_jira_services, :creator_id),
projects_jira_dvcs_cloud_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_cloud, :creator_id),
projects_jira_dvcs_server_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_server, :creator_id),
service_desk_enabled_projects: distinct_count(::Project.with_active_services.service_desk_enabled, :creator_id),
service_desk_issues: distinct_count(::Issue.service_desk),
todos: distinct_count(::Todo, :author_id)
assignee_lists: distinct_count(::List.assignee.where(time_period), :user_id),
epics: distinct_count(::Epic.where(time_period), :author_id),
issues: distinct_count(::Issue.where(time_period), :author_id),
label_lists: distinct_count(::List.label.where(time_period), :user_id),
milestone_lists: distinct_count(::List.milestone.where(time_period), :user_id),
notes: distinct_count(::Note.where(time_period), :author_id),
projects: distinct_count(::Project.where(time_period), :creator_id),
projects_jira_active: distinct_count(::Project.with_active_jira_services.where(time_period), :creator_id),
projects_jira_dvcs_cloud_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_cloud.where(time_period), :creator_id),
projects_jira_dvcs_server_active: distinct_count(::Project.with_active_jira_services.with_jira_dvcs_server.where(time_period), :creator_id),
service_desk_enabled_projects: distinct_count(::Project.with_active_services.service_desk_enabled.where(time_period), :creator_id),
service_desk_issues: distinct_count(::Issue.service_desk.where(time_period)),
todos: distinct_count(::Todo.where(time_period), :author_id)
}
end
# Omitted because no user, creator or author associated: `environments`, `feature_flags`, `in_review_folder`, `pages_domains`
def usage_activity_by_stage_release
def usage_activity_by_stage_release(time_period)
{
deployments: distinct_count(::Deployment, :user_id),
failed_deployments: distinct_count(::Deployment.failed, :user_id),
projects_mirrored_with_pipelines_enabled: distinct_count(::Project.mirrored_with_enabled_pipelines, :creator_id),
releases: distinct_count(::Release, :author_id),
successful_deployments: distinct_count(::Deployment.success, :user_id)
deployments: distinct_count(::Deployment.where(time_period), :user_id),
failed_deployments: distinct_count(::Deployment.failed.where(time_period), :user_id),
projects_mirrored_with_pipelines_enabled: distinct_count(::Project.mirrored_with_enabled_pipelines.where(time_period), :creator_id),
releases: distinct_count(::Release.where(time_period), :author_id),
successful_deployments: distinct_count(::Deployment.success.where(time_period), :user_id)
}
end
# Omitted because no user, creator or author associated: `ci_runners`
def usage_activity_by_stage_verify
def usage_activity_by_stage_verify(time_period)
{
ci_builds: distinct_count(::Ci::Build, :user_id),
ci_external_pipelines: distinct_count(::Ci::Pipeline.external, :user_id),
ci_internal_pipelines: distinct_count(::Ci::Pipeline.internal, :user_id),
ci_pipeline_config_auto_devops: distinct_count(::Ci::Pipeline.auto_devops_source, :user_id),
ci_pipeline_config_repository: distinct_count(::Ci::Pipeline.repository_source, :user_id),
ci_pipeline_schedules: distinct_count(::Ci::PipelineSchedule, :owner_id),
ci_pipelines: distinct_count(::Ci::Pipeline, :user_id),
ci_triggers: distinct_count(::Ci::Trigger, :owner_id),
clusters_applications_runner: ::Clusters::Applications::Runner.distinct_by_user,
projects_reporting_ci_cd_back_to_github: distinct_count(::Project.with_github_service_pipeline_events, :creator_id)
ci_builds: distinct_count(::Ci::Build.where(time_period), :user_id),
ci_external_pipelines: distinct_count(::Ci::Pipeline.external.where(time_period), :user_id),
ci_internal_pipelines: distinct_count(::Ci::Pipeline.internal.where(time_period), :user_id),
ci_pipeline_config_auto_devops: distinct_count(::Ci::Pipeline.auto_devops_source.where(time_period), :user_id),
ci_pipeline_config_repository: distinct_count(::Ci::Pipeline.repository_source.where(time_period), :user_id),
ci_pipeline_schedules: distinct_count(::Ci::PipelineSchedule.where(time_period), :owner_id),
ci_pipelines: distinct_count(::Ci::Pipeline.where(time_period), :user_id),
ci_triggers: distinct_count(::Ci::Trigger.where(time_period), :owner_id),
clusters_applications_runner: ::Clusters::Applications::Runner.where(time_period).distinct_by_user,
projects_reporting_ci_cd_back_to_github: distinct_count(::Project.with_github_service_pipeline_events.where(time_period), :creator_id)
}
end
# Currently too complicated and to get reliable counts for these stats:
# container_scanning_jobs, dast_jobs, dependency_scanning_jobs, license_management_jobs, sast_jobs
# Once https://gitlab.com/gitlab-org/gitlab/merge_requests/17568 is merged, this might be doable
def usage_activity_by_stage_secure
def usage_activity_by_stage_secure(time_period)
{
user_preferences_group_overview_security_dashboard: count(::User.active.group_view_security_dashboard)
user_preferences_group_overview_security_dashboard: count(::User.active.group_view_security_dashboard.where(time_period))
}
end
end
......
......@@ -21,6 +21,7 @@ describe Gitlab::UsageData do
it "does #{'not' unless usage_ping_batch_counter_on} include usage_activity_by_stage data" do
expect(described_class.uncached_data.include?(:usage_activity_by_stage)).to be(usage_ping_batch_counter_on)
expect(described_class.uncached_data.include?(:usage_activity_by_stage_monthly)).to be(usage_ping_batch_counter_on)
end
context 'when feature is enabled' do
......@@ -30,6 +31,17 @@ describe Gitlab::UsageData do
it "does #{'not' unless usage_ping_batch_counter_on} include usage_activity_by_stage data" do
expect(described_class.uncached_data.include?(:usage_activity_by_stage)).to be(usage_ping_batch_counter_on)
expect(described_class.uncached_data.include?(:usage_activity_by_stage_monthly)).to be(usage_ping_batch_counter_on)
end
context 'when the :usage_activity_by_stage_monthly feature is disabled' do
before do
stub_feature_flags(usage_activity_by_stage_monthly: false)
end
it "does not include usage_activity_by_stage data" do
expect(described_class.uncached_data.include?(:usage_activity_by_stage_monthly)).to be(false)
end
end
end
end
......@@ -41,34 +53,58 @@ describe Gitlab::UsageData do
it "does not include usage_activity_by_stage data" do
expect(described_class.uncached_data).not_to include(:usage_activity_by_stage)
expect(described_class.uncached_data).not_to include(:usage_activity_by_stage_monthly)
end
end
context 'when not on Gitlab.com' do
it 'includes usage_activity_by_stage data' do
expect(described_class.uncached_data).to include(:usage_activity_by_stage)
expect(described_class.uncached_data).to include(:usage_activity_by_stage_monthly)
end
context 'for configure' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
cluster = create(:cluster, user: user)
project = create(:project, creator: user)
create(:clusters_applications_cert_manager, :installed, cluster: cluster)
create(:clusters_applications_helm, :installed, cluster: cluster)
create(:clusters_applications_ingress, :installed, cluster: cluster)
create(:clusters_applications_knative, :installed, cluster: cluster)
create(:cluster, :disabled, user: user)
create(:cluster_provider_gcp, :created)
create(:cluster_provider_aws, :created)
create(:cluster_platform_kubernetes)
create(:cluster, :group, :disabled, user: user)
create(:cluster, :group, user: user)
create(:slack_service, project: project)
create(:slack_slash_commands_service, project: project)
create(:prometheus_service, project: project)
[29, 2].each do |n|
Timecop.travel n.days.ago do
user = create(:user)
cluster = create(:cluster, user: user)
project = create(:project, creator: user)
create(:clusters_applications_cert_manager, :installed, cluster: cluster)
create(:clusters_applications_helm, :installed, cluster: cluster)
create(:clusters_applications_ingress, :installed, cluster: cluster)
create(:clusters_applications_knative, :installed, cluster: cluster)
create(:cluster, :disabled, user: user)
create(:cluster_provider_gcp, :created)
create(:cluster_provider_aws, :created)
create(:cluster_platform_kubernetes)
create(:cluster, :group, :disabled, user: user)
create(:cluster, :group, user: user)
create(:slack_service, project: project)
create(:slack_slash_commands_service, project: project)
create(:prometheus_service, project: project)
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:configure]).to eq(
clusters_applications_cert_managers: 2,
clusters_applications_helm: 2,
clusters_applications_ingress: 2,
clusters_applications_knative: 2,
clusters_disabled: 2,
clusters_enabled: 8,
clusters_platforms_gke: 2,
clusters_platforms_eks: 2,
clusters_platforms_user: 2,
group_clusters_disabled: 2,
group_clusters_enabled: 2,
project_clusters_disabled: 2,
project_clusters_enabled: 8,
projects_slack_notifications_active: 2,
projects_slack_slash_active: 2,
projects_with_prometheus_alerts: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:configure]).to eq(
clusters_applications_cert_managers: 1,
clusters_applications_helm: 1,
clusters_applications_ingress: 1,
......@@ -91,19 +127,35 @@ describe Gitlab::UsageData do
context 'for create' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
project = create(:project, :repository_private, :github_imported,
:test_repo, :remote_mirror, creator: user)
create(:deploy_key, user: user)
create(:key, user: user)
create(:merge_request, source_project: project)
create(:project, creator: user)
create(:protected_branch, project: project)
create(:remote_mirror, project: project)
create(:snippet, author: user)
create(:suggestion, note: create(:note, project: project))
[29, 2].each do |n|
Timecop.travel n.days.ago do
user = create(:user)
project = create(:project, :repository_private, :github_imported,
:test_repo, :remote_mirror, creator: user)
create(:deploy_key, user: user)
create(:key, user: user)
create(:merge_request, source_project: project)
create(:project, creator: user)
create(:protected_branch, project: project)
create(:remote_mirror, project: project)
create(:snippet, author: user)
create(:suggestion, note: create(:note, project: project))
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:create]).to eq(
deploy_keys: 2,
keys: 2,
merge_requests: 2,
projects_enforcing_code_owner_approval: 0,
projects_imported_from_github: 2,
projects_with_repositories_enabled: 2,
protected_branches: 2,
remote_mirrors: 2,
snippets: 2,
suggestions: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:create]).to eq(
deploy_keys: 1,
keys: 1,
merge_requests: 1,
......@@ -120,13 +172,23 @@ describe Gitlab::UsageData do
context 'for manage' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
create(:event, author: user)
create(:group_member, user: user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
[29, 2].each do |n|
Timecop.travel n.days.ago do
user = create(:user)
create(:event, author: user)
create(:group_member, user: user)
create(:key, type: 'LDAPKey', user: user)
create(:group_member, ldap: true, user: user)
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:manage]).to eq(
events: 2,
groups: 2,
ldap_keys: 2,
ldap_users: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:manage]).to eq(
events: 1,
groups: 1,
ldap_keys: 1,
......@@ -137,17 +199,30 @@ describe Gitlab::UsageData do
context 'for monitor' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user, dashboard: 'operations')
cluster = create(:cluster, user: user)
project = create(:project, creator: user)
[29, 2].each do |n|
Timecop.travel n.days.ago do
user = create(:user, dashboard: 'operations')
cluster = create(:cluster, user: user)
project = create(:project, creator: user)
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:users_ops_dashboard_project, user: user)
create(:prometheus_service, project: project)
create(:project_error_tracking_setting, project: project)
create(:project_tracing_setting, project: project)
create(:clusters_applications_prometheus, :installed, cluster: cluster)
create(:users_ops_dashboard_project, user: user)
create(:prometheus_service, project: project)
create(:project_error_tracking_setting, project: project)
create(:project_tracing_setting, project: project)
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:monitor]).to eq(
clusters: 2,
clusters_applications_prometheus: 2,
operations_dashboard_default_dashboard: 2,
operations_dashboard_users_with_projects_added: 2,
projects_prometheus_active: 2,
projects_with_error_tracking_enabled: 2,
projects_with_tracing_enabled: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:monitor]).to eq(
clusters: 1,
clusters_applications_prometheus: 1,
operations_dashboard_default_dashboard: 1,
......@@ -161,9 +236,16 @@ describe Gitlab::UsageData do
context 'for package' do
it 'includes accurate usage_activity_by_stage data' do
create(:project, packages: [create(:package)] )
[29, 2].each do |n|
Timecop.travel n.days.ago do
create(:project, packages: [create(:package)] )
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:package]).to eq(
projects_with_packages: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:package]).to eq(
projects_with_packages: 1
)
end
......@@ -173,23 +255,43 @@ describe Gitlab::UsageData do
it 'includes accurate usage_activity_by_stage data' do
stub_licensed_features(board_assignee_lists: true, board_milestone_lists: true)
user = create(:user)
project = create(:project, creator: user)
issue = create(:issue, project: project, author: User.support_bot)
board = create(:board, project: project)
create(:user_list, board: board, user: user)
create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user)
create(:list, board: board, label: create(:label, project: project), user: user)
create(:note, project: project, noteable: issue, author: user)
create(:epic, author: user)
create(:todo, project: project, target: issue, author: user)
create(:jira_service, :jira_cloud_service, active: true, project: create(:project, :jira_dvcs_cloud, creator: user))
create(:jira_service, active: true, project: create(:project, :jira_dvcs_server, creator: user))
[29, 2].each do |n|
Timecop.travel n.days.ago do
user = create(:user)
project = create(:project, creator: user)
issue = create(:issue, project: project, author: User.support_bot)
create(:issue, project: project, author: user)
board = create(:board, project: project)
create(:user_list, board: board, user: user)
create(:milestone_list, board: board, milestone: create(:milestone, project: project), user: user)
create(:list, board: board, label: create(:label, project: project), user: user)
create(:note, project: project, noteable: issue, author: user)
create(:epic, author: user)
create(:todo, project: project, target: issue, author: user)
create(:jira_service, :jira_cloud_service, active: true, project: create(:project, :jira_dvcs_cloud, creator: user))
create(:jira_service, active: true, project: create(:project, :jira_dvcs_server, creator: user))
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:plan]).to eq(
assignee_lists: 2,
epics: 2,
issues: 3,
label_lists: 2,
milestone_lists: 2,
notes: 2,
projects: 2,
projects_jira_active: 2,
projects_jira_dvcs_cloud_active: 2,
projects_jira_dvcs_server_active: 2,
service_desk_enabled_projects: 2,
service_desk_issues: 2,
todos: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:plan]).to eq(
assignee_lists: 1,
epics: 1,
issues: 1,
issues: 2,
label_lists: 1,
milestone_lists: 1,
notes: 1,
......@@ -206,13 +308,24 @@ describe Gitlab::UsageData do
context 'for release' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
create(:deployment, :failed, user: user)
create(:project, :mirror, mirror_trigger_builds: true)
create(:release, author: user)
create(:deployment, :success, user: user)
[29, 2].each do |n|
Timecop.travel n.days.ago do
user = create(:user)
create(:deployment, :failed, user: user)
create(:project, :mirror, mirror_trigger_builds: true)
create(:release, author: user)
create(:deployment, :success, user: user)
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:release]).to eq(
deployments: 2,
failed_deployments: 2,
projects_mirrored_with_pipelines_enabled: 2,
releases: 2,
successful_deployments: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:release]).to eq(
deployments: 1,
failed_deployments: 1,
projects_mirrored_with_pipelines_enabled: 1,
......@@ -226,7 +339,7 @@ describe Gitlab::UsageData do
it 'includes accurate usage_activity_by_stage data' do
create(:user, group_view: :security_dashboard)
expect(described_class.uncached_data[:usage_activity_by_stage][:secure]).to eq(
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:secure]).to eq(
user_preferences_group_overview_security_dashboard: 1
)
end
......@@ -234,18 +347,34 @@ describe Gitlab::UsageData do
context 'for verify' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
create(:ci_build, user: user)
create(:ci_empty_pipeline, source: :external, user: user)
create(:ci_empty_pipeline, user: user)
create(:ci_pipeline, :auto_devops_source, user: user)
create(:ci_pipeline, :repository_source, user: user)
create(:ci_pipeline_schedule, owner: user)
create(:ci_trigger, owner: user)
create(:clusters_applications_runner, :installed)
create(:github_service)
[29, 2].each do |n|
Timecop.travel n.days.ago do
user = create(:user)
create(:ci_build, user: user)
create(:ci_empty_pipeline, source: :external, user: user)
create(:ci_empty_pipeline, user: user)
create(:ci_pipeline, :auto_devops_source, user: user)
create(:ci_pipeline, :repository_source, user: user)
create(:ci_pipeline_schedule, owner: user)
create(:ci_trigger, owner: user)
create(:clusters_applications_runner, :installed)
create(:github_service)
end
end
expect(described_class.uncached_data[:usage_activity_by_stage][:verify]).to eq(
ci_builds: 2,
ci_external_pipelines: 2,
ci_internal_pipelines: 2,
ci_pipeline_config_auto_devops: 2,
ci_pipeline_config_repository: 2,
ci_pipeline_schedules: 2,
ci_pipelines: 2,
ci_triggers: 2,
clusters_applications_runner: 2,
projects_reporting_ci_cd_back_to_github: 2
)
expect(described_class.uncached_data[:usage_activity_by_stage_monthly][:verify]).to eq(
ci_builds: 1,
ci_external_pipelines: 1,
ci_internal_pipelines: 1,
......
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