From 2f8f92df48326c7ae61679773e64afca46d9a374 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 3 Oct 2023 09:52:47 -0400 Subject: [PATCH] Fix Elastic check deprecation warning about gem version (#27262) --- .../admin/system_check/elasticsearch_check.rb | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/lib/admin/system_check/elasticsearch_check.rb b/app/lib/admin/system_check/elasticsearch_check.rb index 406bb5bcb9..ea35807f30 100644 --- a/app/lib/admin/system_check/elasticsearch_check.rb +++ b/app/lib/admin/system_check/elasticsearch_check.rb @@ -76,14 +76,35 @@ class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck end def compatible_version? - return false if running_version.nil? - - Gem::Version.new(running_version) >= Gem::Version.new(required_version) || - Gem::Version.new(compatible_wire_version) >= Gem::Version.new(required_version) + running_version_ok? || compatible_wire_version_ok? rescue ArgumentError false end + def running_version_ok? + return false if running_version.blank? + + gem_version_running >= gem_version_required + end + + def compatible_wire_version_ok? + return false if compatible_wire_version.blank? + + gem_version_compatible_wire >= gem_version_required + end + + def gem_version_running + Gem::Version.new(running_version) + end + + def gem_version_required + Gem::Version.new(required_version) + end + + def gem_version_compatible_wire + Gem::Version.new(compatible_wire_version) + end + def mismatched_indexes @mismatched_indexes ||= INDEXES.filter_map do |klass| klass.base_name if Chewy.client.indices.get_mapping[klass.index_name]&.deep_symbolize_keys != klass.mappings_hash