2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
module Gitlab
|
|
|
|
module Metrics
|
|
|
|
module Subscribers
|
|
|
|
# Class for tracking the rendering timings of views.
|
|
|
|
class ActionView < ActiveSupport::Subscriber
|
|
|
|
attach_to :action_view
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
SERIES = 'views'
|
2016-01-14 18:37:52 +05:30
|
|
|
|
|
|
|
def render_template(event)
|
|
|
|
track(event) if current_transaction
|
|
|
|
end
|
|
|
|
|
|
|
|
alias_method :render_view, :render_template
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def track(event)
|
2020-05-24 23:13:21 +05:30
|
|
|
tags = tags_for(event)
|
2020-10-24 23:57:45 +05:30
|
|
|
current_transaction.observe(:gitlab_view_rendering_duration_seconds, event.duration, tags) do
|
|
|
|
docstring 'View rendering time'
|
|
|
|
label_keys %i(view)
|
|
|
|
buckets [0.001, 0.01, 0.1, 1, 10.0]
|
|
|
|
with_feature :prometheus_metrics_view_instrumentation
|
|
|
|
end
|
|
|
|
|
|
|
|
current_transaction.increment(:gitlab_transaction_view_duration_total, event.duration)
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def relative_path(path)
|
2020-03-13 15:44:24 +05:30
|
|
|
path.gsub(%r{^#{Rails.root}/?}, '')
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def tags_for(event)
|
|
|
|
path = relative_path(event.payload[:identifier])
|
|
|
|
|
|
|
|
{ view: path }
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_transaction
|
2021-10-27 15:23:28 +05:30
|
|
|
::Gitlab::Metrics::Transaction.current
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|