Commit 6d728226 authored by Alex Buijs's avatar Alex Buijs

Add usage statistics data for release stage

Added usage activity data for the release stage
parent c7dd5259
......@@ -180,3 +180,5 @@ class Deployment < ApplicationRecord
self.created_at if success? && !read_attribute(:finished_at)
end
end
Deployment.prepend_if_ee('EE::Deployment')
......@@ -67,3 +67,5 @@ class Release < ApplicationRecord
end
end
end
Release.prepend_if_ee('EE::Release')
# frozen_string_literal: true
module EE
# Project EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be prepended in the `Deployment` model
module Deployment
extend ActiveSupport::Concern
prepended do
include UsageStatistics
end
end
end
......@@ -14,8 +14,8 @@ module EE
# Returns environments where its latest deployment is to a cluster
scope :deployed_to_cluster, -> (cluster) do
environments = model.arel_table
deployments = Deployment.arel_table
later_deployments = Deployment.arel_table.alias('latest_deployments')
deployments = ::Deployment.arel_table
later_deployments = ::Deployment.arel_table.alias('latest_deployments')
join_conditions = later_deployments[:environment_id]
.eq(deployments[:environment_id])
.and(deployments[:id].lt(later_deployments[:id]))
......
......@@ -123,6 +123,10 @@ module EE
scope :with_enabled_error_tracking, -> { joins(:error_tracking_setting).where(project_error_tracking_settings: { enabled: true }) }
scope :with_tracing_enabled, -> { joins(:tracing_setting) }
scope :with_packages, -> { joins(:packages) }
scope :mirrored_with_enabled_pipelines, -> do
joins(:project_feature).mirror.where(mirror_trigger_builds: true,
project_features: { builds_access_level: ::ProjectFeature::ENABLED })
end
delegate :shared_runners_minutes, :shared_runners_seconds, :shared_runners_seconds_last_reset,
to: :statistics, allow_nil: true
......
# frozen_string_literal: true
module EE
# Project EE mixin
#
# This module is intended to encapsulate EE-specific model logic
# and be prepended in the `Release` model
module Release
extend ActiveSupport::Concern
prepended do
include UsageStatistics
end
end
end
......@@ -63,20 +63,6 @@ module EE
usage_data
end
# rubocop: disable CodeReuse/ActiveRecord
def projects_mirrored_with_pipelines_enabled
count(
::Project.joins(:project_feature).where(
mirror: true,
mirror_trigger_builds: true,
project_features: {
builds_access_level: ::ProjectFeature::ENABLED
}
)
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def service_desk_counts
return {} unless ::License.feature_available?(:service_desk)
......@@ -148,7 +134,7 @@ module EE
operations_dashboard: operations_dashboard_usage,
pod_logs_usages_total: ::Gitlab::UsageCounters::PodLogs.usage_totals[:total],
projects_enforcing_code_owner_approval: count(::Project.without_deleted.non_archived.requiring_code_owner_approval),
projects_mirrored_with_pipelines_enabled: projects_mirrored_with_pipelines_enabled,
projects_mirrored_with_pipelines_enabled: count(::Project.mirrored_with_enabled_pipelines),
projects_reporting_ci_cd_back_to_github: count(::GithubService.without_defaults.active),
projects_with_packages: count(::Packages::Package.select('distinct project_id')),
projects_with_prometheus_alerts: count(PrometheusAlert.distinct_projects),
......@@ -188,6 +174,7 @@ module EE
monitor: usage_activity_by_stage_monitor,
package: usage_activity_by_stage_package,
plan: usage_activity_by_stage_plan,
release: usage_activity_by_stage_release,
verify: usage_activity_by_stage_verify
}
}
......@@ -257,6 +244,17 @@ module EE
}
end
# Omitted because no user, creator or author associated: `environments`, `feature_flags`, `in_review_folder`, `pages_domains`
def usage_activity_by_stage_release
{
deployments: ::Deployment.distinct_count_by(:user_id),
failed_deployments: ::Deployment.failed.distinct_count_by(:user_id),
projects_mirrored_with_pipelines_enabled: ::Project.mirrored_with_enabled_pipelines.distinct_count_by(:creator_id),
releases: ::Release.distinct_count_by(:author_id),
successful_deployments: ::Deployment.success.distinct_count_by(:user_id)
}
end
# Omitted because no user, creator or author associated: `ci_runners`
def usage_activity_by_stage_verify
{
......
......@@ -152,6 +152,24 @@ describe Gitlab::UsageData do
end
end
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)
expect(described_class.uncached_data[:usage_activity_by_stage][:release]).to eq(
deployments: 1,
failed_deployments: 1,
projects_mirrored_with_pipelines_enabled: 1,
releases: 1,
successful_deployments: 1
)
end
end
context 'for verify' 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