summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-12 21:09:12 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-12 21:09:12 +0000
commit963c6277b29b205c38c24fa907dda933097fbd25 (patch)
tree58215f8cfa870eaef589c612d61e498f6e7e8f48 /lib
parentee4105895ebffdc6185d20f4592031723a76fedc (diff)
downloadgitlab-ce-963c6277b29b205c38c24fa907dda933097fbd25.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb55
-rw-r--r--lib/gitlab/ci/artifacts/metrics.rb26
-rw-r--r--lib/gitlab/ci/reports/test_suite_summary.rb11
3 files changed, 91 insertions, 1 deletions
diff --git a/lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb b/lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb
new file mode 100644
index 00000000000..4eaef26c9c6
--- /dev/null
+++ b/lib/gitlab/background_migration/move_container_registry_enabled_to_project_feature.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module BackgroundMigration
+ # This migration moves projects.container_registry_enabled values to
+ # project_features.container_registry_access_level for the projects within
+ # the given range of ids.
+ class MoveContainerRegistryEnabledToProjectFeature
+ MAX_BATCH_SIZE = 1_000
+
+ module Migratable
+ # Migration model namespace isolated from application code.
+ class ProjectFeature < ActiveRecord::Base
+ ENABLED = 20
+ DISABLED = 0
+ end
+ end
+
+ def perform(from_id, to_id)
+ (from_id..to_id).each_slice(MAX_BATCH_SIZE) do |batch|
+ process_batch(batch.first, batch.last)
+ end
+ end
+
+ private
+
+ def process_batch(from_id, to_id)
+ ActiveRecord::Base.connection.execute(update_sql(from_id, to_id))
+
+ logger.info(message: "#{self.class}: Copied container_registry_enabled values for projects with IDs between #{from_id}..#{to_id}")
+ end
+
+ # For projects that have a project_feature:
+ # Set project_features.container_registry_access_level to ENABLED (20) or DISABLED (0)
+ # depending if container_registry_enabled is true or false.
+ def update_sql(from_id, to_id)
+ <<~SQL
+ UPDATE project_features
+ SET container_registry_access_level = (CASE p.container_registry_enabled
+ WHEN true THEN #{ProjectFeature::ENABLED}
+ WHEN false THEN #{ProjectFeature::DISABLED}
+ ELSE #{ProjectFeature::DISABLED}
+ END)
+ FROM projects p
+ WHERE project_id = p.id AND
+ project_id BETWEEN #{from_id} AND #{to_id}
+ SQL
+ end
+
+ def logger
+ @logger ||= Gitlab::BackgroundMigration::Logger.build
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/artifacts/metrics.rb b/lib/gitlab/ci/artifacts/metrics.rb
new file mode 100644
index 00000000000..656f4d2cc13
--- /dev/null
+++ b/lib/gitlab/ci/artifacts/metrics.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ module Artifacts
+ class Metrics
+ include Gitlab::Utils::StrongMemoize
+
+ def increment_destroyed_artifacts(size)
+ destroyed_artifacts_counter.increment({}, size.to_i)
+ end
+
+ private
+
+ def destroyed_artifacts_counter
+ strong_memoize(:destroyed_artifacts_counter) do
+ name = :destroyed_job_artifacts_count_total
+ comment = 'Counter of destroyed expired job artifacts'
+
+ ::Gitlab::Metrics.counter(name, comment)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/reports/test_suite_summary.rb b/lib/gitlab/ci/reports/test_suite_summary.rb
index 32b06d0ad49..461aefc6fa9 100644
--- a/lib/gitlab/ci/reports/test_suite_summary.rb
+++ b/lib/gitlab/ci/reports/test_suite_summary.rb
@@ -4,6 +4,8 @@ module Gitlab
module Ci
module Reports
class TestSuiteSummary
+ include Gitlab::Utils::StrongMemoize
+
def initialize(build_report_results)
@build_report_results = build_report_results
end
@@ -42,6 +44,12 @@ module Gitlab
end
# rubocop: disable CodeReuse/ActiveRecord
+ def suite_error
+ strong_memoize(:suite_error) do
+ @build_report_results.map(&:suite_error).compact.first
+ end
+ end
+
def to_h
{
time: total_time,
@@ -49,7 +57,8 @@ module Gitlab
success: success_count,
failed: failed_count,
skipped: skipped_count,
- error: error_count
+ error: error_count,
+ suite_error: suite_error
}
end
end