Line data Source code
1 : #pragma once 2 : 3 : #include <chrono> 4 : #include <cstdint> 5 : #include <functional> 6 : #include <list> 7 : #include <memory> 8 : #include <string> 9 : #include <vector> 10 : 11 : #include "envoy/access_log/access_log.h" 12 : #include "envoy/api/api.h" 13 : #include "envoy/common/random_generator.h" 14 : #include "envoy/config/cluster/v3/cluster.pb.h" 15 : #include "envoy/config/typed_config.h" 16 : #include "envoy/event/dispatcher.h" 17 : #include "envoy/local_info/local_info.h" 18 : #include "envoy/network/dns.h" 19 : #include "envoy/runtime/runtime.h" 20 : #include "envoy/server/admin.h" 21 : #include "envoy/server/factory_context.h" 22 : #include "envoy/server/options.h" 23 : #include "envoy/singleton/manager.h" 24 : #include "envoy/ssl/context.h" 25 : #include "envoy/ssl/context_manager.h" 26 : #include "envoy/stats/stats.h" 27 : #include "envoy/stats/store.h" 28 : #include "envoy/thread_local/thread_local.h" 29 : #include "envoy/upstream/cluster_manager.h" 30 : #include "envoy/upstream/outlier_detection.h" 31 : 32 : namespace Envoy { 33 : namespace Upstream { 34 : 35 : /** 36 : * Context passed to cluster factory to access Envoy resources. Cluster factory should only access 37 : * the rest of the server through this context object. 38 : */ 39 : class ClusterFactoryContext { 40 : public: 41 159 : virtual ~ClusterFactoryContext() = default; 42 : 43 : /** 44 : * @return Server::Configuration::ServerFactoryContext& the server factory context. All the 45 : * server-wide resources should be accessed through this context. 46 : */ 47 : virtual Server::Configuration::ServerFactoryContext& serverFactoryContext() PURE; 48 : 49 : /** 50 : * @return Upstream::ClusterManager& singleton for use by the entire server. 51 : * TODO(wbpcode): clusterManager() of ServerFactoryContext still be invalid when loading 52 : * static cluster. So we need to provide an cluster manager reference here. 53 : * This could be removed after https://github.com/envoyproxy/envoy/issues/26653 is resolved. 54 : */ 55 : virtual Upstream::ClusterManager& clusterManager() PURE; 56 : 57 : /** 58 : * @return ProtobufMessage::ValidationVisitor& validation visitor for cluster configuration 59 : * messages. 60 : */ 61 : virtual ProtobufMessage::ValidationVisitor& messageValidationVisitor() PURE; 62 : 63 : /** 64 : * @return bool flag indicating whether the cluster is added via api. 65 : */ 66 : virtual bool addedViaApi() PURE; 67 : 68 : /** 69 : * @return Network::DnsResolverSharedPtr the dns resolver for the server. 70 : */ 71 : virtual Network::DnsResolverSharedPtr dnsResolver() PURE; 72 : 73 : /** 74 : * @return Ssl::ContextManager& the SSL context manager. 75 : */ 76 : virtual Ssl::ContextManager& sslContextManager() PURE; 77 : 78 : /** 79 : * @return Outlier::EventLoggerSharedPtr sink for outlier detection event logs. 80 : */ 81 : virtual Outlier::EventLoggerSharedPtr outlierEventLogger() PURE; 82 : }; 83 : 84 : /** 85 : * Implemented by cluster and registered via Registry::registerFactory() or the convenience class 86 : * RegisterFactory. 87 : */ 88 : class ClusterFactory : public Config::UntypedFactory { 89 : public: 90 0 : ~ClusterFactory() override = default; 91 : 92 : /** 93 : * Create a new instance of cluster. If the implementation is unable to produce a cluster instance 94 : * with the provided parameters, it should throw an EnvoyException in the case of general error. 95 : * @param cluster supplies the general protobuf configuration for the cluster. 96 : * @param context supplies the cluster's context. 97 : * @return a pair containing the cluster instance as well as an option thread aware load balancer 98 : * if this cluster has an integrated load balancer or an absl::Satus error on failure. 99 : */ 100 : virtual absl::StatusOr<std::pair<ClusterSharedPtr, ThreadAwareLoadBalancerPtr>> 101 : create(const envoy::config::cluster::v3::Cluster& cluster, ClusterFactoryContext& context) PURE; 102 : 103 53 : std::string category() const override { return "envoy.clusters"; } 104 : }; 105 : 106 : } // namespace Upstream 107 : } // namespace Envoy