about summary refs log tree commit diff
path: root/app/lib/admin
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2021-04-03 14:12:30 +0200
committerGitHub <noreply@github.com>2021-04-03 14:12:30 +0200
commit487e37d6d46d81caac54c536791ad1a16a4eb267 (patch)
treedba259c8f056222a839e372e934f4c742f4998cb /app/lib/admin
parent82cce18227419a55a12e34652a944fd612a86891 (diff)
Add system checks to dashboard in admin UI (#15989)
Diffstat (limited to 'app/lib/admin')
-rw-r--r--app/lib/admin/system_check.rb21
-rw-r--r--app/lib/admin/system_check/base_check.rb11
-rw-r--r--app/lib/admin/system_check/database_schema_check.rb11
-rw-r--r--app/lib/admin/system_check/message.rb11
-rw-r--r--app/lib/admin/system_check/rules_check.rb13
-rw-r--r--app/lib/admin/system_check/sidekiq_process_check.rb26
6 files changed, 93 insertions, 0 deletions
diff --git a/app/lib/admin/system_check.rb b/app/lib/admin/system_check.rb
new file mode 100644
index 000000000..afb20cb47
--- /dev/null
+++ b/app/lib/admin/system_check.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck
+  ACTIVE_CHECKS = [
+    Admin::SystemCheck::DatabaseSchemaCheck,
+    Admin::SystemCheck::SidekiqProcessCheck,
+    Admin::SystemCheck::RulesCheck,
+  ].freeze
+
+  def self.perform
+    ACTIVE_CHECKS.each_with_object([]) do |klass, arr|
+      check = klass.new
+
+      if check.pass?
+        arr
+      else
+        arr << check.message
+      end
+    end
+  end
+end
diff --git a/app/lib/admin/system_check/base_check.rb b/app/lib/admin/system_check/base_check.rb
new file mode 100644
index 000000000..fcad8daca
--- /dev/null
+++ b/app/lib/admin/system_check/base_check.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::BaseCheck
+  def pass?
+    raise NotImplementedError
+  end
+
+  def message
+    raise NotImplementedError
+  end
+end
diff --git a/app/lib/admin/system_check/database_schema_check.rb b/app/lib/admin/system_check/database_schema_check.rb
new file mode 100644
index 000000000..b93d1954e
--- /dev/null
+++ b/app/lib/admin/system_check/database_schema_check.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::DatabaseSchemaCheck < Admin::SystemCheck::BaseCheck
+  def pass?
+    !ActiveRecord::Base.connection.migration_context.needs_migration?
+  end
+
+  def message
+    Admin::SystemCheck::Message.new(:database_schema_check)
+  end
+end
diff --git a/app/lib/admin/system_check/message.rb b/app/lib/admin/system_check/message.rb
new file mode 100644
index 000000000..bfcad3bf3
--- /dev/null
+++ b/app/lib/admin/system_check/message.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::Message
+  attr_reader :key, :value, :action
+
+  def initialize(key, value = nil, action = nil)
+    @key    = key
+    @value  = value
+    @action = action
+  end
+end
diff --git a/app/lib/admin/system_check/rules_check.rb b/app/lib/admin/system_check/rules_check.rb
new file mode 100644
index 000000000..1fbdf955d
--- /dev/null
+++ b/app/lib/admin/system_check/rules_check.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::RulesCheck < Admin::SystemCheck::BaseCheck
+  include RoutingHelper
+
+  def pass?
+    Rule.kept.exists?
+  end
+
+  def message
+    Admin::SystemCheck::Message.new(:rules_check, nil, admin_rules_path)
+  end
+end
diff --git a/app/lib/admin/system_check/sidekiq_process_check.rb b/app/lib/admin/system_check/sidekiq_process_check.rb
new file mode 100644
index 000000000..c44d86c44
--- /dev/null
+++ b/app/lib/admin/system_check/sidekiq_process_check.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+class Admin::SystemCheck::SidekiqProcessCheck < Admin::SystemCheck::BaseCheck
+  SIDEKIQ_QUEUES = %w(
+    default
+    push
+    mailers
+    pull
+    scheduler
+    ingress
+  ).freeze
+
+  def pass?
+    missing_queues.empty?
+  end
+
+  def message
+    Admin::SystemCheck::Message.new(:sidekiq_process_check, missing_queues.join(', '))
+  end
+
+  private
+
+  def missing_queues
+    @missing_queues ||= Sidekiq::ProcessSet.new.reduce(SIDEKIQ_QUEUES) { |queues, process| queues - process['queues'] }
+  end
+end