mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-12 06:06:05 +10:00
Where a vew is called from doesn't matter as much. We already know what action they belong to and this is more than enough information. By removing the file/line number from the list of tags we should also be able to reduce the number of series stored in InfluxDB.
47 lines
1.0 KiB
Ruby
47 lines
1.0 KiB
Ruby
module Gitlab
|
|
module Metrics
|
|
module Subscribers
|
|
# Class for tracking the rendering timings of views.
|
|
class ActionView < ActiveSupport::Subscriber
|
|
attach_to :action_view
|
|
|
|
SERIES = 'views'
|
|
|
|
def render_template(event)
|
|
track(event) if current_transaction
|
|
end
|
|
|
|
alias_method :render_view, :render_template
|
|
|
|
private
|
|
|
|
def track(event)
|
|
values = values_for(event)
|
|
tags = tags_for(event)
|
|
|
|
current_transaction.increment(:view_duration, event.duration)
|
|
current_transaction.add_metric(SERIES, values, tags)
|
|
end
|
|
|
|
def relative_path(path)
|
|
path.gsub(/^#{Rails.root.to_s}\/?/, '')
|
|
end
|
|
|
|
def values_for(event)
|
|
{ duration: event.duration }
|
|
end
|
|
|
|
def tags_for(event)
|
|
path = relative_path(event.payload[:identifier])
|
|
|
|
{ view: path }
|
|
end
|
|
|
|
def current_transaction
|
|
Transaction.current
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|