diff options
Diffstat (limited to 'lib/gitlab/import/metrics.rb')
-rw-r--r-- | lib/gitlab/import/metrics.rb | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/lib/gitlab/import/metrics.rb b/lib/gitlab/import/metrics.rb index 2692ab2fa12..5f27d0ab965 100644 --- a/lib/gitlab/import/metrics.rb +++ b/lib/gitlab/import/metrics.rb @@ -3,27 +3,35 @@ module Gitlab module Import class Metrics + include Gitlab::Utils::UsageData + IMPORT_DURATION_BUCKETS = [0.5, 1, 3, 5, 10, 60, 120, 240, 360, 720, 1440].freeze - attr_reader :importer + attr_reader :importer, :duration def initialize(importer, project) @importer = importer @project = project end + def track_start_import + return unless project.github_import? + + track_usage_event(:github_import_project_start, project.id) + end + def track_finished_import - duration = Time.zone.now - @project.created_at + @duration = Time.zone.now - project.created_at - duration_histogram.observe({ importer: importer }, duration) + observe_histogram projects_counter.increment + track_finish_metric end - def projects_counter - @projects_counter ||= Gitlab::Metrics.counter( - :"#{importer}_imported_projects_total", - 'The number of imported projects' - ) + def track_failed_import + return unless project.github_import? + + track_usage_event(:github_import_project_failure, project.id) end def issues_counter @@ -42,6 +50,8 @@ module Gitlab private + attr_reader :project + def duration_histogram @duration_histogram ||= Gitlab::Metrics.histogram( :"#{importer}_total_duration_seconds", @@ -50,6 +60,27 @@ module Gitlab IMPORT_DURATION_BUCKETS ) end + + def projects_counter + @projects_counter ||= Gitlab::Metrics.counter( + :"#{importer}_imported_projects_total", + 'The number of imported projects' + ) + end + + def observe_histogram + if project.github_import? + duration_histogram.observe({ project: project.full_path }, duration) + else + duration_histogram.observe({ importer: importer }, duration) + end + end + + def track_finish_metric + return unless project.github_import? + + track_usage_event(:github_import_project_success, project.id) + end end end end |