From 3cce275d5c9c099bb026150944a19335597e4a07 Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Wed, 27 Mar 2019 16:49:18 -0700 Subject: [PATCH 01/12] Removes capturing env by reference in main --- onnxruntime/hosting/main.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/onnxruntime/hosting/main.cc b/onnxruntime/hosting/main.cc index 0218a06530987..7385ebd955487 100644 --- a/onnxruntime/hosting/main.cc +++ b/onnxruntime/hosting/main.cc @@ -32,14 +32,14 @@ int main(int argc, char* argv[]) { hosting::App app{}; app.RegisterStartup( - [&env](const auto& details) -> void { + [env](const auto& details) -> void { auto logger = env->GetLogger(); LOGS(logger, VERBOSE) << "Listening at: " << "http://" << details.address << ":" << details.port; }); app.RegisterError( - [&env](auto& context) -> void { + [env](auto& context) -> void { auto logger = env->GetLogger(); LOGS(logger, VERBOSE) << "Error code: " << context.error_code; LOGS(logger, VERBOSE) << "Error message: " << context.error_message; @@ -48,10 +48,11 @@ int main(int argc, char* argv[]) { context.response.body() = hosting::CreateJsonError(context.error_code, context.error_message); }); - app.RegisterPost(R"(/v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict))", - [env](const auto& name, const auto& version, const auto& action, auto& context) -> void { - hosting::Predict(name, version, action, context, env); - }); + app.RegisterPost( + R"(/v1/models/([^/:]+)(?:/versions/(\d+))?:(classify|regress|predict))", + [env](const auto& name, const auto& version, const auto& action, auto& context) -> void { + hosting::Predict(name, version, action, context, env); + }); app.Bind(boost_address, config.http_port) .NumThreads(config.num_http_threads) From cdf5fde4c32c5b590ea83326a4ba5c030887abad Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Fri, 29 Mar 2019 17:17:50 +0000 Subject: [PATCH 02/12] Uses CreateLogger() instead of DefaultLogger() --- onnxruntime/hosting/environment.cc | 6 +++--- onnxruntime/hosting/environment.h | 2 +- onnxruntime/hosting/http/predict_request_handler.cc | 6 +++--- onnxruntime/hosting/main.cc | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index f7323217f11ff..92d408a336d88 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -23,8 +23,8 @@ HostingEnvironment::HostingEnvironment() : logger_id_("HostingLog"), session_ = std::make_shared(options_, &default_logging_manager_); } -const onnxruntime::logging::Logger& HostingEnvironment::GetLogger() { - return this->default_logging_manager_.DefaultLogger(); +std::shared_ptr HostingEnvironment::GetLogger() { + return this->default_logging_manager_.CreateLogger("1234"); } std::shared_ptr HostingEnvironment::GetSession() const { @@ -32,4 +32,4 @@ std::shared_ptr HostingEnvironment::GetSession() } } // namespace hosting -} // namespace onnxruntime \ No newline at end of file +} // namespace onnxruntime diff --git a/onnxruntime/hosting/environment.h b/onnxruntime/hosting/environment.h index 9e4af9a8bf844..7aace0aefcfa8 100644 --- a/onnxruntime/hosting/environment.h +++ b/onnxruntime/hosting/environment.h @@ -19,7 +19,7 @@ class HostingEnvironment { HostingEnvironment(); HostingEnvironment(const HostingEnvironment&) = delete; - const onnxruntime::logging::Logger& GetLogger(); + std::shared_ptr GetLogger(); std::shared_ptr GetSession() const; private: diff --git a/onnxruntime/hosting/http/predict_request_handler.cc b/onnxruntime/hosting/http/predict_request_handler.cc index 11efc3f7701dd..85efc09fc5976 100644 --- a/onnxruntime/hosting/http/predict_request_handler.cc +++ b/onnxruntime/hosting/http/predict_request_handler.cc @@ -17,9 +17,9 @@ void Predict(const std::string& name, PredictRequest predictRequest{}; auto logger = env->GetLogger(); - LOGS(logger, VERBOSE) << "Name: " << name; - LOGS(logger, VERBOSE) << "Version: " << version; - LOGS(logger, VERBOSE) << "Action: " << action; + LOGS(*logger, VERBOSE) << "Name: " << name; + LOGS(*logger, VERBOSE) << "Version: " << version; + LOGS(*logger, VERBOSE) << "Action: " << action; auto body = context.request.body(); auto status = GetRequestFromJson(body, predictRequest); diff --git a/onnxruntime/hosting/main.cc b/onnxruntime/hosting/main.cc index 7385ebd955487..fba5b759005be 100644 --- a/onnxruntime/hosting/main.cc +++ b/onnxruntime/hosting/main.cc @@ -22,10 +22,10 @@ int main(int argc, char* argv[]) { auto env = std::make_shared(); auto logger = env->GetLogger(); - LOGS(logger, VERBOSE) << "Logging manager initialized."; - LOGS(logger, VERBOSE) << "Model path: " << config.model_path; + LOGS(*logger, VERBOSE) << "Logging manager initialized."; + LOGS(*logger, VERBOSE) << "Model path: " << config.model_path; auto status = env->GetSession()->Load(config.model_path); - LOGS(logger, VERBOSE) << "Load Model Status: " << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]"; + LOGS(*logger, VERBOSE) << "Load Model Status: " << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]"; auto const boost_address = boost::asio::ip::make_address(config.address); @@ -34,15 +34,15 @@ int main(int argc, char* argv[]) { app.RegisterStartup( [env](const auto& details) -> void { auto logger = env->GetLogger(); - LOGS(logger, VERBOSE) << "Listening at: " + LOGS(*logger, VERBOSE) << "Listening at: " << "http://" << details.address << ":" << details.port; }); app.RegisterError( [env](auto& context) -> void { auto logger = env->GetLogger(); - LOGS(logger, VERBOSE) << "Error code: " << context.error_code; - LOGS(logger, VERBOSE) << "Error message: " << context.error_message; + LOGS(*logger, VERBOSE) << "Error code: " << context.error_code; + LOGS(*logger, VERBOSE) << "Error message: " << context.error_message; context.response.result(context.error_code); context.response.body() = hosting::CreateJsonError(context.error_code, context.error_message); From 2c35c46fb1d737f104b03cdf6ac3092ee4d25484 Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Fri, 29 Mar 2019 17:15:47 -0700 Subject: [PATCH 03/12] Use logger_id_ instead of random digits --- onnxruntime/hosting/environment.cc | 2 +- onnxruntime/hosting/server_configuration.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index 92d408a336d88..064b0c7bf8c88 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -24,7 +24,7 @@ HostingEnvironment::HostingEnvironment() : logger_id_("HostingLog"), } std::shared_ptr HostingEnvironment::GetLogger() { - return this->default_logging_manager_.CreateLogger("1234"); + return this->default_logging_manager_.CreateLogger(logger_id_); } std::shared_ptr HostingEnvironment::GetSession() const { diff --git a/onnxruntime/hosting/server_configuration.h b/onnxruntime/hosting/server_configuration.h index 9ab742e2f7102..997405054fac5 100644 --- a/onnxruntime/hosting/server_configuration.h +++ b/onnxruntime/hosting/server_configuration.h @@ -12,9 +12,9 @@ namespace onnxruntime { namespace hosting { -enum Result { ExitSuccess = 1, - ExitFailure, - ContinueSuccess }; +enum class Result { ExitSuccess = 1, + ExitFailure, + ContinueSuccess }; namespace po = boost::program_options; From a4fdf1c0725bc526f546d987400203d3342855ab Mon Sep 17 00:00:00 2001 From: Trent McCormick Date: Sat, 30 Mar 2019 14:11:35 -0700 Subject: [PATCH 04/12] Uses uuid for logging ids --- onnxruntime/hosting/environment.cc | 8 ++++-- onnxruntime/hosting/environment.h | 3 ++- onnxruntime/hosting/http/context.h | 27 ++++++++++++++----- .../hosting/http/predict_request_handler.cc | 2 +- onnxruntime/hosting/http/session.cc | 2 +- onnxruntime/hosting/main.cc | 16 +++++------ tools/ci_build/build.py | 2 +- 7 files changed, 40 insertions(+), 20 deletions(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index 064b0c7bf8c88..2787ccc89301b 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -23,8 +23,12 @@ HostingEnvironment::HostingEnvironment() : logger_id_("HostingLog"), session_ = std::make_shared(options_, &default_logging_manager_); } -std::shared_ptr HostingEnvironment::GetLogger() { - return this->default_logging_manager_.CreateLogger(logger_id_); +const onnxruntime::logging::Logger& HostingEnvironment::GetDefaultLogger() { + return this->default_logging_manager_.DefaultLogger(); +} + +std::shared_ptr HostingEnvironment::GetLogger(const std::string& id) { + return this->default_logging_manager_.CreateLogger(id); } std::shared_ptr HostingEnvironment::GetSession() const { diff --git a/onnxruntime/hosting/environment.h b/onnxruntime/hosting/environment.h index 7aace0aefcfa8..0e40905fe4c07 100644 --- a/onnxruntime/hosting/environment.h +++ b/onnxruntime/hosting/environment.h @@ -19,7 +19,8 @@ class HostingEnvironment { HostingEnvironment(); HostingEnvironment(const HostingEnvironment&) = delete; - std::shared_ptr GetLogger(); + const onnxruntime::logging::Logger& GetDefaultLogger(); + std::shared_ptr GetLogger(const std::string& id); std::shared_ptr GetSession() const; private: diff --git a/onnxruntime/hosting/http/context.h b/onnxruntime/hosting/http/context.h index 23a6b59769934..678279d0a6bfe 100644 --- a/onnxruntime/hosting/http/context.h +++ b/onnxruntime/hosting/http/context.h @@ -1,10 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#ifndef ONNXRUNTIME_HOSTING_HTTP_HTTP_CONTEXT_H -#define ONNXRUNTIME_HOSTING_HTTP_HTTP_CONTEXT_H +#ifndef ONNXRUNTIME_HOSTING_HTTP_CONTEXT_H +#define ONNXRUNTIME_HOSTING_HTTP_CONTEXT_H + +// boost random is using a deprecated header in 1.69 +// See: https://github.com/boostorg/random/issues/49 +#define BOOST_PENDING_INTEGER_LOG2_HPP +#include + +#include #include +#include +#include +#include +#include namespace onnxruntime { namespace hosting { @@ -19,10 +30,14 @@ class HttpContext { http::request>> request{}; http::response response{}; - std::string error_message = "An unknown server error has occurred"; - http::status error_code = http::status::internal_server_error; + std::string uuid; + http::status error_code; + std::string error_message; + + HttpContext() : uuid(boost::uuids::to_string(boost::uuids::random_generator()())), + error_code(http::status::internal_server_error), + error_message("An unknown server error has occurred") {} - HttpContext() = default; ~HttpContext() = default; HttpContext(const HttpContext&) = delete; }; @@ -30,4 +45,4 @@ class HttpContext { } // namespace hosting } // namespace onnxruntime -#endif // ONNXRUNTIME_HOSTING_HTTP_HTTP_CONTEXT_H +#endif // ONNXRUNTIME_HOSTING_HTTP_CONTEXT_H diff --git a/onnxruntime/hosting/http/predict_request_handler.cc b/onnxruntime/hosting/http/predict_request_handler.cc index 85efc09fc5976..38e5d3ffc9445 100644 --- a/onnxruntime/hosting/http/predict_request_handler.cc +++ b/onnxruntime/hosting/http/predict_request_handler.cc @@ -15,7 +15,7 @@ void Predict(const std::string& name, HttpContext& context, std::shared_ptr env) { PredictRequest predictRequest{}; - auto logger = env->GetLogger(); + auto logger = env->GetLogger(context.uuid); LOGS(*logger, VERBOSE) << "Name: " << name; LOGS(*logger, VERBOSE) << "Version: " << version; diff --git a/onnxruntime/hosting/http/session.cc b/onnxruntime/hosting/http/session.cc index b2366dce5f53e..7eb06942f7f79 100644 --- a/onnxruntime/hosting/http/session.cc +++ b/onnxruntime/hosting/http/session.cc @@ -85,7 +85,7 @@ void HttpSession::Send(Msg&& msg) { http::async_write(self_->socket_, *ptr, net::bind_executor(strand_, - [self_, close = ptr->need_eof()](beast::error_code ec, std::size_t bytes) { + [ self_, close = ptr->need_eof() ](beast::error_code ec, std::size_t bytes) { self_->OnWrite(ec, bytes, close); })); } diff --git a/onnxruntime/hosting/main.cc b/onnxruntime/hosting/main.cc index fba5b759005be..73023f33cb01d 100644 --- a/onnxruntime/hosting/main.cc +++ b/onnxruntime/hosting/main.cc @@ -21,11 +21,11 @@ int main(int argc, char* argv[]) { } auto env = std::make_shared(); - auto logger = env->GetLogger(); - LOGS(*logger, VERBOSE) << "Logging manager initialized."; - LOGS(*logger, VERBOSE) << "Model path: " << config.model_path; + auto logger = env->GetDefaultLogger(); + LOGS(logger, VERBOSE) << "Logging manager initialized."; + LOGS(logger, VERBOSE) << "Model path: " << config.model_path; auto status = env->GetSession()->Load(config.model_path); - LOGS(*logger, VERBOSE) << "Load Model Status: " << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]"; + LOGS(logger, VERBOSE) << "Load Model Status: " << status.Code() << " ---- Error: [" << status.ErrorMessage() << "]"; auto const boost_address = boost::asio::ip::make_address(config.address); @@ -33,14 +33,14 @@ int main(int argc, char* argv[]) { app.RegisterStartup( [env](const auto& details) -> void { - auto logger = env->GetLogger(); - LOGS(*logger, VERBOSE) << "Listening at: " - << "http://" << details.address << ":" << details.port; + auto logger = env->GetDefaultLogger(); + LOGS(logger, VERBOSE) << "Listening at: " + << "http://" << details.address << ":" << details.port; }); app.RegisterError( [env](auto& context) -> void { - auto logger = env->GetLogger(); + auto logger = env->GetLogger(context.uuid); LOGS(*logger, VERBOSE) << "Error code: " << context.error_code; LOGS(*logger, VERBOSE) << "Error message: " << context.error_message; diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 8ab6a3b6b230b..4eb381eec4f70 100755 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -227,7 +227,7 @@ def install_hosting_deps(source_dir): boostrap_path = os.path.join(vcpkg_folder_path, 'bootstrap-vcpkg' + file_ending) run_subprocess([boostrap_path]) - run_subprocess([vcpkg_executable, 'install', 'boost-beast', 'boost-program-options', 'rapidjson']) + run_subprocess([vcpkg_executable, 'install', 'boost-beast', 'boost-program-options', 'boost-uuid']) def check_md5(filename, expected_md5): if not os.path.exists(filename): From a645169d143ece2d50b39e6cfb456b43fd08e334 Mon Sep 17 00:00:00 2001 From: Trent McCormick Date: Sat, 30 Mar 2019 15:57:19 -0700 Subject: [PATCH 05/12] Take logging_level as a program argument --- onnxruntime/hosting/http/context.h | 1 - onnxruntime/hosting/main.cc | 2 +- onnxruntime/hosting/server_configuration.h | 39 ++++++++++++++----- .../test/hosting/server_configuration_test.cc | 24 ++++++++++-- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/onnxruntime/hosting/http/context.h b/onnxruntime/hosting/http/context.h index 678279d0a6bfe..1da6117cd1a2b 100644 --- a/onnxruntime/hosting/http/context.h +++ b/onnxruntime/hosting/http/context.h @@ -12,7 +12,6 @@ #include #include -#include #include #include #include diff --git a/onnxruntime/hosting/main.cc b/onnxruntime/hosting/main.cc index 73023f33cb01d..22ceb07ea0266 100644 --- a/onnxruntime/hosting/main.cc +++ b/onnxruntime/hosting/main.cc @@ -35,7 +35,7 @@ int main(int argc, char* argv[]) { [env](const auto& details) -> void { auto logger = env->GetDefaultLogger(); LOGS(logger, VERBOSE) << "Listening at: " - << "http://" << details.address << ":" << details.port; + << "http://" << details.address << ":" << details.port; }); app.RegisterError( diff --git a/onnxruntime/hosting/server_configuration.h b/onnxruntime/hosting/server_configuration.h index 997405054fac5..1ce2b1c48810a 100644 --- a/onnxruntime/hosting/server_configuration.h +++ b/onnxruntime/hosting/server_configuration.h @@ -9,6 +9,8 @@ #include "boost/program_options.hpp" +#include "core/common/logging/logging.h" + namespace onnxruntime { namespace hosting { @@ -22,8 +24,16 @@ namespace po = boost::program_options; // Provides sane default values class ServerConfiguration { public: + const std::string full_desc = "ONNX Hosting: host an ONNX model for inferencing with ONNXRuntime"; + std::string model_path; + std::string address = "0.0.0.0"; + int http_port = 8001; + int num_http_threads = std::thread::hardware_concurrency(); + onnxruntime::logging::Severity logging_level{}; + ServerConfiguration() { desc.add_options()("help,h", "Shows a help message and exits"); + desc.add_options()("logging_level", po::value(&logging_level_str)->default_value(logging_level_str), "Logging level. Allowed options: verbose, info, warning, error, fatal"); desc.add_options()("model_path,m", po::value(&model_path)->required(), "Path to ONNX model"); desc.add_options()("address,a", po::value(&address)->default_value(address), "The base HTTP address"); desc.add_options()("http_port", po::value(&http_port)->default_value(http_port), "HTTP port to listen to requests"); @@ -51,19 +61,22 @@ class ServerConfiguration { return Result::ExitFailure; } + logging_level = GetSeverity(logging_level_str); return ValidateOptions(); } - const std::string full_desc = "ONNX Hosting: host an ONNX model for inferencing with ONNXRuntime"; - std::string model_path; - std::string address = "0.0.0.0"; - int http_port = 8001; - int num_http_threads = std::thread::hardware_concurrency(); - private: + po::options_description desc{"Allowed options"}; + po::variables_map vm{}; + std::string logging_level_str = "verbose"; + // Print help and return if there is a bad value Result ValidateOptions() { - if (num_http_threads <= 0) { + if (vm.count("logging_level") && + (!(logging_level_str == "verbose" || logging_level_str == "info") || logging_level_str == "warning" || logging_level_str == "error" || logging_level_str == "fatal")) { + PrintHelp(std::cerr, "logging_level must be one of verbose, info, warning, error, or fatal"); + return Result::ExitFailure; + } else if (num_http_threads <= 0) { PrintHelp(std::cerr, "num_http_threads must be greater than 0"); return Result::ExitFailure; } else if (http_port < 0 || http_port > 65535) { @@ -82,6 +95,15 @@ class ServerConfiguration { return vm.count("help") || vm.count("h"); } + onnxruntime::logging::Severity GetSeverity(const std::string& level) { + if (level == "verbose") return onnxruntime::logging::Severity::kVERBOSE; + if (level == "info") return onnxruntime::logging::Severity::kINFO; + if (level == "warning") return onnxruntime::logging::Severity::kWARNING; + if (level == "error") return onnxruntime::logging::Severity::kERROR; + if (level == "fatal") return onnxruntime::logging::Severity::kFATAL; + return onnxruntime::logging::Severity::kVERBOSE; + } + // Prints a helpful message (param: what) to the user and then the program options // Example: config.PrintHelp(std::cout, "Non-negative values not allowed") // Which will print that message and then all publicly available options @@ -94,9 +116,6 @@ class ServerConfiguration { std::ifstream infile(fileName.c_str()); return infile.good(); } - - po::options_description desc{"Allowed options"}; - po::variables_map vm{}; }; } // namespace hosting diff --git a/onnxruntime/test/hosting/server_configuration_test.cc b/onnxruntime/test/hosting/server_configuration_test.cc index 7b4b18b0f3306..f7a21e686df5c 100644 --- a/onnxruntime/test/hosting/server_configuration_test.cc +++ b/onnxruntime/test/hosting/server_configuration_test.cc @@ -16,15 +16,17 @@ TEST(PositiveTests, ConfigParsingFullArgs) { const_cast("--model_path"), const_cast("testdata/mul_1.pb"), const_cast("--address"), const_cast("4.4.4.4"), const_cast("--http_port"), const_cast("80"), - const_cast("--num_http_threads"), const_cast("1")}; + const_cast("--num_http_threads"), const_cast("1"), + const_cast("--logging_level"), const_cast("info")}; onnxruntime::hosting::ServerConfiguration config{}; - Result res = config.ParseInput(9, test_argv); + Result res = config.ParseInput(11, test_argv); EXPECT_EQ(res, Result::ContinueSuccess); EXPECT_EQ(config.model_path, "testdata/mul_1.pb"); EXPECT_EQ(config.address, "4.4.4.4"); EXPECT_EQ(config.http_port, 80); EXPECT_EQ(config.num_http_threads, 1); + EXPECT_EQ(config.logging_level, onnxruntime::logging::Severity::kINFO); } TEST(PositiveTests, ConfigParsingShortArgs) { @@ -42,6 +44,7 @@ TEST(PositiveTests, ConfigParsingShortArgs) { EXPECT_EQ(config.address, "4.4.4.4"); EXPECT_EQ(config.http_port, 5001); EXPECT_EQ(config.num_http_threads, 2); + EXPECT_EQ(config.logging_level, onnxruntime::logging::Severity::kVERBOSE); } TEST(PositiveTests, ConfigParsingDefaults) { @@ -57,6 +60,7 @@ TEST(PositiveTests, ConfigParsingDefaults) { EXPECT_EQ(config.address, "0.0.0.0"); EXPECT_EQ(config.http_port, 8001); EXPECT_EQ(config.num_http_threads, 3); + EXPECT_EQ(config.logging_level, onnxruntime::logging::Severity::kVERBOSE); } TEST(PositiveTests, ConfigParsingHelp) { @@ -79,7 +83,7 @@ TEST(NegativeTests, ConfigParsingNoModelArg) { EXPECT_EQ(res, Result::ExitFailure); } -TEST(PositiveTests, ConfigParsingModelNotFound) { +TEST(NegativeTests, ConfigParsingModelNotFound) { char* test_argv[] = { const_cast("/path/to/binary"), const_cast("--model_path"), const_cast("does/not/exist"), @@ -92,6 +96,20 @@ TEST(PositiveTests, ConfigParsingModelNotFound) { EXPECT_EQ(res, Result::ExitFailure); } +TEST(NegativeTests, ConfigParsingWrongLoggingLevel) { + char* test_argv[] = { + const_cast("/path/to/binary"), + const_cast("--logging_level"), const_cast("not a logging level"), + const_cast("--model_path"), const_cast("testdata/mul_1.pb"), + const_cast("--address"), const_cast("4.4.4.4"), + const_cast("--http_port"), const_cast("80"), + const_cast("--num_http_threads"), const_cast("1")}; + + onnxruntime::hosting::ServerConfiguration config{}; + Result res = config.ParseInput(11, test_argv); + EXPECT_EQ(res, Result::ExitFailure); +} + } // namespace test } // namespace hosting } // namespace onnxruntime \ No newline at end of file From f1f8e2b0cb53cade5c2a785648c50e8348da99e0 Mon Sep 17 00:00:00 2001 From: Trent McCormick Date: Sat, 30 Mar 2019 16:07:43 -0700 Subject: [PATCH 06/12] Pass logging_level to default_logging_manager --- onnxruntime/hosting/environment.cc | 4 ++-- onnxruntime/hosting/environment.h | 7 +++++-- onnxruntime/hosting/main.cc | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index 2787ccc89301b..33550cfe1b95d 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -10,10 +10,10 @@ namespace onnxruntime { namespace hosting { -HostingEnvironment::HostingEnvironment() : logger_id_("HostingLog"), +HostingEnvironment::HostingEnvironment(onnxruntime::logging::Severity severity) : logger_id_("HostingLog"), default_logging_manager_( std::unique_ptr{&sink_}, - onnxruntime::logging::Severity::kVERBOSE, + severity, /* default_filter_user_data */ false, onnxruntime::logging::LoggingManager::InstanceType::Default, &logger_id_) { diff --git a/onnxruntime/hosting/environment.h b/onnxruntime/hosting/environment.h index 0e40905fe4c07..a16382f4f6c85 100644 --- a/onnxruntime/hosting/environment.h +++ b/onnxruntime/hosting/environment.h @@ -16,7 +16,9 @@ namespace hosting { class HostingEnvironment { public: - HostingEnvironment(); + explicit HostingEnvironment(onnxruntime::logging::Severity severity); + // TODO: cleanly dispose session + ~HostingEnvironment() = default; HostingEnvironment(const HostingEnvironment&) = delete; const onnxruntime::logging::Logger& GetDefaultLogger(); @@ -26,8 +28,9 @@ class HostingEnvironment { private: std::string logger_id_; onnxruntime::hosting::LogSink sink_; - std::unique_ptr runtime_environment_; onnxruntime::logging::LoggingManager default_logging_manager_; + + std::unique_ptr runtime_environment_; onnxruntime::SessionOptions options_; std::shared_ptr session_; }; diff --git a/onnxruntime/hosting/main.cc b/onnxruntime/hosting/main.cc index 22ceb07ea0266..961e5460299fe 100644 --- a/onnxruntime/hosting/main.cc +++ b/onnxruntime/hosting/main.cc @@ -20,7 +20,7 @@ int main(int argc, char* argv[]) { exit(EXIT_FAILURE); } - auto env = std::make_shared(); + auto env = std::make_shared(config.logging_level); auto logger = env->GetDefaultLogger(); LOGS(logger, VERBOSE) << "Logging manager initialized."; LOGS(logger, VERBOSE) << "Model path: " << config.model_path; From e02d6a9678ccb8df44eef167fdf26ddcf9805659 Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Mon, 1 Apr 2019 11:07:06 -0700 Subject: [PATCH 07/12] Change name of logger to HostingApp --- onnxruntime/hosting/environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index 33550cfe1b95d..1507367242334 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -10,7 +10,7 @@ namespace onnxruntime { namespace hosting { -HostingEnvironment::HostingEnvironment(onnxruntime::logging::Severity severity) : logger_id_("HostingLog"), +HostingEnvironment::HostingEnvironment(onnxruntime::logging::Severity severity) : logger_id_("HostingApp"), default_logging_manager_( std::unique_ptr{&sink_}, severity, From 5ce903bbdf086de616d2362cea6417473a0addfc Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Mon, 1 Apr 2019 11:08:47 -0700 Subject: [PATCH 08/12] Change name of GetDefaultLogger to GetAppLogger --- onnxruntime/hosting/environment.cc | 2 +- onnxruntime/hosting/environment.h | 2 +- onnxruntime/hosting/main.cc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index 1507367242334..6258c82676278 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -23,7 +23,7 @@ HostingEnvironment::HostingEnvironment(onnxruntime::logging::Severity severity) session_ = std::make_shared(options_, &default_logging_manager_); } -const onnxruntime::logging::Logger& HostingEnvironment::GetDefaultLogger() { +const onnxruntime::logging::Logger& HostingEnvironment::GetAppLogger() { return this->default_logging_manager_.DefaultLogger(); } diff --git a/onnxruntime/hosting/environment.h b/onnxruntime/hosting/environment.h index a16382f4f6c85..485fced686b79 100644 --- a/onnxruntime/hosting/environment.h +++ b/onnxruntime/hosting/environment.h @@ -21,7 +21,7 @@ class HostingEnvironment { ~HostingEnvironment() = default; HostingEnvironment(const HostingEnvironment&) = delete; - const onnxruntime::logging::Logger& GetDefaultLogger(); + const onnxruntime::logging::Logger& GetAppLogger(); std::shared_ptr GetLogger(const std::string& id); std::shared_ptr GetSession() const; diff --git a/onnxruntime/hosting/main.cc b/onnxruntime/hosting/main.cc index 961e5460299fe..a0b4390f50b9b 100644 --- a/onnxruntime/hosting/main.cc +++ b/onnxruntime/hosting/main.cc @@ -21,7 +21,7 @@ int main(int argc, char* argv[]) { } auto env = std::make_shared(config.logging_level); - auto logger = env->GetDefaultLogger(); + auto logger = env->GetAppLogger(); LOGS(logger, VERBOSE) << "Logging manager initialized."; LOGS(logger, VERBOSE) << "Model path: " << config.model_path; auto status = env->GetSession()->Load(config.model_path); @@ -33,7 +33,7 @@ int main(int argc, char* argv[]) { app.RegisterStartup( [env](const auto& details) -> void { - auto logger = env->GetDefaultLogger(); + auto logger = env->GetAppLogger(); LOGS(logger, VERBOSE) << "Listening at: " << "http://" << details.address << ":" << details.port; }); From b29f14c09bddd6eb46ca55867ca67d32d6f55372 Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Mon, 1 Apr 2019 11:15:26 -0700 Subject: [PATCH 09/12] Log if request id is null --- onnxruntime/hosting/environment.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index 6258c82676278..e4330edb7a821 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -11,12 +11,12 @@ namespace onnxruntime { namespace hosting { HostingEnvironment::HostingEnvironment(onnxruntime::logging::Severity severity) : logger_id_("HostingApp"), - default_logging_manager_( - std::unique_ptr{&sink_}, - severity, - /* default_filter_user_data */ false, - onnxruntime::logging::LoggingManager::InstanceType::Default, - &logger_id_) { + default_logging_manager_( + std::unique_ptr{&sink_}, + severity, + /* default_filter_user_data */ false, + onnxruntime::logging::LoggingManager::InstanceType::Default, + &logger_id_) { auto status = onnxruntime::Environment::Create(this->runtime_environment_); // The session initialization MUST BE AFTER environment creation @@ -28,6 +28,10 @@ const onnxruntime::logging::Logger& HostingEnvironment::GetAppLogger() { } std::shared_ptr HostingEnvironment::GetLogger(const std::string& id) { + if (id.empty()) { + LOGS(GetAppLogger(), VERBOSE) << "Request id is null or empty string"; + } + return this->default_logging_manager_.CreateLogger(id); } From 744f54ea85fd32e47b80cca3fa03a00cbb0cc211 Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Mon, 1 Apr 2019 11:17:42 -0700 Subject: [PATCH 10/12] Make logging model info one line --- onnxruntime/hosting/http/predict_request_handler.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/onnxruntime/hosting/http/predict_request_handler.cc b/onnxruntime/hosting/http/predict_request_handler.cc index 38e5d3ffc9445..9ab4aa42074ba 100644 --- a/onnxruntime/hosting/http/predict_request_handler.cc +++ b/onnxruntime/hosting/http/predict_request_handler.cc @@ -17,9 +17,7 @@ void Predict(const std::string& name, PredictRequest predictRequest{}; auto logger = env->GetLogger(context.uuid); - LOGS(*logger, VERBOSE) << "Name: " << name; - LOGS(*logger, VERBOSE) << "Version: " << version; - LOGS(*logger, VERBOSE) << "Action: " << action; + LOGS(*logger, VERBOSE) << "Name: " << name << " Version: " << version << " Action: " << action; auto body = context.request.body(); auto status = GetRequestFromJson(body, predictRequest); From eec54675e5f5f2a348ee821b9b71b4cf76d31e6b Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Mon, 1 Apr 2019 11:23:41 -0700 Subject: [PATCH 11/12] Mention logging level is case sensitive --- onnxruntime/hosting/server_configuration.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/hosting/server_configuration.h b/onnxruntime/hosting/server_configuration.h index 1ce2b1c48810a..cd0cc892560fd 100644 --- a/onnxruntime/hosting/server_configuration.h +++ b/onnxruntime/hosting/server_configuration.h @@ -33,7 +33,7 @@ class ServerConfiguration { ServerConfiguration() { desc.add_options()("help,h", "Shows a help message and exits"); - desc.add_options()("logging_level", po::value(&logging_level_str)->default_value(logging_level_str), "Logging level. Allowed options: verbose, info, warning, error, fatal"); + desc.add_options()("logging_level", po::value(&logging_level_str)->default_value(logging_level_str), "Logging level. Allowed options (case sensitive): verbose, info, warning, error, fatal"); desc.add_options()("model_path,m", po::value(&model_path)->required(), "Path to ONNX model"); desc.add_options()("address,a", po::value(&address)->default_value(address), "The base HTTP address"); desc.add_options()("http_port", po::value(&http_port)->default_value(http_port), "HTTP port to listen to requests"); @@ -95,7 +95,7 @@ class ServerConfiguration { return vm.count("help") || vm.count("h"); } - onnxruntime::logging::Severity GetSeverity(const std::string& level) { + onnxruntime::logging::Severity GetSeverity(const std::string& level) const { if (level == "verbose") return onnxruntime::logging::Severity::kVERBOSE; if (level == "info") return onnxruntime::logging::Severity::kINFO; if (level == "warning") return onnxruntime::logging::Severity::kWARNING; From 25550991a359c9ea1597a53aef4b1715811e009e Mon Sep 17 00:00:00 2001 From: tmccrmck Date: Mon, 1 Apr 2019 11:27:37 -0700 Subject: [PATCH 12/12] If request id is empty log a warning --- onnxruntime/hosting/environment.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onnxruntime/hosting/environment.cc b/onnxruntime/hosting/environment.cc index e4330edb7a821..1bcde3da2246d 100644 --- a/onnxruntime/hosting/environment.cc +++ b/onnxruntime/hosting/environment.cc @@ -29,7 +29,7 @@ const onnxruntime::logging::Logger& HostingEnvironment::GetAppLogger() { std::shared_ptr HostingEnvironment::GetLogger(const std::string& id) { if (id.empty()) { - LOGS(GetAppLogger(), VERBOSE) << "Request id is null or empty string"; + LOGS(GetAppLogger(), WARNING) << "Request id is null or empty string"; } return this->default_logging_manager_.CreateLogger(id);