elasticsearch_check.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # frozen_string_literal: true
  2. class Admin::SystemCheck::ElasticsearchCheck < Admin::SystemCheck::BaseCheck
  3. def skip?
  4. !current_user.can?(:view_devops)
  5. end
  6. def pass?
  7. return true unless Chewy.enabled?
  8. running_version.present? && compatible_version?
  9. end
  10. def message
  11. if running_version.present?
  12. Admin::SystemCheck::Message.new(
  13. :elasticsearch_version_check,
  14. I18n.t(
  15. 'admin.system_checks.elasticsearch_version_check.version_comparison',
  16. running_version: running_version,
  17. required_version: required_version
  18. )
  19. )
  20. else
  21. Admin::SystemCheck::Message.new(:elasticsearch_running_check)
  22. end
  23. end
  24. private
  25. def running_version
  26. @running_version ||= begin
  27. Chewy.client.info['version']['number']
  28. rescue Faraday::ConnectionFailed, Elasticsearch::Transport::Transport::Error
  29. nil
  30. end
  31. end
  32. def compatible_wire_version
  33. Chewy.client.info['version']['minimum_wire_compatibility_version']
  34. end
  35. def required_version
  36. '7.x'
  37. end
  38. def compatible_version?
  39. return false if running_version.nil?
  40. Gem::Version.new(running_version) >= Gem::Version.new(required_version) ||
  41. Gem::Version.new(compatible_wire_version) >= Gem::Version.new(required_version)
  42. end
  43. end