Commit c7b8b63e authored by Tiago Botelho's avatar Tiago Botelho

Adds prometheus metrics to both mirroring and remote mirroring features

parent 1501d7c9
...@@ -73,6 +73,8 @@ module EE ...@@ -73,6 +73,8 @@ module EE
if import? && !repository_exists? if import? && !repository_exists?
super super
elsif mirror? elsif mirror?
::Gitlab::Mirror.increment_metric(:mirrors_scheduled, 'Mirrors scheduled count')
RepositoryUpdateMirrorWorker.perform_async(self.id) RepositoryUpdateMirrorWorker.perform_async(self.id)
end end
end end
......
...@@ -46,10 +46,14 @@ class RemoteMirror < ActiveRecord::Base ...@@ -46,10 +46,14 @@ class RemoteMirror < ActiveRecord::Base
state :failed state :failed
after_transition any => :started do |remote_mirror, _| after_transition any => :started do |remote_mirror, _|
Gitlab::Mirror.increment_metric(:remote_mirrors_running, 'Remote mirrors running count')
remote_mirror.update(last_update_started_at: Time.now) remote_mirror.update(last_update_started_at: Time.now)
end end
after_transition started: :finished do |remote_mirror, _| after_transition started: :finished do |remote_mirror, _|
Gitlab::Mirror.increment_metric(:remote_mirrors_finished, 'Remote mirrors successfully finished count')
timestamp = Time.now timestamp = Time.now
remote_mirror.update_attributes!( remote_mirror.update_attributes!(
last_update_at: timestamp, last_successful_update_at: timestamp, last_error: nil last_update_at: timestamp, last_successful_update_at: timestamp, last_error: nil
...@@ -57,6 +61,8 @@ class RemoteMirror < ActiveRecord::Base ...@@ -57,6 +61,8 @@ class RemoteMirror < ActiveRecord::Base
end end
after_transition started: :failed do |remote_mirror, _| after_transition started: :failed do |remote_mirror, _|
Gitlab::Mirror.increment_metric(:remote_mirrors_failed, 'Remote mirrors failed count')
remote_mirror.update(last_update_at: Time.now) remote_mirror.update(last_update_at: Time.now)
end end
end end
......
...@@ -14,14 +14,14 @@ class RepositoryUpdateMirrorWorker ...@@ -14,14 +14,14 @@ class RepositoryUpdateMirrorWorker
project = Project.find(project_id) project = Project.find(project_id)
raise UpdateAlreadyInProgressError if project.import_started? raise UpdateAlreadyInProgressError if project.import_started?
project.import_start start_mirror(project)
@current_user = project.mirror_user || project.creator @current_user = project.mirror_user || project.creator
result = Projects::UpdateMirrorService.new(project, @current_user).execute result = Projects::UpdateMirrorService.new(project, @current_user).execute
raise UpdateError, result[:message] if result[:status] == :error raise UpdateError, result[:message] if result[:status] == :error
project.import_finish finish_mirror(project)
rescue UpdateAlreadyInProgressError rescue UpdateAlreadyInProgressError
raise raise
rescue UpdateError => ex rescue UpdateError => ex
...@@ -38,8 +38,21 @@ class RepositoryUpdateMirrorWorker ...@@ -38,8 +38,21 @@ class RepositoryUpdateMirrorWorker
private private
def start_mirror(project)
project.import_start
Gitlab::Mirror.increment_metric(:mirrors_running, 'Mirrors running count')
end
def fail_mirror(project, message) def fail_mirror(project, message)
Rails.logger.error(message)
project.mark_import_as_failed(message) project.mark_import_as_failed(message)
Gitlab::Mirror.increment_metric(:mirrors_failed, 'Mirrors failed count')
Rails.logger.error(message)
end
def finish_mirror(project)
project.import_finish
Gitlab::Mirror.increment_metric(:mirrors_finished, 'Mirrors successfully finished count')
end end
end end
...@@ -41,7 +41,8 @@ class RepositoryUpdateRemoteMirrorWorker ...@@ -41,7 +41,8 @@ class RepositoryUpdateRemoteMirrorWorker
private private
def fail_remote_mirror(remote_mirror, message) def fail_remote_mirror(remote_mirror, message)
Rails.logger.error(message)
remote_mirror.mark_as_failed(message) remote_mirror.mark_as_failed(message)
Rails.logger.error(message)
end end
end end
---
title: Add metrics to both remote and non remote mirroring
merge_request: 2118
author:
...@@ -54,6 +54,10 @@ module Gitlab ...@@ -54,6 +54,10 @@ module Gitlab
current_application_settings.mirror_capacity_threshold current_application_settings.mirror_capacity_threshold
end end
def increment_metric(name, docstring)
Gitlab::Metrics.counter(name, docstring).increment
end
private private
def update_all_mirrors_cron_job def update_all_mirrors_cron_job
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment