Commit 8d470bff authored by Douwe Maan's avatar Douwe Maan

Merge branch 'mirroring-prometheus-metrics' into 'master'

adds prometheus metrics to both mirro and remote mirror features

See merge request !2118
parents 3718417b c7b8b63e
......@@ -78,6 +78,8 @@ module EE
if import? && !repository_exists?
super
elsif mirror?
::Gitlab::Mirror.increment_metric(:mirrors_scheduled, 'Mirrors scheduled count')
RepositoryUpdateMirrorWorker.perform_async(self.id)
end
end
......
......@@ -43,10 +43,14 @@ class RemoteMirror < ActiveRecord::Base
state :failed
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)
end
after_transition started: :finished do |remote_mirror, _|
Gitlab::Mirror.increment_metric(:remote_mirrors_finished, 'Remote mirrors successfully finished count')
timestamp = Time.now
remote_mirror.update_attributes!(
last_update_at: timestamp, last_successful_update_at: timestamp, last_error: nil
......@@ -54,6 +58,8 @@ class RemoteMirror < ActiveRecord::Base
end
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)
end
end
......
......@@ -14,14 +14,14 @@ class RepositoryUpdateMirrorWorker
project = Project.find(project_id)
raise UpdateAlreadyInProgressError if project.import_started?
project.import_start
start_mirror(project)
@current_user = project.mirror_user || project.creator
result = Projects::UpdateMirrorService.new(project, @current_user).execute
raise UpdateError, result[:message] if result[:status] == :error
project.import_finish
finish_mirror(project)
rescue UpdateAlreadyInProgressError
raise
rescue UpdateError => ex
......@@ -38,8 +38,21 @@ class RepositoryUpdateMirrorWorker
private
def start_mirror(project)
project.import_start
Gitlab::Mirror.increment_metric(:mirrors_running, 'Mirrors running count')
end
def fail_mirror(project, message)
Rails.logger.error(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
......@@ -41,7 +41,8 @@ class RepositoryUpdateRemoteMirrorWorker
private
def fail_remote_mirror(remote_mirror, message)
Rails.logger.error(message)
remote_mirror.mark_as_failed(message)
Rails.logger.error(message)
end
end
---
title: Add metrics to both remote and non remote mirroring
merge_request: 2118
author:
......@@ -54,6 +54,10 @@ module Gitlab
current_application_settings.mirror_capacity_threshold
end
def increment_metric(name, docstring)
Gitlab::Metrics.counter(name, docstring).increment
end
private
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