Commit 473691ca authored by Shinya Maeda's avatar Shinya Maeda

Merge branch...

Merge branch '338492-augment-current-deployment-count-which-counts-environments-with-additional-counters' into 'master'

Resolve "Augment current Deployment count with additional counters"

See merge request gitlab-org/gitlab!79272
parents 3e7b1482 95dd6e9e
......@@ -10,6 +10,8 @@ module Ci
include Presentable
include Importable
include Ci::HasRef
include HasDeploymentName
extend ::Gitlab::Utils::Override
BuildArchivedError = Class.new(StandardError)
......@@ -35,6 +37,8 @@ module Ci
DEGRADATION_THRESHOLD_VARIABLE_NAME = 'DEGRADATION_THRESHOLD'
RUNNERS_STATUS_CACHE_EXPIRATION = 1.minute
DEPLOYMENT_NAMES = %w[deploy release rollout].freeze
has_one :deployment, as: :deployable, class_name: 'Deployment'
has_one :pending_state, class_name: 'Ci::BuildPendingState', inverse_of: :build
has_one :queuing_entry, class_name: 'Ci::PendingBuild', foreign_key: :build_id
......@@ -1123,6 +1127,10 @@ module Ci
.include?(exit_code)
end
def track_deployment_usage
Gitlab::Utils::UsageData.track_usage_event('ci_users_executing_deployment_job', user_id) if user_id.present? && count_user_deployment?
end
protected
def run_status_commit_hooks!
......
# frozen_string_literal: true
module Ci
module HasDeploymentName
extend ActiveSupport::Concern
def count_user_deployment?
Feature.enabled?(:job_deployment_count) && deployment_name?
end
def deployment_name?
self.class::DEPLOYMENT_NAMES.any? { |n| name.downcase.include?(n) }
end
end
end
......@@ -39,6 +39,7 @@ module Ci
# We execute these async as these are independent operations.
BuildHooksWorker.perform_async(build.id)
ChatNotificationWorker.perform_async(build.id) if build.pipeline.chat?
build.track_deployment_usage
if build.failed? && !build.auto_retry_expected?
::Ci::MergeRequests::AddTodoWhenBuildFailsWorker.perform_async(build.id)
......
---
name: job_deployment_count
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79272
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/351591
milestone: '14.8'
type: development
group: group::release
default_enabled: false
---
key_path: redis_hll_counters.ci_users.ci_users_executing_deployment_job_monthly
description: Monthly counts of times users have executed deployment jobs
product_section: ops
product_stage: release
product_group: group::release
product_category: continuous_delivery
value_type: number
status: active
milestone: "14.8"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79272
time_frame: 28d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
performance_indicator_type: []
options:
events:
- ci_users_executing_deployment_job
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
---
key_path: redis_hll_counters.ci_users.ci_users_executing_deployment_job_weekly
description: Weekly counts of times users have executed deployment jobs
product_section: ops
product_stage: release
product_group: group::release
product_category: continuous_delivery
value_type: number
status: active
milestone: "14.8"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79272
time_frame: 7d
data_source: redis_hll
data_category: optional
instrumentation_class: RedisHLLMetric
performance_indicator_type: []
options:
events:
- ci_users_executing_deployment_job
distribution:
- ce
- ee
tier:
- free
- premium
- ultimate
- name: ci_users_executing_deployment_job
category: ci_users
redis_slot: ci_users
aggregation: weekly
feature_flag: job_deployment_count
......@@ -51,7 +51,8 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s
'network_policies',
'geo',
'growth',
'work_items'
'work_items',
'ci_users'
)
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::HasDeploymentName do
describe 'deployment_name?' do
let(:build) { create(:ci_build) }
subject { build.branch? }
it 'does detect deployment names' do
build.name = 'deployment'
expect(build.deployment_name?).to be_truthy
end
it 'does detect partial deployment names' do
build.name = 'do a really cool deploy'
expect(build.deployment_name?).to be_truthy
end
it 'does not detect non-deployment names' do
build.name = 'testing'
expect(build.deployment_name?).to be_falsy
end
it 'is case insensitive' do
build.name = 'DEPLOY'
expect(build.deployment_name?).to be_truthy
end
end
end
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