debian-mirror-gitlab/lib/gitlab/database/background_migration/health_status.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.5 KiB
Ruby
Raw Normal View History

2022-08-13 15:12:31 +05:30
# frozen_string_literal: true
module Gitlab
module Database
module BackgroundMigration
module HealthStatus
2022-08-27 11:52:29 +05:30
DEFAULT_INIDICATORS = [
Indicators::AutovacuumActiveOnTable,
2023-06-20 00:43:36 +05:30
Indicators::WriteAheadLog,
Indicators::PatroniApdex
2022-08-27 11:52:29 +05:30
].freeze
2022-08-13 15:12:31 +05:30
# Rather than passing along the migration, we use a more explicitly defined context
2023-06-20 00:43:36 +05:30
Context = Struct.new(:connection, :tables, :gitlab_schema)
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
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,
2022-10-11 01:57:18 +05:30
job_class_name: migration.job_class_name)
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
Signals::Unknown.new(indicator, reason: "unexpected error: #{e.message} (#{e.class})")
end
2022-08-13 15:12:31 +05:30
2022-08-27 11:52:29 +05:30
log_signal(signal, migration) if signal.log_info?
signal
end
2022-08-13 15:12:31 +05:30
end
def self.log_signal(signal, migration)
2023-07-09 08:55:56 +05:30
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}"
2022-08-13 15:12:31 +05:30
)
end
end
end
end
end