Welcome to mirror list, hosted at ThFree Co, Russian Federation.

action_view.rb « subscribers « metrics « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e1f1f37c905c52ce3da1674c993ce496644cbcd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# frozen_string_literal: true

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)
          tags = tags_for(event)
          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)
        end

        def relative_path(path)
          path.gsub(%r{^#{Rails.root}/?}, '')
        end

        def tags_for(event)
          path = relative_path(event.payload[:identifier])

          { view: path }
        end

        def current_transaction
          Transaction.current
        end
      end
    end
  end
end