Skip to content

Commit

Permalink
outlier: changing to use statusor
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk committed Dec 11, 2023
1 parent 00fe753 commit f6f5299
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 62 deletions.
6 changes: 4 additions & 2 deletions source/common/upstream/cluster_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ ClusterFactoryImplBase::create(const envoy::config::cluster::v3::Cluster& cluste
}
}

new_cluster_pair.first->setOutlierDetector(Outlier::DetectorImplFactory::createForCluster(
auto detector_or_error = Outlier::DetectorImplFactory::createForCluster(
*new_cluster_pair.first, cluster, server_context.mainThreadDispatcher(),
server_context.runtime(), context.outlierEventLogger(),
server_context.api().randomGenerator()));
server_context.api().randomGenerator());
RETURN_IF_STATUS_NOT_OK(detector_or_error);
new_cluster_pair.first->setOutlierDetector(detector_or_error.value());

return status_or_cluster;
}
Expand Down
6 changes: 3 additions & 3 deletions source/common/upstream/outlier_detection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Envoy {
namespace Upstream {
namespace Outlier {

DetectorSharedPtr DetectorImplFactory::createForCluster(
absl::StatusOr<DetectorSharedPtr> DetectorImplFactory::createForCluster(
Cluster& cluster, const envoy::config::cluster::v3::Cluster& cluster_config,
Event::Dispatcher& dispatcher, Runtime::Loader& runtime, EventLoggerSharedPtr event_logger,
Random::RandomGenerator& random) {
Expand Down Expand Up @@ -284,7 +284,7 @@ DetectorImpl::~DetectorImpl() {
}
}

std::shared_ptr<DetectorImpl>
absl::StatusOr<std::shared_ptr<DetectorImpl>>
DetectorImpl::create(Cluster& cluster, const envoy::config::cluster::v3::OutlierDetection& config,
Event::Dispatcher& dispatcher, Runtime::Loader& runtime,
TimeSource& time_source, EventLoggerSharedPtr event_logger,
Expand All @@ -293,7 +293,7 @@ DetectorImpl::create(Cluster& cluster, const envoy::config::cluster::v3::Outlier
new DetectorImpl(cluster, config, dispatcher, runtime, time_source, event_logger, random));

if (detector->config().maxEjectionTimeMs() < detector->config().baseEjectionTimeMs()) {
throwEnvoyExceptionOrPanic(
return absl::InvalidArgumentError(
"outlier detector's max_ejection_time cannot be smaller than base_ejection_time");
}
detector->initialize(cluster);
Expand Down
4 changes: 2 additions & 2 deletions source/common/upstream/outlier_detection_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace Outlier {
*/
class DetectorImplFactory {
public:
static DetectorSharedPtr
static absl::StatusOr<DetectorSharedPtr>
createForCluster(Cluster& cluster, const envoy::config::cluster::v3::Cluster& cluster_config,
Event::Dispatcher& dispatcher, Runtime::Loader& runtime,
EventLoggerSharedPtr event_logger, Random::RandomGenerator& random);
Expand Down Expand Up @@ -372,7 +372,7 @@ class DetectorConfig {
*/
class DetectorImpl : public Detector, public std::enable_shared_from_this<DetectorImpl> {
public:
static std::shared_ptr<DetectorImpl>
static absl::StatusOr<std::shared_ptr<DetectorImpl>>
create(Cluster& cluster, const envoy::config::cluster::v3::OutlierDetection& config,
Event::Dispatcher& dispatcher, Runtime::Loader& runtime, TimeSource& time_source,
EventLoggerSharedPtr event_logger, Random::RandomGenerator& random);
Expand Down
Loading

0 comments on commit f6f5299

Please sign in to comment.