about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-03-25 21:00:59 +0100
committerGitHub <noreply@github.com>2022-03-25 21:00:59 +0100
commitf65eaa5aae8a71431bdcfb9c49c869cbdbc4da3f (patch)
tree69d73545858c965bfab968c0e7ebfdeba520535a /app/lib
parentb58db8f12eb19787ee3bd1ec8abab21027b3d4ef (diff)
Add admin dashboard checks for Elasticsearch version (#17863)
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/admin/system_check.rb1
-rw-r--r--app/lib/admin/system_check/elasticsearch_check.rb39
2 files changed, 40 insertions, 0 deletions
diff --git a/app/lib/admin/system_check.rb b/app/lib/admin/system_check.rb
index afb20cb47..877a42ef6 100644
--- a/app/lib/admin/system_check.rb
+++ b/app/lib/admin/system_check.rb
@@ -5,6 +5,7 @@ class Admin::SystemCheck
     Admin::SystemCheck::DatabaseSchemaCheck,
     Admin::SystemCheck::SidekiqProcessCheck,
     Admin::SystemCheck::RulesCheck,
+    Admin::SystemCheck::ElasticsearchCheck,
   ].freeze
 
   def self.perform
diff --git a/app/lib/admin/system_check/elasticsearch_check.rb b/app/lib/admin/system_check/elasticsearch_check.rb
new file mode 100644
index 000000000..1b48a5415
--- /dev/null
+++ b/app/lib/admin/system_check/elasticsearch_check.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck
+  def pass?
+    return true unless Chewy.enabled?
+
+    running_version.present? && compatible_version?
+  end
+
+  def message
+    if running_version.present?
+      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))
+    else
+      Admin::SystemCheck::Message.new(:elasticsearch_running_check)
+    end
+  end
+
+  private
+
+  def running_version
+    @running_version ||= begin
+      Chewy.client.info['version']['number']
+    rescue Faraday::ConnectionFailed
+      nil
+    end
+  end
+
+  def required_version
+    '7.x'
+  end
+
+  def compatible_version?
+    Gem::Version.new(running_version) >= Gem::Version.new(required_version)
+  end
+
+  def missing_queues
+    @missing_queues ||= Sidekiq::ProcessSet.new.reduce(SIDEKIQ_QUEUES) { |queues, process| queues - process['queues'] }
+  end
+end