2022-03-26 05:00:59 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck
|
2022-07-05 09:41:40 +09:00
|
|
|
def skip?
|
|
|
|
!current_user.can?(:view_devops)
|
|
|
|
end
|
|
|
|
|
2022-03-26 05:00:59 +09:00
|
|
|
def pass?
|
|
|
|
return true unless Chewy.enabled?
|
|
|
|
|
|
|
|
running_version.present? && compatible_version?
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
if running_version.present?
|
2023-01-05 21:44:31 +09:00
|
|
|
Admin::SystemCheck::Message.new(
|
|
|
|
:elasticsearch_version_check,
|
|
|
|
I18n.t(
|
|
|
|
'admin.system_checks.elasticsearch_version_check.version_comparison',
|
|
|
|
running_version: running_version,
|
|
|
|
required_version: required_version
|
|
|
|
)
|
|
|
|
)
|
2022-03-26 05:00:59 +09:00
|
|
|
else
|
|
|
|
Admin::SystemCheck::Message.new(:elasticsearch_running_check)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def running_version
|
|
|
|
@running_version ||= begin
|
2023-01-19 00:21:48 +09:00
|
|
|
Chewy.client.info['version']['number']
|
2023-03-15 12:01:49 +09:00
|
|
|
rescue Faraday::ConnectionFailed, Elasticsearch::Transport::Transport::Error
|
2022-03-26 05:00:59 +09:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-19 00:21:48 +09:00
|
|
|
def compatible_wire_version
|
|
|
|
Chewy.client.info['version']['minimum_wire_compatibility_version']
|
|
|
|
end
|
|
|
|
|
2022-03-26 05:00:59 +09:00
|
|
|
def required_version
|
|
|
|
'7.x'
|
|
|
|
end
|
|
|
|
|
|
|
|
def compatible_version?
|
2022-12-15 23:56:48 +09:00
|
|
|
return false if running_version.nil?
|
2023-01-19 00:21:48 +09:00
|
|
|
|
|
|
|
Gem::Version.new(running_version) >= Gem::Version.new(required_version) ||
|
|
|
|
Gem::Version.new(compatible_wire_version) >= Gem::Version.new(required_version)
|
2022-03-26 05:00:59 +09:00
|
|
|
end
|
|
|
|
end
|