Class HealthCheckValve

java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.valves.ValveBase
io.meeds.platform.server.tomcat.healthcheck.HealthCheckValve
All Implemented Interfaces:
MBeanRegistration, org.apache.catalina.Contained, org.apache.catalina.JmxEnabled, org.apache.catalina.Lifecycle, org.apache.catalina.Valve

public final class HealthCheckValve extends org.apache.catalina.valves.ValveBase
A Valve of the Host answering the health check of the platform. It runs before any web application: no filter, no authentication and no HttpSession is involved.
  • 200 when every web application is started, the portal container is started and, unless setDeep(String) says otherwise, what the platform depends on answers: every JDBC pool declared in the global naming resources of the server gives a valid connection, and the Elasticsearch server of the platform answers and is not red. Each is given a few seconds and the result is kept for setCacheSeconds(int)
  • 503 with the reasons otherwise
  • 403 when the caller is not allowed, see setAllow(String), or when the request carries a header set by a reverse proxy (X-Forwarded-For, Forwarded, X-Real-IP, X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-By or Via): a proxy running on the same machine would otherwise make every caller look local. A reverse proxy that forwards /healthcheck without any of them still makes the caller look local: block that path in the proxy, or disable the health check
  • 405 for any method but GET and HEAD
Declare it in the Host, before the RemoteIpValve so that the address is the one of the TCP peer.

Set EXO_HEALTHCHECK=false (or the system property exo.healthcheck) to disable it.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.catalina.Lifecycle

    org.apache.catalina.Lifecycle.SingleUse
  • Field Summary

    Fields inherited from class org.apache.catalina.valves.ValveBase

    asyncSupported, container, containerLog, next, sm

    Fields inherited from interface org.apache.catalina.Lifecycle

    AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    void
    invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)
     
    void
    setAllow(String callers)
     
    void
    setCacheSeconds(int seconds)
     
    void
    setDeep(String checks)
     
    void
     
    void
    setPortalContainer(String containerName)
     
    protected void
     
    protected void
     

    Methods inherited from class org.apache.catalina.valves.ValveBase

    backgroundProcess, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, isAsyncSupported, setAsyncSupported, setContainer, setNext, toString

    Methods inherited from class org.apache.catalina.util.LifecycleMBeanBase

    destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregister

    Methods inherited from class org.apache.catalina.util.LifecycleBase

    addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • HealthCheckValve

      public HealthCheckValve()
  • Method Details

    • setPath

      public void setPath(String uri)
      Parameters:
      uri - URI answered by the valve, /healthcheck by default
    • setAllow

      public void setAllow(String callers)
      Parameters:
      callers - comma separated IP addresses or CIDR networks allowed to call the health check, defaults to the property exo.healthcheck.allow or the variable EXO_HEALTHCHECK_ALLOW, then to 127.0.0.1,::1
    • setPortalContainer

      public void setPortalContainer(String containerName)
      Parameters:
      containerName - name of the portal container that must be started, none to skip the portal container check (the web applications, and unless setDeep(String) says otherwise the database and the search server, are still checked), defaults to the property exo.healthcheck.container or the variable EXO_HEALTHCHECK_CONTAINER, then to portal
    • setDeep

      public void setDeep(String checks)
      Parameters:
      checks - the dependencies checked once the platform is started: true for the databases and the search server, false or none for none, or a comma separated list of database and search. Defaults to the property exo.healthcheck.deep or the variable EXO_HEALTHCHECK_DEEP, then to true
    • setCacheSeconds

      public void setCacheSeconds(int seconds)
      Parameters:
      seconds - seconds the result of the dependencies is kept, 10 by default: however often it is called, the health check asks the dependencies once in that time
    • initInternal

      protected void initInternal() throws org.apache.catalina.LifecycleException
      Overrides:
      initInternal in class org.apache.catalina.valves.ValveBase
      Throws:
      org.apache.catalina.LifecycleException
    • startInternal

      protected void startInternal() throws org.apache.catalina.LifecycleException
      Overrides:
      startInternal in class org.apache.catalina.valves.ValveBase
      Throws:
      org.apache.catalina.LifecycleException
    • stopInternal

      protected void stopInternal() throws org.apache.catalina.LifecycleException
      Overrides:
      stopInternal in class org.apache.catalina.valves.ValveBase
      Throws:
      org.apache.catalina.LifecycleException
    • invoke

      public void invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response) throws IOException, jakarta.servlet.ServletException
      Throws:
      IOException
      jakarta.servlet.ServletException