Class: OkComputer::SolrCheck

Inherits:
HttpCheck show all
Defined in:
lib/ok_computer/built_in_checks/solr_check.rb

Overview

This class performs a health check on Solr instance using the admin/ping handler.

Constant Summary

Constants inherited from HttpCheck

HttpCheck::ConnectionFailed

Constants inherited from Check

Check::CheckNotDefined

Instance Attribute Summary collapse

Attributes inherited from HttpCheck

#basic_auth_password, #basic_auth_username, #request_timeout, #url

Attributes inherited from Check

#failure_occurred, #message, #registrant_name, #time

Instance Method Summary collapse

Methods inherited from HttpCheck

#basic_auth_options, #parse_url, #perform_request

Methods inherited from Check

#<=>, #clear, #mark_failure, #mark_message, #run, #success?, #to_json, #to_text, #with_benchmarking

Constructor Details

#initialize(host, request_timeout = 5) ⇒ SolrCheck

Public: Initialize a new Solr check.

host - The hostname of Solr request_timeout - How long to wait to connect before timing out. Defaults to 5 seconds.



11
12
13
14
# File 'lib/ok_computer/built_in_checks/solr_check.rb', line 11

def initialize(host, request_timeout = 5)
  @host = URI(host)
  super("#{host}/admin/ping", request_timeout)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/ok_computer/built_in_checks/solr_check.rb', line 5

def host
  @host
end

Instance Method Details

#checkObject

Public: Return the status of Solr



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ok_computer/built_in_checks/solr_check.rb', line 17

def check
  if ping?
    mark_message "Solr ping reported success"
  else
    mark_failure
    mark_message "Solr ping reported failure"
  end
rescue => e
  mark_failure
  mark_message "Error: '#{e}'"
end

#ping?Boolean

Public: Returns true if Solr’s ping returned OK, otherwise false

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/ok_computer/built_in_checks/solr_check.rb', line 30

def ping?
  response = perform_request
  !!(response =~ Regexp.union(%r(<str name="status">OK</str>), %r("status":"OK")))
end