summaryrefslogtreecommitdiff
path: root/app/services/projects
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/projects')
-rw-r--r--app/services/projects/alerting/notify_service.rb14
-rw-r--r--app/services/projects/container_repository/delete_tags_service.rb1
-rw-r--r--app/services/projects/participants_service.rb2
-rw-r--r--app/services/projects/prometheus/alerts/notify_service.rb40
-rw-r--r--app/services/projects/schedule_bulk_repository_shard_moves_service.rb35
-rw-r--r--app/services/projects/transfer_service.rb11
-rw-r--r--app/services/projects/update_pages_service.rb16
7 files changed, 93 insertions, 26 deletions
diff --git a/app/services/projects/alerting/notify_service.rb b/app/services/projects/alerting/notify_service.rb
index ab8f53a3757..014fb0e3ed3 100644
--- a/app/services/projects/alerting/notify_service.rb
+++ b/app/services/projects/alerting/notify_service.rb
@@ -2,10 +2,16 @@
module Projects
module Alerting
- class NotifyService < BaseService
+ class NotifyService
+ include BaseServiceUtility
include Gitlab::Utils::StrongMemoize
include ::IncidentManagement::Settings
+ def initialize(project, payload)
+ @project = project
+ @payload = payload
+ end
+
def execute(token, integration = nil)
@integration = integration
@@ -24,7 +30,7 @@ module Projects
private
- attr_reader :integration
+ attr_reader :project, :payload, :integration
def process_alert
if alert.persisted?
@@ -101,7 +107,7 @@ module Projects
def incoming_payload
strong_memoize(:incoming_payload) do
- Gitlab::AlertManagement::Payload.parse(project, params.to_h)
+ Gitlab::AlertManagement::Payload.parse(project, payload.to_h)
end
end
@@ -110,7 +116,7 @@ module Projects
end
def valid_payload_size?
- Gitlab::Utils::DeepSize.new(params).valid?
+ Gitlab::Utils::DeepSize.new(payload).valid?
end
def active_integration?
diff --git a/app/services/projects/container_repository/delete_tags_service.rb b/app/services/projects/container_repository/delete_tags_service.rb
index 505ddaf50e3..410cf6c624e 100644
--- a/app/services/projects/container_repository/delete_tags_service.rb
+++ b/app/services/projects/container_repository/delete_tags_service.rb
@@ -36,6 +36,7 @@ module Projects
def log_response(response)
log_data = LOG_DATA_BASE.merge(
container_repository_id: @container_repository.id,
+ project_id: @container_repository.project_id,
message: 'deleted tags',
deleted_tags_count: response[:deleted]&.size
).compact
diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb
index 1cd81fe37c7..228115d72b8 100644
--- a/app/services/projects/participants_service.rb
+++ b/app/services/projects/participants_service.rb
@@ -14,7 +14,7 @@ module Projects
groups +
project_members
- participants.uniq
+ render_participants_as_hash(participants.uniq)
end
def project_members
diff --git a/app/services/projects/prometheus/alerts/notify_service.rb b/app/services/projects/prometheus/alerts/notify_service.rb
index 8ad4f59373d..93165a58470 100644
--- a/app/services/projects/prometheus/alerts/notify_service.rb
+++ b/app/services/projects/prometheus/alerts/notify_service.rb
@@ -3,7 +3,7 @@
module Projects
module Prometheus
module Alerts
- class NotifyService < BaseService
+ class NotifyService
include Gitlab::Utils::StrongMemoize
include ::IncidentManagement::Settings
@@ -17,28 +17,35 @@ module Projects
SUPPORTED_VERSION = '4'
- def execute(token, _integration = nil)
+ def initialize(project, payload)
+ @project = project
+ @payload = payload
+ end
+
+ def execute(token, integration = nil)
return bad_request unless valid_payload_size?
- return unprocessable_entity unless self.class.processable?(params)
- return unauthorized unless valid_alert_manager_token?(token)
+ return unprocessable_entity unless self.class.processable?(payload)
+ return unauthorized unless valid_alert_manager_token?(token, integration)
process_prometheus_alerts
ServiceResponse.success
end
- def self.processable?(params)
+ def self.processable?(payload)
# Workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/220496
- return false unless params
+ return false unless payload
- REQUIRED_PAYLOAD_KEYS.subset?(params.keys.to_set) &&
- params['version'] == SUPPORTED_VERSION
+ REQUIRED_PAYLOAD_KEYS.subset?(payload.keys.to_set) &&
+ payload['version'] == SUPPORTED_VERSION
end
private
+ attr_reader :project, :payload
+
def valid_payload_size?
- Gitlab::Utils::DeepSize.new(params).valid?
+ Gitlab::Utils::DeepSize.new(payload).valid?
end
def firings
@@ -50,12 +57,12 @@ module Projects
end
def alerts
- params['alerts']
+ payload['alerts']
end
- def valid_alert_manager_token?(token)
+ def valid_alert_manager_token?(token, integration)
valid_for_manual?(token) ||
- valid_for_alerts_endpoint?(token) ||
+ valid_for_alerts_endpoint?(token, integration) ||
valid_for_managed?(token)
end
@@ -70,11 +77,10 @@ module Projects
end
end
- def valid_for_alerts_endpoint?(token)
- return false unless project.alerts_service_activated?
+ def valid_for_alerts_endpoint?(token, integration)
+ return false unless integration&.active?
- # Here we are enforcing the existence of the token
- compare_token(token, project.alerts_service.token)
+ compare_token(token, integration.token)
end
def valid_for_managed?(token)
@@ -122,7 +128,7 @@ module Projects
def process_prometheus_alerts
alerts.each do |alert|
AlertManagement::ProcessPrometheusAlertService
- .new(project, nil, alert.to_h)
+ .new(project, alert.to_h)
.execute
end
end
diff --git a/app/services/projects/schedule_bulk_repository_shard_moves_service.rb b/app/services/projects/schedule_bulk_repository_shard_moves_service.rb
new file mode 100644
index 00000000000..dd49910207f
--- /dev/null
+++ b/app/services/projects/schedule_bulk_repository_shard_moves_service.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+module Projects
+ # Tries to schedule a move for every project with repositories on the source shard
+ class ScheduleBulkRepositoryShardMovesService
+ include BaseServiceUtility
+
+ def execute(source_storage_name, destination_storage_name = nil)
+ shard = Shard.find_by_name!(source_storage_name)
+
+ ProjectRepository.for_shard(shard).each_batch(column: :project_id) do |relation|
+ Project.id_in(relation.select(:project_id)).each do |project|
+ project.with_lock do
+ next if project.repository_storage != source_storage_name
+
+ storage_move = project.repository_storage_moves.build(
+ source_storage_name: source_storage_name,
+ destination_storage_name: destination_storage_name
+ )
+
+ unless storage_move.schedule
+ log_info("Project #{project.full_path} (#{project.id}) was skipped: #{storage_move.errors.full_messages.to_sentence}")
+ end
+ end
+ end
+ end
+
+ success
+ end
+
+ def self.enqueue(source_storage_name, destination_storage_name = nil)
+ ::ProjectScheduleBulkRepositoryShardMovesWorker.perform_async(source_storage_name, destination_storage_name)
+ end
+ end
+end
diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb
index 5178c76f0fc..1574c90d2ac 100644
--- a/app/services/projects/transfer_service.rb
+++ b/app/services/projects/transfer_service.rb
@@ -59,7 +59,7 @@ module Projects
raise TransferError.new(s_("TransferProject|Root namespace can't be updated if project has NPM packages"))
end
- attempt_transfer_transaction
+ proceed_to_transfer
end
# rubocop: enable CodeReuse/ActiveRecord
@@ -67,7 +67,7 @@ module Projects
new_namespace.root_ancestor == project.namespace.root_ancestor
end
- def attempt_transfer_transaction
+ def proceed_to_transfer
Project.transaction do
project.expire_caches_before_rename(@old_path)
@@ -87,6 +87,8 @@ module Projects
# Move uploads
move_project_uploads(project)
+ update_integrations
+
project.old_path_with_namespace = @old_path
update_repository_configuration(@new_path)
@@ -214,6 +216,11 @@ module Projects
project.shared_runners_enabled = false
end
end
+
+ def update_integrations
+ project.services.inherit.delete_all
+ Service.create_from_active_default_integrations(project, :project_id)
+ end
end
end
diff --git a/app/services/projects/update_pages_service.rb b/app/services/projects/update_pages_service.rb
index b9c579a130f..53872c67f49 100644
--- a/app/services/projects/update_pages_service.rb
+++ b/app/services/projects/update_pages_service.rb
@@ -4,6 +4,9 @@ module Projects
class UpdatePagesService < BaseService
InvalidStateError = Class.new(StandardError)
FailedToExtractError = Class.new(StandardError)
+ ExclusiveLeaseTaken = Class.new(StandardError)
+
+ include ::Pages::LegacyStorageLease
BLOCK_SIZE = 32.kilobytes
PUBLIC_DIR = 'public'
@@ -109,6 +112,17 @@ module Projects
end
def deploy_page!(archive_public_path)
+ deployed = try_obtain_lease do
+ deploy_page_unsafe!(archive_public_path)
+ true
+ end
+
+ unless deployed
+ raise ExclusiveLeaseTaken, "Failed to deploy pages - other deployment is in progress"
+ end
+ end
+
+ def deploy_page_unsafe!(archive_public_path)
# Do atomic move of pages
# Move and removal may not be atomic, but they are significantly faster then extracting and removal
# 1. We move deployed public to previous public path (file removal is slow)
@@ -125,8 +139,6 @@ module Projects
end
def create_pages_deployment(artifacts_path, build)
- return unless Feature.enabled?(:zip_pages_deployments, project, default_enabled: true)
-
# we're using the full archive and pages daemon needs to read it
# so we want the total count from entries, not only "public/" directory
# because it better approximates work we need to do before we can serve the site