LCOV - code coverage report
Current view: top level - source/extensions/common/redis - cluster_refresh_manager.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 2 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 2 0.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <chrono>
       4             : #include <cstdint>
       5             : #include <functional>
       6             : #include <memory>
       7             : #include <string>
       8             : 
       9             : #include "envoy/common/pure.h"
      10             : 
      11             : namespace Envoy {
      12             : namespace Extensions {
      13             : namespace Common {
      14             : namespace Redis {
      15             : 
      16             : using RefreshCB = std::function<void()>;
      17             : 
      18             : /**
      19             :  * A manager for tracking events that would trigger a cluster refresh, and calling registered
      20             :  * callbacks when the error rate exceeds a configurable threshold (while ensuring that a minimum
      21             :  * time passes between calling the callback).
      22             :  */
      23             : class ClusterRefreshManager {
      24             : public:
      25             :   class Handle {
      26             :   public:
      27           0 :     virtual ~Handle() = default;
      28             :   };
      29             : 
      30             :   using HandlePtr = std::unique_ptr<Handle>;
      31             : 
      32           0 :   virtual ~ClusterRefreshManager() = default;
      33             : 
      34             :   /**
      35             :    * Notifies the manager that a redirection error has been received for a given cluster.
      36             :    * @param cluster_name is the name of the cluster.
      37             :    * @return bool true if a cluster's registered callback is scheduled on the main thread, false
      38             :    * otherwise.
      39             :    */
      40             :   virtual bool onRedirection(const std::string& cluster_name) PURE;
      41             : 
      42             :   /**
      43             :    * Notifies the manager that a failure has been received for a given cluster.
      44             :    * @param cluster_name is the name of the cluster.
      45             :    * @return bool true if a cluster's registered callback is scheduled on the main thread, false
      46             :    * otherwise.
      47             :    */
      48             :   virtual bool onFailure(const std::string& cluster_name) PURE;
      49             : 
      50             :   /**
      51             :    * Notifies the manager that a degraded host has been used for a given cluster.
      52             :    * @param cluster_name is the name of the cluster.
      53             :    * @return bool true if a cluster's registered callback is scheduled on the main thread, false
      54             :    * otherwise.
      55             :    */
      56             :   virtual bool onHostDegraded(const std::string& cluster_name) PURE;
      57             : 
      58             :   /**
      59             :    * Register a cluster to be tracked by the manager (called by main thread only).
      60             :    * @param cluster_name is the name of the cluster.
      61             :    * @param min_time_between_triggering is the minimum amount of time that must pass between
      62             :    * callback invocations (redirects ignored and not counted during this time).
      63             :    * @param redirects_threshold is the number of redirects that must be reached to consider
      64             :    * calling the callback.
      65             :    * @param cb is the cluster callback function.
      66             :    * @return HandlePtr is a smart pointer to an opaque Handle that will unregister the cluster upon
      67             :    * destruction.
      68             :    */
      69             :   virtual HandlePtr registerCluster(const std::string& cluster_name,
      70             :                                     std::chrono::milliseconds min_time_between_triggering,
      71             :                                     const uint32_t redirects_threshold,
      72             :                                     const uint32_t failure_threshold,
      73             :                                     const uint32_t host_degraded_threshold,
      74             :                                     const RefreshCB& cb) PURE;
      75             : };
      76             : 
      77             : using ClusterRefreshManagerSharedPtr = std::shared_ptr<ClusterRefreshManager>;
      78             : 
      79             : } // namespace Redis
      80             : } // namespace Common
      81             : } // namespace Extensions
      82             : } // namespace Envoy

Generated by: LCOV version 1.15