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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <chrono>
       4             : #include <functional>
       5             : #include <vector>
       6             : 
       7             : #include "envoy/common/time.h"
       8             : #include "envoy/config/listener/v3/listener.pb.h"
       9             : #include "envoy/event/dispatcher.h"
      10             : #include "envoy/event/timer.h"
      11             : #include "envoy/server/drain_manager.h"
      12             : #include "envoy/server/instance.h"
      13             : 
      14             : #include "source/common/common/callback_impl.h"
      15             : #include "source/common/common/logger.h"
      16             : 
      17             : namespace Envoy {
      18             : namespace Server {
      19             : 
      20             : /**
      21             :  * Implementation of drain manager that does the following by default:
      22             :  * 1) Terminates the parent process after 15 minutes.
      23             :  * 2) Drains the parent process over a period of 10 minutes where drain close becomes more
      24             :  *    likely each second that passes.
      25             :  */
      26             : class DrainManagerImpl : Logger::Loggable<Logger::Id::main>, public DrainManager {
      27             : public:
      28             :   DrainManagerImpl(Instance& server, envoy::config::listener::v3::Listener::DrainType drain_type,
      29             :                    Event::Dispatcher& dispatcher);
      30             : 
      31             :   // Network::DrainDecision
      32             :   bool drainClose() const override;
      33             :   Common::CallbackHandlePtr addOnDrainCloseCb(DrainCloseCb cb) const override;
      34             : 
      35             :   // Server::DrainManager
      36             :   void startDrainSequence(std::function<void()> drain_complete_cb) override;
      37           0 :   bool draining() const override { return draining_; }
      38             :   void startParentShutdownSequence() override;
      39             :   DrainManagerPtr
      40             :   createChildManager(Event::Dispatcher& dispatcher,
      41             :                      envoy::config::listener::v3::Listener::DrainType drain_type) override;
      42             :   DrainManagerPtr createChildManager(Event::Dispatcher& dispatcher) override;
      43             : 
      44             : private:
      45             :   void addDrainCompleteCallback(std::function<void()> cb);
      46             : 
      47             :   Instance& server_;
      48             :   Event::Dispatcher& dispatcher_;
      49             :   const envoy::config::listener::v3::Listener::DrainType drain_type_;
      50             : 
      51             :   std::atomic<bool> draining_{false};
      52             :   Event::TimerPtr drain_tick_timer_;
      53             :   MonotonicTime drain_deadline_;
      54             :   mutable Common::CallbackManager<std::chrono::milliseconds> cbs_{};
      55             :   std::vector<std::function<void()>> drain_complete_cbs_{};
      56             : 
      57             :   // Callbacks called by startDrainSequence to cascade/proxy to children
      58             :   std::shared_ptr<Common::ThreadSafeCallbackManager> children_;
      59             : 
      60             :   // Callback handle parent will invoke to initiate drain-sequence. Created and set
      61             :   // by the parent drain-manager.
      62             :   Common::CallbackHandlePtr parent_callback_handle_;
      63             : 
      64             :   Event::TimerPtr parent_shutdown_timer_;
      65             : };
      66             : 
      67             : } // namespace Server
      68             : } // namespace Envoy

Generated by: LCOV version 1.15