Skip to content

Commit

Permalink
server: return processContext as optional reference (envoyproxy#8238)
Browse files Browse the repository at this point in the history
Signed-off-by: Elisha Ziskind <[email protected]>
  • Loading branch information
eziskind authored and danzh1989 committed Sep 24, 2019
1 parent bdc4703 commit c2df144
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions include/envoy/server/filter_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ class FactoryContext : public virtual CommonFactoryContext {
virtual Grpc::Context& grpcContext() PURE;

/**
* @return ProcessContext& a reference to the process context.
* @return absl::optional<std::reference_wrapper<ProcessContext>> an optional reference to the
* process context. Will be unset when running in validation mode.
*/
virtual ProcessContext& processContext() PURE;
virtual absl::optional<std::reference_wrapper<ProcessContext>> processContext() PURE;
};

class ListenerFactoryContext : public virtual FactoryContext {
Expand Down
2 changes: 1 addition & 1 deletion include/envoy/server/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Instance {
/**
* @return the server-wide process context.
*/
virtual ProcessContext& processContext() PURE;
virtual absl::optional<std::reference_wrapper<ProcessContext>> processContext() PURE;

/**
* @return ThreadLocal::Instance& the thread local storage engine for the server. This is used to
Expand Down
4 changes: 3 additions & 1 deletion source/server/config_validation/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class ValidationInstance : Logger::Loggable<Logger::Id::main>,
Stats::Store& stats() override { return stats_store_; }
Grpc::Context& grpcContext() override { return grpc_context_; }
Http::Context& httpContext() override { return http_context_; }
ProcessContext& processContext() override { NOT_IMPLEMENTED_GCOVR_EXCL_LINE; }
absl::optional<std::reference_wrapper<ProcessContext>> processContext() override {
return absl::nullopt;
}
ThreadLocal::Instance& threadLocal() override { return thread_local_; }
const LocalInfo::LocalInfo& localInfo() override { return *local_info_; }
TimeSource& timeSource() override { return api_->timeSource(); }
Expand Down
4 changes: 3 additions & 1 deletion source/server/listener_manager_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ class ListenerImpl : public Network::ListenerConfig,
ServerLifecycleNotifier& lifecycleNotifier() override {
return parent_.server_.lifecycleNotifier();
}
ProcessContext& processContext() override { return parent_.server_.processContext(); }
absl::optional<std::reference_wrapper<ProcessContext>> processContext() override {
return parent_.server_.processContext();
}

// Network::DrainDecision
bool drainClose() const override;
Expand Down
4 changes: 3 additions & 1 deletion source/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ class InstanceImpl : Logger::Loggable<Logger::Id::main>,
Stats::Store& stats() override { return stats_store_; }
Grpc::Context& grpcContext() override { return grpc_context_; }
Http::Context& httpContext() override { return http_context_; }
ProcessContext& processContext() override { return *process_context_; }
absl::optional<std::reference_wrapper<ProcessContext>> processContext() override {
return *process_context_;
}
ThreadLocal::Instance& threadLocal() override { return thread_local_; }
const LocalInfo::LocalInfo& localInfo() override { return *local_info_; }
TimeSource& timeSource() override { return time_source_; }
Expand Down
2 changes: 1 addition & 1 deletion test/integration/filters/process_context_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ProcessContextFilterConfig : public Extensions::HttpFilters::Common::Empty
Server::Configuration::FactoryContext& factory_context) override {
return [&factory_context](Http::FilterChainFactoryCallbacks& callbacks) {
callbacks.addStreamFilter(
std::make_shared<ProcessContextFilter>(factory_context.processContext()));
std::make_shared<ProcessContextFilter>(*factory_context.processContext()));
};
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/mocks/server/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class MockInstance : public Instance {
MOCK_METHOD0(stats, Stats::Store&());
MOCK_METHOD0(grpcContext, Grpc::Context&());
MOCK_METHOD0(httpContext, Http::Context&());
MOCK_METHOD0(processContext, ProcessContext&());
MOCK_METHOD0(processContext, absl::optional<std::reference_wrapper<ProcessContext>>());
MOCK_METHOD0(threadLocal, ThreadLocal::Instance&());
MOCK_METHOD0(localInfo, const LocalInfo::LocalInfo&());
MOCK_CONST_METHOD0(statsFlushInterval, std::chrono::milliseconds());
Expand Down Expand Up @@ -470,7 +470,7 @@ class MockFactoryContext : public virtual FactoryContext {
Event::TestTimeSystem& timeSystem() { return time_system_; }
Grpc::Context& grpcContext() override { return grpc_context_; }
Http::Context& httpContext() override { return http_context_; }
MOCK_METHOD0(processContext, ProcessContext&());
MOCK_METHOD0(processContext, absl::optional<std::reference_wrapper<ProcessContext>>());
MOCK_METHOD0(messageValidationVisitor, ProtobufMessage::ValidationVisitor&());
MOCK_METHOD0(api, Api::Api&());

Expand Down
4 changes: 2 additions & 2 deletions test/server/server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ TEST_P(ServerInstanceImplTest, WithProcessContext) {

EXPECT_NO_THROW(initialize("test/server/empty_bootstrap.yaml"));

ProcessContext& context = server_->processContext();
auto& object_from_context = dynamic_cast<TestObject&>(context.get());
auto context = server_->processContext();
auto& object_from_context = dynamic_cast<TestObject&>(context->get().get());
EXPECT_EQ(&object_from_context, &object);
EXPECT_TRUE(object_from_context.boolean_flag_);

Expand Down

0 comments on commit c2df144

Please sign in to comment.