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

redis_interceptor.rb « instrumentation « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9c89af6a0dc5814b1a156faab19171be0b3dde5f (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
49
50
51
52
53
54
55
# frozen_string_literal: true

module Gitlab
  module Instrumentation
    module RedisInterceptor
      include RedisHelper

      def call(command)
        instrument_call([command], instrumentation_class) do
          super
        end
      end

      def call_pipeline(pipeline)
        instrument_call(pipeline.commands, instrumentation_class, true) do
          super
        end
      end

      def write(command)
        measure_write_size(command, instrumentation_class) if ::RequestStore.active?
        super
      end

      def read
        result = super
        measure_read_size(result, instrumentation_class) if ::RequestStore.active?
        result
      end

      def ensure_connected
        super do
          instrument_reconnection_errors do
            yield
          end
        end
      end

      def instrument_reconnection_errors
        yield
      rescue ::Redis::BaseConnectionError => ex
        instrumentation_class.instance_count_connection_exception(ex)

        raise ex
      end

      # That's required so it knows which GitLab Redis instance
      # it's interacting with in order to categorize accordingly.
      #
      def instrumentation_class
        @options[:instrumentation_class] # rubocop:disable Gitlab/ModuleWithInstanceVariables
      end
    end
  end
end