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

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

module Gitlab
  module Database
    module BackgroundMigration
      module HealthStatus
        DEFAULT_INIDICATORS = [
          Indicators::AutovacuumActiveOnTable,
          Indicators::WriteAheadLog,
          Indicators::PatroniApdex
        ].freeze

        # Rather than passing along the migration, we use a more explicitly defined context
        Context = Struct.new(:connection, :tables, :gitlab_schema)

        def self.evaluate(migration, indicators = DEFAULT_INIDICATORS)
          indicators.map do |indicator|
            signal = begin
              indicator.new(migration.health_context).evaluate
            rescue StandardError => e
              Gitlab::ErrorTracking.track_exception(e, migration_id: migration.id,
                                                       job_class_name: migration.job_class_name)

              Signals::Unknown.new(indicator, reason: "unexpected error: #{e.message} (#{e.class})")
            end

            log_signal(signal, migration) if signal.log_info?

            signal
          end
        end

        def self.log_signal(signal, migration)
          Gitlab::BackgroundMigration::Logger.info(
            migration_id: migration.id,
            health_status_indicator: signal.indicator_class.to_s,
            indicator_signal: signal.short_name,
            signal_reason: signal.reason,
            message: "#{migration} signaled: #{signal}"
          )
        end
      end
    end
  end
end