-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logger: Create only one Context per process for mobile #38149
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
#include "source/common/api/os_sys_calls_impl.h" | ||
#include "source/common/common/lock_guard.h" | ||
#include "source/common/common/logger.h" | ||
#include "source/common/common/thread.h" | ||
#include "source/common/common/utility.h" | ||
#include "source/common/http/http_server_properties_cache_manager_impl.h" | ||
#include "source/common/network/io_socket_handle_impl.h" | ||
|
@@ -19,6 +21,17 @@ constexpr absl::Duration ENGINE_RUNNING_TIMEOUT = absl::Seconds(30); | |
// Google DNS address used for IPv6 probes. | ||
constexpr absl::string_view IPV6_PROBE_ADDRESS = "2001:4860:4860::8888"; | ||
constexpr uint32_t IPV6_PROBE_PORT = 53; | ||
|
||
// There is only one shared static Logger::Context instance for all Envoy Mobile engines. | ||
// This helps avoid issues on Logger::Context destruction when the previous saved context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the essence of this problem that Envoy-Mobile does not have access to make changes in main()? How does it handle things like ProcessWIde? Note that ProcessWide was invented after this whole thing I did long ago with MainCommon and tbe logger context. Maybe we can lean on that more and clean some of this stuff up, so there's just one way to initalize all the things that need to be done once per process, rather than having Logger::Context be special. What I'd like to see is most of this stuff is normally owned in main() or similar, without singletons for the most part. But if E-M is special cause it doesn't get any access to main, then there can be one ProcessWide singleton specific to E-M. |
||
// could be activated in a thread-unsafe manner. | ||
void initOnceLoggerContext(const OptionsImplBase& options) { | ||
static Thread::MutexBasicLockable* log_lock = new Thread::MutexBasicLockable(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: MUTABLE_CONSTRUCT_ON_FIRST_USE if we can make that work, just for consistency. |
||
static Logger::Context* context = | ||
new Logger::Context(options.logLevel(), options.logFormat(), *log_lock, | ||
options.logFormatEscaped(), options.enableFineGrainLogging()); | ||
UNREFERENCED_PARAMETER(context); | ||
} | ||
} // namespace | ||
|
||
static std::atomic<envoy_stream_t> current_stream_handle_{0}; | ||
|
@@ -90,15 +103,16 @@ envoy_status_t InternalEngine::cancelStream(envoy_stream_t stream) { | |
// This function takes a `std::shared_ptr` instead of `std::unique_ptr` because `std::function` is a | ||
// copy-constructible type, so it's not possible to move capture `std::unique_ptr` with | ||
// `std::function`. | ||
envoy_status_t InternalEngine::run(std::shared_ptr<Envoy::OptionsImplBase> options) { | ||
envoy_status_t InternalEngine::run(std::shared_ptr<OptionsImplBase> options) { | ||
initOnceLoggerContext(*options); | ||
Thread::Options thread_options; | ||
thread_options.priority_ = thread_priority_; | ||
main_thread_ = thread_factory_->createThread([this, options]() mutable -> void { main(options); }, | ||
thread_options, /* crash_on_failure= */ false); | ||
return (main_thread_ != nullptr) ? ENVOY_SUCCESS : ENVOY_FAILURE; | ||
} | ||
|
||
envoy_status_t InternalEngine::main(std::shared_ptr<Envoy::OptionsImplBase> options) { | ||
envoy_status_t InternalEngine::main(std::shared_ptr<OptionsImplBase> options) { | ||
// Using unique_ptr ensures main_common's lifespan is strictly scoped to this function. | ||
std::unique_ptr<EngineCommon> main_common; | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is a good use-case for
auto
as the type is obvious from context.