Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/api/api.h" 4 : #include "envoy/config/core/v3/health_check.pb.h" 5 : #include "envoy/data/core/v3/health_check_event.pb.h" 6 : #include "envoy/extensions/health_checkers/thrift/v3/thrift.pb.h" 7 : 8 : #include "source/extensions/filters/network/thrift_proxy/config.h" 9 : #include "source/extensions/health_checkers/common/health_checker_base_impl.h" 10 : #include "source/extensions/health_checkers/thrift/client.h" 11 : 12 : namespace Envoy { 13 : namespace Extensions { 14 : namespace HealthCheckers { 15 : namespace ThriftHealthChecker { 16 : 17 : using namespace Envoy::Extensions::NetworkFilters; 18 : using namespace Envoy::Extensions::NetworkFilters::ThriftProxy; 19 : 20 : /** 21 : * Thrift health checker implementation. 22 : */ 23 : class ThriftHealthChecker : public Upstream::HealthCheckerImplBase { 24 : public: 25 : ThriftHealthChecker(const Upstream::Cluster& cluster, 26 : const envoy::config::core::v3::HealthCheck& config, 27 : const envoy::extensions::health_checkers::thrift::v3::Thrift& thrift_config, 28 : Event::Dispatcher& dispatcher, Runtime::Loader& runtime, 29 : Upstream::HealthCheckEventLoggerPtr&& event_logger, Api::Api& api, 30 : ClientFactory& client_factory); 31 : 32 : protected: 33 0 : envoy::data::core::v3::HealthCheckerType healthCheckerType() const override { 34 0 : return envoy::data::core::v3::THRIFT; 35 0 : } 36 : 37 : private: 38 : class ThriftActiveHealthCheckSession : public ActiveHealthCheckSession, public ClientCallback { 39 : public: 40 : ThriftActiveHealthCheckSession(ThriftHealthChecker& parent, 41 : const Upstream::HostSharedPtr& host); 42 : ~ThriftActiveHealthCheckSession() override; 43 : 44 : // ClientCallback 45 : void onResponseResult(bool is_success) override; 46 : Upstream::Host::CreateConnectionData createConnection() override; 47 : 48 : // ActiveHealthCheckSession 49 : void onInterval() override; 50 : void onTimeout() override; 51 : void onDeferredDelete() final; 52 : 53 : // Network::ConnectionCallbacks in ClientCallback 54 : void onEvent(Network::ConnectionEvent event) override; 55 0 : void onAboveWriteBufferHighWatermark() override {} 56 0 : void onBelowWriteBufferLowWatermark() override {} 57 : 58 : private: 59 : ThriftHealthChecker& parent_; 60 : const std::string& hostname_; 61 : ClientPtr client_; 62 : bool expect_close_{}; 63 : }; 64 : 65 : using ThriftActiveHealthCheckSessionPtr = std::unique_ptr<ThriftActiveHealthCheckSession>; 66 : 67 : // HealthCheckerImplBase 68 0 : ActiveHealthCheckSessionPtr makeSession(Upstream::HostSharedPtr host) override { 69 0 : return std::make_unique<ThriftActiveHealthCheckSession>(*this, host); 70 0 : } 71 : 72 : const std::string method_name_; 73 : const TransportType transport_; 74 : const ProtocolType protocol_; 75 : ClientFactory& client_factory_; 76 : }; 77 : 78 : } // namespace ThriftHealthChecker 79 : } // namespace HealthCheckers 80 : } // namespace Extensions 81 : } // namespace Envoy