From 3a8425c52044f6e2a52f0654b6f94577f9eda291 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Sat, 9 Jul 2022 06:08:43 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- app/models/ci/build.rb | 8 ++++++ app/workers/ci/archive_trace_worker.rb | 8 ++---- app/workers/ci/build_finished_worker.rb | 1 + .../sticky_ci_archive_trace_worker.yml | 8 ------ ..._ci_users_executing_verify_job_monthly.yml | 26 +++++++++++++++++++ ...7_ci_users_executing_verify_job_weekly.yml | 26 +++++++++++++++++++ .../known_events/ci_users.yml | 5 ++++ spec/models/ci/build_spec.rb | 26 +++++++++++++++++++ spec/workers/ci/archive_trace_worker_spec.rb | 17 ------------ 9 files changed, 94 insertions(+), 31 deletions(-) delete mode 100644 config/feature_flags/development/sticky_ci_archive_trace_worker.yml create mode 100644 config/metrics/counts_28d/20220706175117_ci_users_executing_verify_job_monthly.yml create mode 100644 config/metrics/counts_7d/20220706175117_ci_users_executing_verify_job_weekly.yml diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index a624c665353..2c0977043f4 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -1135,6 +1135,14 @@ module Ci Gitlab::Utils::UsageData.track_usage_event('ci_users_executing_deployment_job', user_id) if user_id.present? && count_user_deployment? end + def track_verify_usage + Gitlab::Utils::UsageData.track_usage_event('ci_users_executing_verify_environment_job', user_id) if user_id.present? && count_user_verification? + end + + def count_user_verification? + has_environment? && environment_action == 'verify' + end + def each_report(report_types) job_artifacts_for_types(report_types).each do |report_artifact| report_artifact.each_blob do |blob| diff --git a/app/workers/ci/archive_trace_worker.rb b/app/workers/ci/archive_trace_worker.rb index 47d77c15b4a..edbaf0536a2 100644 --- a/app/workers/ci/archive_trace_worker.rb +++ b/app/workers/ci/archive_trace_worker.rb @@ -4,17 +4,13 @@ module Ci class ArchiveTraceWorker # rubocop:disable Scalability/IdempotentWorker include ApplicationWorker - data_consistency :sticky, feature_flag: :sticky_ci_archive_trace_worker + data_consistency :sticky sidekiq_options retry: 3 include PipelineBackgroundQueue def perform(job_id) - archivable_jobs = Ci::Build.without_archived_trace - - if Feature.enabled?(:sticky_ci_archive_trace_worker) - archivable_jobs = archivable_jobs.eager_load_for_archiving_trace - end + archivable_jobs = Ci::Build.without_archived_trace.eager_load_for_archiving_trace archivable_jobs.find_by_id(job_id).try do |job| Ci::ArchiveTraceService.new.execute(job, worker_name: self.class.name) diff --git a/app/workers/ci/build_finished_worker.rb b/app/workers/ci/build_finished_worker.rb index 5ceaa87d2f5..25c7637a79f 100644 --- a/app/workers/ci/build_finished_worker.rb +++ b/app/workers/ci/build_finished_worker.rb @@ -40,6 +40,7 @@ module Ci BuildHooksWorker.perform_async(build) ChatNotificationWorker.perform_async(build.id) if build.pipeline.chat? build.track_deployment_usage + build.track_verify_usage if build.failed? && !build.auto_retry_expected? ::Ci::MergeRequests::AddTodoWhenBuildFailsWorker.perform_async(build.id) diff --git a/config/feature_flags/development/sticky_ci_archive_trace_worker.yml b/config/feature_flags/development/sticky_ci_archive_trace_worker.yml deleted file mode 100644 index 9494f6070f4..00000000000 --- a/config/feature_flags/development/sticky_ci_archive_trace_worker.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: sticky_ci_archive_trace_worker -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/87577 -rollout_issue_url: https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/1681 -milestone: '15.1' -type: development -group: group::scalability -default_enabled: false diff --git a/config/metrics/counts_28d/20220706175117_ci_users_executing_verify_job_monthly.yml b/config/metrics/counts_28d/20220706175117_ci_users_executing_verify_job_monthly.yml new file mode 100644 index 00000000000..7abc7b63c84 --- /dev/null +++ b/config/metrics/counts_28d/20220706175117_ci_users_executing_verify_job_monthly.yml @@ -0,0 +1,26 @@ +--- +key_path: redis_hll_counters.ci_users.ci_users_executing_verify_environment_job_monthly +description: Monthly counts of times users have executed verify jobs +product_section: ops +product_stage: release +product_group: release +product_category: continuous_delivery +value_type: number +status: active +milestone: "15.2" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/91925 +time_frame: 28d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +performance_indicator_type: [] +options: + events: + - ci_users_executing_verify_environment_job +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/config/metrics/counts_7d/20220706175117_ci_users_executing_verify_job_weekly.yml b/config/metrics/counts_7d/20220706175117_ci_users_executing_verify_job_weekly.yml new file mode 100644 index 00000000000..032ecc838b4 --- /dev/null +++ b/config/metrics/counts_7d/20220706175117_ci_users_executing_verify_job_weekly.yml @@ -0,0 +1,26 @@ +--- +key_path: redis_hll_counters.ci_users.ci_users_executing_verify_environment_job_weekly +description: Weekly counts of times users have executed verify jobs +product_section: ops +product_stage: release +product_group: release +product_category: continuous_delivery +value_type: number +status: active +milestone: "15.2" +introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/91925 +time_frame: 7d +data_source: redis_hll +data_category: optional +instrumentation_class: RedisHLLMetric +performance_indicator_type: [] +options: + events: + - ci_users_executing_verify_environment_job +distribution: + - ce + - ee +tier: + - free + - premium + - ultimate diff --git a/lib/gitlab/usage_data_counters/known_events/ci_users.yml b/lib/gitlab/usage_data_counters/known_events/ci_users.yml index 5159dcf62ab..b012d61eef5 100644 --- a/lib/gitlab/usage_data_counters/known_events/ci_users.yml +++ b/lib/gitlab/usage_data_counters/known_events/ci_users.yml @@ -3,3 +3,8 @@ redis_slot: ci_users aggregation: weekly feature_flag: +- name: ci_users_executing_verify_environment_job + category: ci_users + redis_slot: ci_users + aggregation: weekly + feature_flag: diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index fef28e7c550..6d04fb86d22 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1554,6 +1554,32 @@ RSpec.describe Ci::Build do end end + describe '#count_user_verification?' do + subject { build.count_user_verification? } + + context 'when build is the verify action for the environment' do + let(:build) do + create(:ci_build, + ref: 'master', + environment: 'staging', + options: { environment: { action: 'verify' } }) + end + + it { is_expected.to be_truthy } + end + + context 'when build is not the verify action for the environment' do + let(:build) do + create(:ci_build, + ref: 'master', + environment: 'staging', + options: { environment: { action: 'start' } }) + end + + it { is_expected.to be_falsey } + end + end + describe '#expanded_environment_name' do subject { build.expanded_environment_name } diff --git a/spec/workers/ci/archive_trace_worker_spec.rb b/spec/workers/ci/archive_trace_worker_spec.rb index 52723ff5823..3ac769aab9e 100644 --- a/spec/workers/ci/archive_trace_worker_spec.rb +++ b/spec/workers/ci/archive_trace_worker_spec.rb @@ -27,23 +27,6 @@ RSpec.describe Ci::ArchiveTraceWorker do subject end - - context 'when sticky_ci_archive_trace_worker is disabled' do - before do - stub_feature_flags(sticky_ci_archive_trace_worker: false) - end - - it 'does not preload associations' do - allow_next_instance_of(Ci::ArchiveTraceService) do |instance| - allow(instance).to receive(:execute) do |job| - expect(job.association(:project)).not_to be_loaded - expect(job.association(:pending_state)).not_to be_loaded - end - end - - subject - end - end end context 'when job is not found' do