solrsolr4solrcloud

Configure Health Check in Solr 4


How to configure Health Check?

What is Healthcheck file in Solr 4? And how it is used? I'm configuring Solr Cloud and found the reference to this file which should be there, but not found any sample configuration.

Any link / article / example on how to use it is highly appreciated.


Solution

  • Overview

    Here is a good explanation of what the PingRequestHandler/HealthCheck is from the PingRequestHandler Documentation

    Ping Request Handler for reporting SolrCore health to a Load Balancer.

    This handler is designed to be used as the endpoint for an HTTP Load-Balancer to use when checking the "health" or "up status" of a Solr server.

    In it's simplest form, the PingRequestHandler should be configured with some defaults indicating a request that should be executed. If the request succeeds, then the PingRequestHandler will respond back with a simple "OK" status. If the request fails, then the PingRequestHandler will respond back with the corresponding HTTP Error code. Clients (such as load balancers) can be configured to poll the PingRequestHandler monitoring for these types of responses (or for a simple connection failure) to know if there is a problem with the Solr server.

    A more advanced option available, is to configure the handler with a "healthcheckFile" which can be used to enable/disable the PingRequestHandler. This health check file feature can be used as a way to indicate to some Load Balancers that the server should be "removed from rotation" for maintenance, or upgrades, or whatever reason you may wish.

    Configuration

    From the Solr Reference Guide - Major Changes from Solr 3 to Solr 4

    The PingRequestHandler no longer looks for a option in the (legacy) section of solrconfig.xml. If you want to take advantage of this feature, configure a healthcheckFile initialization parameter directly on the PingRequestHandler. As part of this change, relative file paths have been fixed to be resolved against the data directory. The sample solrconfig.xml has an example of this configuration.

    Here is the relevant section from the sample solrconfig.xml:

      <!-- ping/healthcheck -->
      <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
        <lst name="invariants">
          <str name="q">solrpingquery</str>
        </lst>
        <lst name="defaults">
          <str name="echoParams">all</str>
        </lst>
        <!-- An optional feature of the PingRequestHandler is to configure the 
             handler with a "healthcheckFile" which can be used to enable/disable 
             the PingRequestHandler.
             relative paths are resolved against the data dir 
          -->
        <!-- <str name="healthcheckFile">server-enabled.txt</str> -->
      </requestHandler>
    

    Example Usage

    The example usage is best described as the advanced option (last paragraph) under the PingRequestHandler documentation in the Overview section above. I have used this setting in the scenario they describe, where we had two Solr servers that we wanted to load balance. By having the healthcheckFile enabled, we could control from the Solr Admin page whether or not the Solr server would respond to ping requests. When the file is present, it will respond to a ping request and when the file is not present, it will not respond. There will be an Enable/Disable Ping button on the Core Overview Page under the Healthcheck section. See the screenshot below:

    Admin Page Ping Button