Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/ci')
-rw-r--r--app/services/ci/job_artifacts/destroy_all_expired_service.rb2
-rw-r--r--app/services/ci/job_artifacts/destroy_batch_service.rb37
-rw-r--r--app/services/ci/pipeline_artifacts/coverage_report_service.rb38
-rw-r--r--app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb2
-rw-r--r--app/services/ci/runners/reset_registration_token_service.rb7
5 files changed, 67 insertions, 19 deletions
diff --git a/app/services/ci/job_artifacts/destroy_all_expired_service.rb b/app/services/ci/job_artifacts/destroy_all_expired_service.rb
index 4070875ffe1..b5dd5b843c6 100644
--- a/app/services/ci/job_artifacts/destroy_all_expired_service.rb
+++ b/app/services/ci/job_artifacts/destroy_all_expired_service.rb
@@ -60,7 +60,7 @@ module Ci
end
def destroy_batch(artifacts)
- Ci::JobArtifacts::DestroyBatchService.new(artifacts).execute
+ Ci::JobArtifacts::DestroyBatchService.new(artifacts, skip_projects_on_refresh: true).execute
end
def loop_timeout?
diff --git a/app/services/ci/job_artifacts/destroy_batch_service.rb b/app/services/ci/job_artifacts/destroy_batch_service.rb
index 5121a8b0a8b..49b65f13804 100644
--- a/app/services/ci/job_artifacts/destroy_batch_service.rb
+++ b/app/services/ci/job_artifacts/destroy_batch_service.rb
@@ -17,14 +17,21 @@ module Ci
# +pick_up_at+:: When to pick up for deletion of files
# Returns:
# +Hash+:: A hash with status and destroyed_artifacts_count keys
- def initialize(job_artifacts, pick_up_at: nil, fix_expire_at: fix_expire_at?)
+ def initialize(job_artifacts, pick_up_at: nil, fix_expire_at: fix_expire_at?, skip_projects_on_refresh: false)
@job_artifacts = job_artifacts.with_destroy_preloads.to_a
@pick_up_at = pick_up_at
@fix_expire_at = fix_expire_at
+ @skip_projects_on_refresh = skip_projects_on_refresh
end
# rubocop: disable CodeReuse/ActiveRecord
def execute(update_stats: true)
+ if @skip_projects_on_refresh
+ exclude_artifacts_undergoing_stats_refresh
+ else
+ track_artifacts_undergoing_stats_refresh
+ end
+
# Detect and fix artifacts that had `expire_at` wrongly backfilled by migration
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/47723
detect_and_fix_wrongly_expired_artifacts
@@ -154,6 +161,34 @@ module Ci
Gitlab::AppLogger.info(message: "Fixed expire_at from artifacts.", fixed_artifacts_expire_at_count: artifacts.count)
end
+
+ def track_artifacts_undergoing_stats_refresh
+ project_ids = @job_artifacts.find_all do |artifact|
+ artifact.project.refreshing_build_artifacts_size?
+ end.map(&:project_id).uniq
+
+ project_ids.each do |project_id|
+ Gitlab::ProjectStatsRefreshConflictsLogger.warn_artifact_deletion_during_stats_refresh(
+ method: 'Ci::JobArtifacts::DestroyBatchService#execute',
+ project_id: project_id
+ )
+ end
+ end
+
+ def exclude_artifacts_undergoing_stats_refresh
+ project_ids = Set.new
+
+ @job_artifacts.reject! do |artifact|
+ next unless artifact.project.refreshing_build_artifacts_size?
+
+ project_ids << artifact.project_id
+ end
+
+ Gitlab::ProjectStatsRefreshConflictsLogger.warn_skipped_artifact_deletion_during_stats_refresh(
+ method: 'Ci::JobArtifacts::DestroyBatchService#execute',
+ project_ids: project_ids
+ )
+ end
end
end
end
diff --git a/app/services/ci/pipeline_artifacts/coverage_report_service.rb b/app/services/ci/pipeline_artifacts/coverage_report_service.rb
index 8209639fa22..b0acb1d5a0b 100644
--- a/app/services/ci/pipeline_artifacts/coverage_report_service.rb
+++ b/app/services/ci/pipeline_artifacts/coverage_report_service.rb
@@ -2,30 +2,44 @@
module Ci
module PipelineArtifacts
class CoverageReportService
- def execute(pipeline)
- return unless pipeline.can_generate_coverage_reports?
- return if pipeline.has_coverage_reports?
+ include Gitlab::Utils::StrongMemoize
+
+ def initialize(pipeline)
+ @pipeline = pipeline
+ end
- file = build_carrierwave_file(pipeline)
+ def execute
+ return if pipeline.has_coverage_reports?
+ return if report.empty?
pipeline.pipeline_artifacts.create!(
project_id: pipeline.project_id,
file_type: :code_coverage,
file_format: Ci::PipelineArtifact::REPORT_TYPES.fetch(:code_coverage),
- size: file["tempfile"].size,
- file: file,
+ size: carrierwave_file["tempfile"].size,
+ file: carrierwave_file,
expire_at: Ci::PipelineArtifact::EXPIRATION_DATE.from_now
)
end
private
- def build_carrierwave_file(pipeline)
- CarrierWaveStringFile.new_file(
- file_content: pipeline.coverage_reports.to_json,
- filename: Ci::PipelineArtifact::DEFAULT_FILE_NAMES.fetch(:code_coverage),
- content_type: 'application/json'
- )
+ attr_reader :pipeline
+
+ def report
+ strong_memoize(:report) do
+ Gitlab::Ci::Reports::CoverageReportGenerator.new(pipeline).report
+ end
+ end
+
+ def carrierwave_file
+ strong_memoize(:carrier_wave_file) do
+ CarrierWaveStringFile.new_file(
+ file_content: report.to_json,
+ filename: Ci::PipelineArtifact::DEFAULT_FILE_NAMES.fetch(:code_coverage),
+ content_type: 'application/json'
+ )
+ end
end
end
end
diff --git a/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb b/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb
index 7b6590a117c..17c039885e5 100644
--- a/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb
+++ b/app/services/ci/pipeline_artifacts/destroy_all_expired_service.rb
@@ -25,7 +25,7 @@ module Ci
private
def destroy_artifacts_batch
- artifacts = ::Ci::PipelineArtifact.unlocked.expired(BATCH_SIZE).to_a
+ artifacts = ::Ci::PipelineArtifact.unlocked.expired.limit(BATCH_SIZE).to_a
return false if artifacts.empty?
artifacts.each(&:destroy!)
diff --git a/app/services/ci/runners/reset_registration_token_service.rb b/app/services/ci/runners/reset_registration_token_service.rb
index 2a3fb08c5e1..81a70a771cf 100644
--- a/app/services/ci/runners/reset_registration_token_service.rb
+++ b/app/services/ci/runners/reset_registration_token_service.rb
@@ -13,11 +13,10 @@ module Ci
def execute
return unless @user.present? && @user.can?(:update_runners_registration_token, scope)
- case scope
- when ::ApplicationSetting
+ if scope.respond_to?(:runners_registration_token)
scope.reset_runners_registration_token!
- ApplicationSetting.current_without_cache.runners_registration_token
- when ::Group, ::Project
+ scope.runners_registration_token
+ else
scope.reset_runners_token!
scope.runners_token
end