From 36a59d088eca61b834191dacea009677a96c052f Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 19 May 2022 07:33:21 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-0-stable-ee --- .../ci/create_downstream_pipeline_service.rb | 3 +++ app/services/ci/expire_pipeline_cache_service.rb | 2 +- app/services/ci/generate_kubeconfig_service.rb | 11 ++++---- app/services/ci/job_artifacts/create_service.rb | 2 +- .../ci/job_artifacts/destroy_batch_service.rb | 17 ++++++++++--- .../ci/pipeline_creation/start_pipeline_service.rb | 5 ++++ app/services/ci/pipeline_trigger_service.rb | 2 ++ app/services/ci/queue/build_queue_service.rb | 2 +- app/services/ci/queue/builds_table_strategy.rb | 2 +- app/services/ci/queue/pending_builds_strategy.rb | 4 +-- app/services/ci/register_job_service.rb | 16 ++++++------ app/services/ci/retry_job_service.rb | 29 +++++----------------- app/services/ci/runners/register_runner_service.rb | 2 +- .../ci/runners/reset_registration_token_service.rb | 2 ++ .../ci/stuck_builds/drop_running_service.rb | 2 +- app/services/ci/update_build_state_service.rb | 4 +-- 16 files changed, 54 insertions(+), 51 deletions(-) (limited to 'app/services/ci') diff --git a/app/services/ci/create_downstream_pipeline_service.rb b/app/services/ci/create_downstream_pipeline_service.rb index 0a0c614bb87..b38b3b93353 100644 --- a/app/services/ci/create_downstream_pipeline_service.rb +++ b/app/services/ci/create_downstream_pipeline_service.rb @@ -6,6 +6,7 @@ module Ci # specifications. class CreateDownstreamPipelineService < ::BaseService include Gitlab::Utils::StrongMemoize + include Ci::DownstreamPipelineHelpers DuplicateDownstreamPipelineError = Class.new(StandardError) @@ -37,6 +38,8 @@ module Ci .execute(pipeline_params.fetch(:source), **pipeline_params[:execute_params]) .payload + log_downstream_pipeline_creation(downstream_pipeline) + downstream_pipeline.tap do |pipeline| update_bridge_status!(@bridge, pipeline) end diff --git a/app/services/ci/expire_pipeline_cache_service.rb b/app/services/ci/expire_pipeline_cache_service.rb index 8622b1a5863..bf2355c447a 100644 --- a/app/services/ci/expire_pipeline_cache_service.rb +++ b/app/services/ci/expire_pipeline_cache_service.rb @@ -86,7 +86,7 @@ module Ci etag_paths << path end - pipeline.self_with_upstreams_and_downstreams.includes(project: [:route, { namespace: :route }]).each do |relative_pipeline| # rubocop: disable CodeReuse/ActiveRecord + pipeline.all_pipelines_in_hierarchy.includes(project: [:route, { namespace: :route }]).each do |relative_pipeline| # rubocop: disable CodeReuse/ActiveRecord etag_paths << project_pipeline_path(relative_pipeline.project, relative_pipeline) etag_paths << graphql_pipeline_path(relative_pipeline) etag_paths << graphql_pipeline_sha_path(relative_pipeline.sha) diff --git a/app/services/ci/generate_kubeconfig_service.rb b/app/services/ci/generate_kubeconfig_service.rb index 18f68c0ff09..894ab8e8505 100644 --- a/app/services/ci/generate_kubeconfig_service.rb +++ b/app/services/ci/generate_kubeconfig_service.rb @@ -2,8 +2,9 @@ module Ci class GenerateKubeconfigService - def initialize(build) - @build = build + def initialize(pipeline, token:) + @pipeline = pipeline + @token = token @template = Gitlab::Kubernetes::Kubeconfig::Template.new end @@ -33,10 +34,10 @@ module Ci private - attr_reader :build, :template + attr_reader :pipeline, :token, :template def agents - build.pipeline.authorized_cluster_agents + pipeline.authorized_cluster_agents end def cluster_name @@ -52,7 +53,7 @@ module Ci end def agent_token(agent) - ['ci', agent.id, build.token].join(delimiter) + ['ci', agent.id, token].join(delimiter) end def delimiter diff --git a/app/services/ci/job_artifacts/create_service.rb b/app/services/ci/job_artifacts/create_service.rb index 7c67a2e175d..635111130d6 100644 --- a/app/services/ci/job_artifacts/create_service.rb +++ b/app/services/ci/job_artifacts/create_service.rb @@ -133,7 +133,7 @@ module Ci job.update_column(:artifacts_expire_at, artifact.expire_at) end - success + success(artifact: artifact) rescue ActiveRecord::RecordNotUnique => error track_exception(error, params) error('another artifact of the same type already exists', :bad_request) diff --git a/app/services/ci/job_artifacts/destroy_batch_service.rb b/app/services/ci/job_artifacts/destroy_batch_service.rb index 90d157373c3..5121a8b0a8b 100644 --- a/app/services/ci/job_artifacts/destroy_batch_service.rb +++ b/app/services/ci/job_artifacts/destroy_batch_service.rb @@ -33,9 +33,11 @@ module Ci destroy_related_records(@job_artifacts) - Ci::DeletedObject.transaction do - Ci::DeletedObject.bulk_import(@job_artifacts, @pick_up_at) - Ci::JobArtifact.id_in(@job_artifacts.map(&:id)).delete_all + destroy_around_hook(@job_artifacts) do + Ci::DeletedObject.transaction do + Ci::DeletedObject.bulk_import(@job_artifacts, @pick_up_at) + Ci::JobArtifact.id_in(@job_artifacts.map(&:id)).delete_all + end end after_batch_destroy_hook(@job_artifacts) @@ -51,6 +53,13 @@ module Ci private + # Overriden in EE + # :nocov: + def destroy_around_hook(artifacts) + yield + end + # :nocov: + # Overriden in EE def destroy_related_records(artifacts); end @@ -121,7 +130,7 @@ module Ci end def fix_expire_at? - Feature.enabled?(:ci_detect_wrongly_expired_artifacts, default_enabled: :yaml) + Feature.enabled?(:ci_detect_wrongly_expired_artifacts) end def wrongly_expired?(artifact) diff --git a/app/services/ci/pipeline_creation/start_pipeline_service.rb b/app/services/ci/pipeline_creation/start_pipeline_service.rb index 27c12caaa0a..65a045f32dd 100644 --- a/app/services/ci/pipeline_creation/start_pipeline_service.rb +++ b/app/services/ci/pipeline_creation/start_pipeline_service.rb @@ -10,6 +10,11 @@ module Ci end def execute + ## + # Create a persistent ref for the pipeline. + # The pipeline ref is fetched in the jobs and deleted when the pipeline transitions to a finished state. + pipeline.ensure_persistent_ref + Ci::ProcessPipelineService.new(pipeline).execute end end diff --git a/app/services/ci/pipeline_trigger_service.rb b/app/services/ci/pipeline_trigger_service.rb index 7746382b845..06eb1aee8e6 100644 --- a/app/services/ci/pipeline_trigger_service.rb +++ b/app/services/ci/pipeline_trigger_service.rb @@ -4,6 +4,7 @@ module Ci class PipelineTriggerService < BaseService include Gitlab::Utils::StrongMemoize include Services::ReturnServiceResponses + include Ci::DownstreamPipelineHelpers def execute if trigger_from_token @@ -69,6 +70,7 @@ module Ci pipeline.source_pipeline = source end + log_downstream_pipeline_creation(response.payload) pipeline_service_response(response.payload) end diff --git a/app/services/ci/queue/build_queue_service.rb b/app/services/ci/queue/build_queue_service.rb index 9f476c8a785..fefbdb151ec 100644 --- a/app/services/ci/queue/build_queue_service.rb +++ b/app/services/ci/queue/build_queue_service.rb @@ -80,7 +80,7 @@ module Ci def strategy strong_memoize(:strategy) do - if ::Feature.enabled?(:ci_pending_builds_queue_source, runner, default_enabled: :yaml) + if ::Feature.enabled?(:ci_pending_builds_queue_source, runner) Queue::PendingBuildsStrategy.new(runner) else Queue::BuildsTableStrategy.new(runner) diff --git a/app/services/ci/queue/builds_table_strategy.rb b/app/services/ci/queue/builds_table_strategy.rb index 237dd510d50..c27c10bd18d 100644 --- a/app/services/ci/queue/builds_table_strategy.rb +++ b/app/services/ci/queue/builds_table_strategy.rb @@ -18,7 +18,7 @@ module Ci .joins('LEFT JOIN project_features ON ci_builds.project_id = project_features.project_id') .where('project_features.builds_access_level IS NULL or project_features.builds_access_level > 0') - if Feature.enabled?(:ci_queueing_disaster_recovery_disable_fair_scheduling, runner, type: :ops, default_enabled: :yaml) + if Feature.enabled?(:ci_queueing_disaster_recovery_disable_fair_scheduling, runner, type: :ops) # if disaster recovery is enabled, we fallback to FIFO scheduling relation.order('ci_builds.id ASC') else diff --git a/app/services/ci/queue/pending_builds_strategy.rb b/app/services/ci/queue/pending_builds_strategy.rb index 47158b8ea1d..f2eba0681db 100644 --- a/app/services/ci/queue/pending_builds_strategy.rb +++ b/app/services/ci/queue/pending_builds_strategy.rb @@ -51,7 +51,7 @@ module Ci end def use_denormalized_data_strategy? - ::Feature.enabled?(:ci_queuing_use_denormalized_data_strategy, default_enabled: :yaml) + ::Feature.enabled?(:ci_queuing_use_denormalized_data_strategy) end private @@ -70,7 +70,7 @@ module Ci end def builds_ordered_for_shared_runners(relation) - if Feature.enabled?(:ci_queueing_disaster_recovery_disable_fair_scheduling, runner, type: :ops, default_enabled: :yaml) + if Feature.enabled?(:ci_queueing_disaster_recovery_disable_fair_scheduling, runner, type: :ops) # if disaster recovery is enabled, we fallback to FIFO scheduling relation.order('ci_pending_builds.build_id ASC') else diff --git a/app/services/ci/register_job_service.rb b/app/services/ci/register_job_service.rb index 6c9044b5089..8969b95b81f 100644 --- a/app/services/ci/register_job_service.rb +++ b/app/services/ci/register_job_service.rb @@ -157,15 +157,13 @@ module Ci unless build.pending? @metrics.increment_queue_operation(:build_not_pending) - if Feature.enabled?(:ci_pending_builds_table_resiliency, default_enabled: :yaml) - ## - # If this build can not be picked because we had stale data in - # `ci_pending_builds` table, we need to respond with 409 to retry - # this operation. - # - if ::Ci::UpdateBuildQueueService.new.remove!(build) - return Result.new(nil, nil, false) - end + ## + # If this build can not be picked because we had stale data in + # `ci_pending_builds` table, we need to respond with 409 to retry + # this operation. + # + if ::Ci::UpdateBuildQueueService.new.remove!(build) + return Result.new(nil, nil, false) end return diff --git a/app/services/ci/retry_job_service.rb b/app/services/ci/retry_job_service.rb index af7e7fa16e9..e0ced3d0197 100644 --- a/app/services/ci/retry_job_service.rb +++ b/app/services/ci/retry_job_service.rb @@ -23,11 +23,11 @@ module Ci # Cloning a job requires a strict type check to ensure # the attributes being used for the clone are taken straight # from the model and not overridden by other abstractions. - raise TypeError unless job.instance_of?(Ci::Build) + raise TypeError unless job.instance_of?(Ci::Build) || job.instance_of?(Ci::Bridge) check_access!(job) - new_job = clone_job(job) + new_job = job.clone(current_user: current_user) new_job.run_after_commit do ::Ci::CopyCrossDatabaseAssociationsService.new.execute(job, new_job) @@ -53,9 +53,12 @@ module Ci private + def check_assignable_runners!(job); end + def retry_job(job) clone!(job).tap do |new_job| - check_assignable_runners!(new_job) + check_assignable_runners!(new_job) if new_job.is_a?(Ci::Build) + next if new_job.failed? Gitlab::OptimisticLocking.retry_lock(new_job, name: 'retry_build', &:enqueue) @@ -68,26 +71,6 @@ module Ci raise Gitlab::Access::AccessDeniedError, '403 Forbidden' end end - - def check_assignable_runners!(job); end - - def clone_job(job) - project.builds.new(job_attributes(job)) - end - - def job_attributes(job) - attributes = job.class.clone_accessors.to_h do |attribute| - [attribute, job.public_send(attribute)] # rubocop:disable GitlabSecurity/PublicSend - end - - if job.persisted_environment.present? - attributes[:metadata_attributes] ||= {} - attributes[:metadata_attributes][:expanded_environment_name] = job.expanded_environment_name - end - - attributes[:user] = current_user - attributes - end end end diff --git a/app/services/ci/runners/register_runner_service.rb b/app/services/ci/runners/register_runner_service.rb index 7978d094d9b..196d2de1a65 100644 --- a/app/services/ci/runners/register_runner_service.rb +++ b/app/services/ci/runners/register_runner_service.rb @@ -47,7 +47,7 @@ module Ci end def runner_registrar_valid?(type) - Feature.disabled?(:runner_registration_control, default_enabled: :yaml) || Gitlab::CurrentSettings.valid_runner_registrars.include?(type) + Feature.disabled?(:runner_registration_control) || Gitlab::CurrentSettings.valid_runner_registrars.include?(type) end def token_scope diff --git a/app/services/ci/runners/reset_registration_token_service.rb b/app/services/ci/runners/reset_registration_token_service.rb index bbe49c04644..2a3fb08c5e1 100644 --- a/app/services/ci/runners/reset_registration_token_service.rb +++ b/app/services/ci/runners/reset_registration_token_service.rb @@ -29,3 +29,5 @@ module Ci end end end + +Ci::Runners::ResetRegistrationTokenService.prepend_mod diff --git a/app/services/ci/stuck_builds/drop_running_service.rb b/app/services/ci/stuck_builds/drop_running_service.rb index a79224cc231..dfcf3ca3836 100644 --- a/app/services/ci/stuck_builds/drop_running_service.rb +++ b/app/services/ci/stuck_builds/drop_running_service.rb @@ -16,7 +16,7 @@ module Ci private def running_timed_out_builds - if Feature.enabled?(:ci_new_query_for_running_stuck_jobs, default_enabled: :yaml) + if Feature.enabled?(:ci_new_query_for_running_stuck_jobs) Ci::Build .running .created_at_before(BUILD_RUNNING_OUTDATED_TIMEOUT.ago) diff --git a/app/services/ci/update_build_state_service.rb b/app/services/ci/update_build_state_service.rb index 9df36b86404..a74ddcfaf06 100644 --- a/app/services/ci/update_build_state_service.rb +++ b/app/services/ci/update_build_state_service.rb @@ -217,11 +217,11 @@ module Ci def chunks_migration_enabled? ::Feature.enabled?(:ci_enable_live_trace, build.project) && - ::Feature.enabled?(:ci_accept_trace, build.project, type: :ops, default_enabled: true) + ::Feature.enabled?(:ci_accept_trace, build.project, type: :ops) end def log_invalid_chunks? - ::Feature.enabled?(:ci_trace_log_invalid_chunks, build.project, type: :ops, default_enabled: false) + ::Feature.enabled?(:ci_trace_log_invalid_chunks, build.project, type: :ops) end end end -- cgit v1.2.1