Commit d6f77cb3 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '39-count-unique-users-for-more-accurate-smau-reporting-configure' into 'master'

Count unique users for more accurate SMAU reporting - Configure

See merge request gitlab-org/gitlab!17362
parents d5c0545a e864e92a
......@@ -127,6 +127,9 @@ module EE
joins(:project_feature).mirror.where(mirror_trigger_builds: true,
project_features: { builds_access_level: ::ProjectFeature::ENABLED })
end
scope :with_slack_service, -> { joins(:slack_service) }
scope :with_slack_slash_commands_service, -> { joins(:slack_slash_commands_service) }
scope :with_prometheus_service, -> { joins(:prometheus_service) }
delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :statistics, allow_nil: true
......
......@@ -169,6 +169,7 @@ module EE
def usage_activity_by_stage
{
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,
......@@ -181,6 +182,28 @@ module EE
}
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
{
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: ::Clusters::Cluster.disabled.distinct_count_by(:user_id),
clusters_enabled: ::Clusters::Cluster.enabled.distinct_count_by(:user_id),
clusters_platforms_gke: ::Clusters::Cluster.gcp_installed.enabled.distinct_count_by(:user_id),
clusters_platforms_user: ::Clusters::Cluster.user_provided.enabled.distinct_count_by(:user_id),
group_clusters_disabled: ::Clusters::Cluster.disabled.group_type.distinct_count_by(:user_id),
group_clusters_enabled: ::Clusters::Cluster.enabled.group_type.distinct_count_by(:user_id),
project_clusters_disabled: ::Clusters::Cluster.disabled.project_type.distinct_count_by(:user_id),
project_clusters_enabled: ::Clusters::Cluster.enabled.project_type.distinct_count_by(:user_id),
projects_slack_notifications_active: ::Project.with_slack_service.distinct_count_by(:creator_id),
projects_slack_slash_active: ::Project.with_slack_slash_commands_service.distinct_count_by(:creator_id),
projects_with_prometheus_alerts: ::Project.with_prometheus_service.distinct_count_by(:creator_id)
}
end
# Omitted because no user, creator or author associated: `lfs_objects`, `pool_repositories`, `web_hooks`
def usage_activity_by_stage_create
{
......
......@@ -23,4 +23,17 @@ FactoryBot.define do
token { 'github-token' }
type { 'GithubService' }
end
factory :slack_service do
project
active { true }
webhook { 'https://slack.service.url' }
type { 'SlackService' }
end
factory :slack_slash_commands_service do
project
active { true }
type { 'SlackSlashCommandsService' }
end
end
......@@ -39,6 +39,44 @@ describe Gitlab::UsageData do
expect(described_class.uncached_data).to include(:usage_activity_by_stage)
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, :provided_by_gcp, user: user)
create(:cluster, :provided_by_user, user: user)
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)
expect(described_class.uncached_data[:usage_activity_by_stage][:configure]).to eq(
clusters_applications_cert_managers: 1,
clusters_applications_helm: 1,
clusters_applications_ingress: 1,
clusters_applications_knative: 1,
clusters_disabled: 1,
clusters_enabled: 4,
clusters_platforms_gke: 1,
clusters_platforms_user: 1,
group_clusters_disabled: 1,
group_clusters_enabled: 1,
project_clusters_disabled: 1,
project_clusters_enabled: 4,
projects_slack_notifications_active: 1,
projects_slack_slash_active: 1,
projects_with_prometheus_alerts: 1
)
end
end
context 'for create' do
it 'includes accurate usage_activity_by_stage data' do
user = create(:user)
......
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