@@ -117,8 +117,9 @@ void ClusterManagerInitHelper::addCluster(ClusterManagerCluster& cm_cluster) {
117117 ASSERT (state_ != State::AllClustersInitialized);
118118
119119 const auto initialize_cb = [&cm_cluster, this ] {
120- onClusterInit (cm_cluster);
120+ RETURN_IF_NOT_OK ( onClusterInit (cm_cluster) );
121121 cm_cluster.cluster ().info ()->configUpdateStats ().warming_state_ .set (0 );
122+ return absl::OkStatus ();
122123 };
123124 Cluster& cluster = cm_cluster.cluster ();
124125
@@ -142,10 +143,11 @@ void ClusterManagerInitHelper::addCluster(ClusterManagerCluster& cm_cluster) {
142143 primary_init_clusters_.size (), secondary_init_clusters_.size ());
143144}
144145
145- void ClusterManagerInitHelper::onClusterInit (ClusterManagerCluster& cluster) {
146+ absl::Status ClusterManagerInitHelper::onClusterInit (ClusterManagerCluster& cluster) {
146147 ASSERT (state_ != State::AllClustersInitialized);
147- per_cluster_init_callback_ (cluster);
148+ RETURN_IF_NOT_OK ( per_cluster_init_callback_ (cluster) );
148149 removeCluster (cluster);
150+ return absl::OkStatus ();
149151}
150152
151153void ClusterManagerInitHelper::removeCluster (ClusterManagerCluster& cluster) {
@@ -186,7 +188,7 @@ void ClusterManagerInitHelper::initializeSecondaryClusters() {
186188 ClusterManagerCluster* cluster = iter->second ;
187189 ENVOY_LOG (debug, " initializing secondary cluster {}" , iter->first );
188190 ++iter;
189- cluster->cluster ().initialize ([cluster, this ] { onClusterInit (*cluster); });
191+ cluster->cluster ().initialize ([cluster, this ] { return onClusterInit (*cluster); });
190192 }
191193}
192194
@@ -309,15 +311,16 @@ ClusterManagerImpl::ClusterManagerImpl(
309311 AccessLog::AccessLogManager& log_manager, Event::Dispatcher& main_thread_dispatcher,
310312 OptRef<Server::Admin> admin, ProtobufMessage::ValidationContext& validation_context,
311313 Api::Api& api, Http::Context& http_context, Grpc::Context& grpc_context,
312- Router::Context& router_context, Server::Instance& server)
314+ Router::Context& router_context, Server::Instance& server, absl::Status& creation_status )
313315 : server_(server), factory_(factory), runtime_(runtime), stats_(stats), tls_(tls),
314316 random_ (api.randomGenerator()),
315317 deferred_cluster_creation_(bootstrap.cluster_manager().enable_deferred_cluster_creation()),
316318 bind_config_(bootstrap.cluster_manager().has_upstream_bind_config()
317319 ? absl::make_optional(bootstrap.cluster_manager().upstream_bind_config())
318320 : absl::nullopt),
319321 local_info_(local_info), cm_stats_(generateStats(*stats.rootScope())),
320- init_helper_(*this , [this ](ClusterManagerCluster& cluster) { onClusterInit (cluster); }),
322+ init_helper_(*this ,
323+ [this ](ClusterManagerCluster& cluster) { return onClusterInit (cluster); }),
321324 time_source_ (main_thread_dispatcher.timeSource()), dispatcher_(main_thread_dispatcher),
322325 http_context_(http_context), validation_context_(validation_context),
323326 router_context_(router_context), cluster_stat_names_(stats.symbolTable()),
@@ -345,9 +348,10 @@ ClusterManagerImpl::ClusterManagerImpl(
345348 if (cm_config.has_outlier_detection ()) {
346349 const std::string event_log_file_path = cm_config.outlier_detection ().event_log_path ();
347350 if (!event_log_file_path.empty ()) {
348- outlier_event_logger_ = THROW_OR_RETURN_VALUE (
349- Outlier::EventLoggerImpl::create (log_manager, event_log_file_path, time_source_),
350- std::unique_ptr<Outlier::EventLoggerImpl>);
351+ auto outlier_or_error =
352+ Outlier::EventLoggerImpl::create (log_manager, event_log_file_path, time_source_);
353+ SET_AND_RETURN_IF_NOT_OK (outlier_or_error.status (), creation_status);
354+ outlier_event_logger_ = std::move (*outlier_or_error);
351355 }
352356 }
353357
@@ -693,7 +697,7 @@ ClusterManagerImpl::ThreadLocalClusterManagerImpl::generateStats(Stats::Scope& s
693697 return {ALL_THREAD_LOCAL_CLUSTER_MANAGER_STATS (POOL_GAUGE_PREFIX (scope, final_prefix))};
694698}
695699
696- void ClusterManagerImpl::onClusterInit (ClusterManagerCluster& cm_cluster) {
700+ absl::Status ClusterManagerImpl::onClusterInit (ClusterManagerCluster& cm_cluster) {
697701 // This routine is called when a cluster has finished initializing. The cluster has not yet
698702 // been setup for cross-thread updates to avoid needless updates during initialization. The order
699703 // of operations here is important. We start by initializing the thread aware load balancer if
@@ -710,7 +714,7 @@ void ClusterManagerImpl::onClusterInit(ClusterManagerCluster& cm_cluster) {
710714 cluster_data = active_clusters_.find (cluster.info ()->name ());
711715
712716 if (cluster_data->second ->thread_aware_lb_ != nullptr ) {
713- THROW_IF_NOT_OK (cluster_data->second ->thread_aware_lb_ ->initialize ());
717+ RETURN_IF_NOT_OK (cluster_data->second ->thread_aware_lb_ ->initialize ());
714718 }
715719
716720 // Now setup for cross-thread updates.
@@ -793,6 +797,7 @@ void ClusterManagerImpl::onClusterInit(ClusterManagerCluster& cm_cluster) {
793797 // clusters being added/updated. We could gate the below update on hosts being available on
794798 // the cluster or the cluster not already existing, but the special logic is not worth it.
795799 postThreadLocalClusterUpdate (cm_cluster, std::move (params));
800+ return absl::OkStatus ();
796801}
797802
798803bool ClusterManagerImpl::scheduleUpdate (ClusterManagerCluster& cluster, uint32_t priority,
@@ -870,9 +875,10 @@ void ClusterManagerImpl::applyUpdates(ClusterManagerCluster& cluster, uint32_t p
870875 updates.last_updated_ = time_source_.monotonicTime ();
871876}
872877
873- bool ClusterManagerImpl::addOrUpdateCluster (const envoy::config::cluster::v3::Cluster& cluster,
874- const std::string& version_info,
875- const bool avoid_cds_removal) {
878+ absl::StatusOr<bool >
879+ ClusterManagerImpl::addOrUpdateCluster (const envoy::config::cluster::v3::Cluster& cluster,
880+ const std::string& version_info,
881+ const bool avoid_cds_removal) {
876882 // First we need to see if this new config is new or an update to an existing dynamic cluster.
877883 // We don't allow updates to statically configured clusters in the main configuration. We check
878884 // both the warming clusters and the active clusters to see if we need an update or the update
@@ -924,7 +930,7 @@ bool ClusterManagerImpl::addOrUpdateCluster(const envoy::config::cluster::v3::Cl
924930 auto status_or_cluster =
925931 loadCluster (cluster, new_hash, version_info, /* added_via_api=*/ true ,
926932 /* required_for_ads=*/ false , warming_clusters_, avoid_cds_removal);
927- THROW_IF_NOT_OK_REF (status_or_cluster.status ());
933+ RETURN_IF_NOT_OK_REF (status_or_cluster.status ());
928934 const ClusterDataPtr previous_cluster = std::move (status_or_cluster.value ());
929935 auto & cluster_entry = warming_clusters_.at (cluster_name);
930936 cluster_entry->cluster_ ->info ()->configUpdateStats ().warming_state_ .set (1 );
@@ -938,7 +944,7 @@ bool ClusterManagerImpl::addOrUpdateCluster(const envoy::config::cluster::v3::Cl
938944 auto state_changed_cluster_entry = warming_clusters_.find (cluster_name);
939945 state_changed_cluster_entry->second ->cluster_ ->info ()->configUpdateStats ().warming_state_ .set (
940946 0 );
941- onClusterInit (*state_changed_cluster_entry->second );
947+ return onClusterInit (*state_changed_cluster_entry->second );
942948 });
943949 }
944950
@@ -2296,13 +2302,15 @@ void ClusterManagerImpl::ThreadLocalClusterManagerImpl::tcpConnPoolIsIdle(
22962302 }
22972303}
22982304
2299- ClusterManagerPtr ProdClusterManagerFactory::clusterManagerFromProto (
2305+ absl::StatusOr< ClusterManagerPtr> ProdClusterManagerFactory::clusterManagerFromProto (
23002306 const envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
2307+ absl::Status creation_status = absl::OkStatus ();
23012308 auto cluster_manager_impl = std::unique_ptr<ClusterManagerImpl>{new ClusterManagerImpl (
23022309 bootstrap, *this , context_, stats_, tls_, context_.runtime (), context_.localInfo (),
23032310 context_.accessLogManager (), context_.mainThreadDispatcher (), context_.admin (),
23042311 context_.messageValidationContext (), context_.api (), http_context_, context_.grpcContext (),
2305- context_.routerContext (), server_)};
2312+ context_.routerContext (), server_, creation_status)};
2313+ RETURN_IF_NOT_OK (creation_status);
23062314 return cluster_manager_impl;
23072315}
23082316
0 commit comments