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

tracing.rb « graphql « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b505e4262bf18fcb75862ae11559957128910d4 (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
# frozen_string_literal: true

module Gitlab
  module Graphql
    class Tracing < GraphQL::Tracing::PlatformTracing
      self.platform_keys = {
        'lex' => 'graphql.lex',
        'parse' => 'graphql.parse',
        'validate' => 'graphql.validate',
        'analyze_query' => 'graphql.analyze',
        'analyze_multiplex' => 'graphql.analyze',
        'execute_multiplex' => 'graphql.execute',
        'execute_query' => 'graphql.execute',
        'execute_query_lazy' => 'graphql.execute',
        'execute_field' => 'graphql.execute',
        'execute_field_lazy' => 'graphql.execute'
      }

      def platform_field_key(type, field)
        "#{type.name}.#{field.name}"
      end

      def platform_trace(platform_key, key, data, &block)
        start = Gitlab::Metrics::System.monotonic_time

        yield
      ensure
        duration = Gitlab::Metrics::System.monotonic_time - start

        graphql_duration_seconds.observe({ platform_key: platform_key, key: key }, duration)
      end

      private

      def graphql_duration_seconds
        @graphql_duration_seconds ||= Gitlab::Metrics.histogram(
          :graphql_duration_seconds,
          'GraphQL execution time'
        )
      end
    end
  end
end