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

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

module Gitlab
  module Instrumentation
    class GlobalSearchApi
      TYPE = 'meta.search.type'
      LEVEL = 'meta.search.level'
      SCOPE = 'meta.search.scope'
      SEARCH_DURATION_S = :global_search_duration_s

      def self.get_type
        ::Gitlab::SafeRequestStore[TYPE]
      end

      def self.get_level
        ::Gitlab::SafeRequestStore[LEVEL]
      end

      def self.get_scope
        ::Gitlab::SafeRequestStore[SCOPE]
      end

      def self.get_search_duration_s
        ::Gitlab::SafeRequestStore[SEARCH_DURATION_S]
      end

      def self.payload
        {
          TYPE => get_type,
          LEVEL => get_level,
          SCOPE => get_scope,
          SEARCH_DURATION_S => get_search_duration_s
        }.compact
      end

      def self.set_information(type:, level:, scope:, search_duration_s:)
        if ::Gitlab::SafeRequestStore.active?
          ::Gitlab::SafeRequestStore[TYPE] = type
          ::Gitlab::SafeRequestStore[LEVEL] = level
          ::Gitlab::SafeRequestStore[SCOPE] = scope
          ::Gitlab::SafeRequestStore[SEARCH_DURATION_S] = search_duration_s
        end
      end
    end
  end
end