LCOV - code coverage report
Current view: top level - envoy/upstream - health_checker.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 2 2 100.0 %
Date: 2024-01-05 06:35:25 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <functional>
       4             : #include <memory>
       5             : 
       6             : #include "envoy/data/core/v3/health_check_event.pb.h"
       7             : #include "envoy/upstream/upstream.h"
       8             : 
       9             : namespace Envoy {
      10             : namespace Upstream {
      11             : 
      12             : enum class HealthState { Unhealthy, Healthy };
      13             : 
      14             : enum class HealthTransition {
      15             :   /**
      16             :    * Used when the health state of a host hasn't changed.
      17             :    */
      18             :   Unchanged,
      19             :   /**
      20             :    * Used when the health state of a host has changed.
      21             :    */
      22             :   Changed,
      23             :   /**
      24             :    * Used when the health check result differs from the health state of a host, but a change to the
      25             :    * latter is delayed due to healthy/unhealthy threshold settings.
      26             :    */
      27             :   ChangePending
      28             : };
      29             : 
      30             : /**
      31             :  * Wraps active health checking of an upstream cluster.
      32             :  */
      33             : class HealthChecker {
      34             : public:
      35          50 :   virtual ~HealthChecker() = default;
      36             : 
      37             :   /**
      38             :    * Called when a host has been health checked.
      39             :    * @param host supplies the host that was just health checked.
      40             :    * @param changed_state supplies whether the health check resulted in a host moving from healthy
      41             :    *                       to not healthy or vice versa.
      42             :    */
      43             :   using HostStatusCb =
      44             :       std::function<void(const HostSharedPtr& host, HealthTransition changed_state)>;
      45             : 
      46             :   /**
      47             :    * Install a callback that will be invoked every time a health check round is completed for
      48             :    * a host. The host's health check state may not have changed.
      49             :    * @param callback supplies the callback to invoke.
      50             :    */
      51             :   virtual void addHostCheckCompleteCb(HostStatusCb callback) PURE;
      52             : 
      53             :   /**
      54             :    * Start cyclic health checking based on the provided settings and the type of health checker.
      55             :    */
      56             :   virtual void start() PURE;
      57             : };
      58             : 
      59             : using HealthCheckerSharedPtr = std::shared_ptr<HealthChecker>;
      60             : 
      61             : std::ostream& operator<<(std::ostream& out, HealthState state);
      62             : std::ostream& operator<<(std::ostream& out, HealthTransition changed_state);
      63             : 
      64             : /**
      65             :  * Sink for health check event logs.
      66             :  */
      67             : class HealthCheckEventLogger {
      68             : public:
      69          50 :   virtual ~HealthCheckEventLogger() = default;
      70             : 
      71             :   /**
      72             :    * Log an unhealthy host ejection event.
      73             :    * @param health_checker_type supplies the type of health checker that generated the event.
      74             :    * @param host supplies the host that generated the event.
      75             :    * @param failure_type supplies the type of health check failure.
      76             :    */
      77             :   virtual void logEjectUnhealthy(envoy::data::core::v3::HealthCheckerType health_checker_type,
      78             :                                  const HostDescriptionConstSharedPtr& host,
      79             :                                  envoy::data::core::v3::HealthCheckFailureType failure_type) PURE;
      80             : 
      81             :   /**
      82             :    * Log an unhealthy host event.
      83             :    * @param health_checker_type supplies the type of health checker that generated the event.
      84             :    * @param host supplies the host that generated the event.
      85             :    * @param failure_type supplies the type of health check failure.
      86             :    * @param first_check whether this is a failure on the first health check for this host.
      87             :    */
      88             :   virtual void logUnhealthy(envoy::data::core::v3::HealthCheckerType health_checker_type,
      89             :                             const HostDescriptionConstSharedPtr& host,
      90             :                             envoy::data::core::v3::HealthCheckFailureType failure_type,
      91             :                             bool first_check) PURE;
      92             : 
      93             :   /**
      94             :    * Log a healthy host addition event.
      95             :    * @param health_checker_type supplies the type of health checker that generated the event.
      96             :    * @param host supplies the host that generated the event.
      97             :    * @param healthy_threshold supplied the configured healthy threshold for this health check.
      98             :    * @param first_check whether this is a fast path success on the first health check for this host.
      99             :    */
     100             :   virtual void logAddHealthy(envoy::data::core::v3::HealthCheckerType health_checker_type,
     101             :                              const HostDescriptionConstSharedPtr& host, bool first_check) PURE;
     102             : 
     103             :   /**
     104             :    * Log a degraded healthy host event.
     105             :    * @param health_checker_type supplies the type of health checker that generated the event.
     106             :    * @param host supplies the host that generated the event.
     107             :    */
     108             :   virtual void logDegraded(envoy::data::core::v3::HealthCheckerType health_checker_type,
     109             :                            const HostDescriptionConstSharedPtr& host) PURE;
     110             :   /**
     111             :    * Log a no degraded healthy host event.
     112             :    * @param health_checker_type supplies the type of health checker that generated the event.
     113             :    * @param host supplies the host that generated the event.
     114             :    */
     115             :   virtual void logNoLongerDegraded(envoy::data::core::v3::HealthCheckerType health_checker_type,
     116             :                                    const HostDescriptionConstSharedPtr& host) PURE;
     117             : };
     118             : 
     119             : using HealthCheckEventLoggerPtr = std::unique_ptr<HealthCheckEventLogger>;
     120             : 
     121             : } // namespace Upstream
     122             : } // namespace Envoy

Generated by: LCOV version 1.15