2020-04-22 19:07:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Import
|
2020-07-28 23:09:34 +05:30
|
|
|
class Metrics
|
2021-11-18 22:05:49 +05:30
|
|
|
include Gitlab::Utils::UsageData
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
IMPORT_DURATION_BUCKETS = [0.5, 1, 3, 5, 10, 60, 120, 240, 360, 720, 1440].freeze
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
attr_reader :importer, :duration
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def initialize(importer, project)
|
|
|
|
@importer = importer
|
|
|
|
@project = project
|
|
|
|
end
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
def track_start_import
|
|
|
|
return unless project.github_import?
|
|
|
|
|
|
|
|
track_usage_event(:github_import_project_start, project.id)
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def track_finished_import
|
2021-11-18 22:05:49 +05:30
|
|
|
@duration = Time.zone.now - project.created_at
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
observe_histogram
|
2020-07-28 23:09:34 +05:30
|
|
|
projects_counter.increment
|
2021-11-18 22:05:49 +05:30
|
|
|
track_finish_metric
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
def track_failed_import
|
|
|
|
return unless project.github_import?
|
|
|
|
|
|
|
|
track_usage_event(:github_import_project_failure, project.id)
|
2023-05-27 22:25:52 +05:30
|
|
|
track_import_state('github')
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_canceled_import
|
|
|
|
return unless project.github_import?
|
|
|
|
|
|
|
|
track_usage_event(:github_import_project_cancelled, project.id)
|
|
|
|
track_import_state('github')
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def issues_counter
|
|
|
|
@issues_counter ||= Gitlab::Metrics.counter(
|
|
|
|
:"#{importer}_imported_issues_total",
|
|
|
|
'The number of imported issues'
|
|
|
|
)
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def merge_requests_counter
|
|
|
|
@merge_requests_counter ||= Gitlab::Metrics.counter(
|
|
|
|
:"#{importer}_imported_merge_requests_total",
|
|
|
|
'The number of imported merge (pull) requests'
|
|
|
|
)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
private
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
attr_reader :project
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def duration_histogram
|
|
|
|
@duration_histogram ||= Gitlab::Metrics.histogram(
|
|
|
|
:"#{importer}_total_duration_seconds",
|
|
|
|
'Total time spent importing projects, in seconds',
|
|
|
|
{},
|
|
|
|
IMPORT_DURATION_BUCKETS
|
|
|
|
)
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
|
|
|
def projects_counter
|
|
|
|
@projects_counter ||= Gitlab::Metrics.counter(
|
|
|
|
:"#{importer}_imported_projects_total",
|
|
|
|
'The number of imported projects'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def observe_histogram
|
2021-12-11 22:18:48 +05:30
|
|
|
duration_histogram.observe({ importer: importer }, duration)
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def track_finish_metric
|
|
|
|
return unless project.github_import?
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
track_import_state('github')
|
|
|
|
|
|
|
|
case project.beautified_import_status_name
|
|
|
|
when 'partially completed'
|
|
|
|
track_usage_event(:github_import_project_partially_completed, project.id)
|
|
|
|
when 'completed'
|
|
|
|
track_usage_event(:github_import_project_success, project.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_import_state(type)
|
|
|
|
Gitlab::Tracking.event(
|
|
|
|
importer,
|
|
|
|
'create',
|
|
|
|
label: "#{type}_import_project_state",
|
|
|
|
project: project,
|
|
|
|
extra: { import_type: type, state: project.beautified_import_status_name }
|
|
|
|
)
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|