From 7fcf0ac1e2d5362b25e967d48e163f0fbb4382b9 Mon Sep 17 00:00:00 2001 From: Kai Hermann Date: Mon, 2 Oct 2023 19:11:39 +0200 Subject: [PATCH] Make controller RPC timeout configurable (#101) * Make controller RPC timeout configurable Also make it available to the admin panel * Use most recent version of everest-admin-panel (v0.1.0 ) --------- Signed-off-by: Kai-Uwe Hermann --- include/framework/runtime.hpp | 2 ++ lib/runtime.cpp | 7 +++++++ schemas/config.yaml | 2 ++ src/controller/CMakeLists.txt | 2 +- src/controller/command_api.cpp | 2 ++ src/controller/command_api.hpp | 1 + src/controller/controller.cpp | 1 + src/controller/rpc.cpp | 6 +++--- src/controller/rpc.hpp | 1 + src/manager.cpp | 1 + 10 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/framework/runtime.hpp b/include/framework/runtime.hpp index cdf3afa5..253bb7cb 100644 --- a/include/framework/runtime.hpp +++ b/include/framework/runtime.hpp @@ -72,6 +72,7 @@ inline constexpr auto LOGGING_CONFIG_NAME = "default_logging.cfg"; inline constexpr auto WWW_DIR = "www"; inline constexpr auto CONTROLLER_PORT = 8849; +inline constexpr auto CONTROLLER_RPC_TIMEOUT_MS = 2000; inline constexpr auto MQTT_BROKER_HOST = "localhost"; inline constexpr auto MQTT_BROKER_PORT = 1883; inline constexpr auto MQTT_EVEREST_PREFIX = "everest"; @@ -103,6 +104,7 @@ struct RuntimeSettings { fs::path config_file; fs::path www_dir; int controller_port; + int controller_rpc_timeout_ms; std::string mqtt_broker_host; int mqtt_broker_port; std::string mqtt_everest_prefix; diff --git a/lib/runtime.cpp b/lib/runtime.cpp index fbcb5fb4..c5e4b8d5 100644 --- a/lib/runtime.cpp +++ b/lib/runtime.cpp @@ -240,6 +240,13 @@ RuntimeSettings::RuntimeSettings(const std::string& prefix_, const std::string& controller_port = defaults::CONTROLLER_PORT; } + const auto settings_controller_rpc_timeout_ms_it = settings.find("controller_rpc_timeout_ms"); + if (settings_controller_rpc_timeout_ms_it != settings.end()) { + controller_rpc_timeout_ms = settings_controller_rpc_timeout_ms_it->get(); + } else { + controller_rpc_timeout_ms = defaults::CONTROLLER_RPC_TIMEOUT_MS; + } + const auto settings_mqtt_broker_host_it = settings.find("mqtt_broker_host"); if (settings_mqtt_broker_host_it != settings.end()) { mqtt_broker_host = settings_mqtt_broker_host_it->get(); diff --git a/schemas/config.yaml b/schemas/config.yaml index eda2af80..43eaa649 100644 --- a/schemas/config.yaml +++ b/schemas/config.yaml @@ -45,6 +45,8 @@ properties: type: string controller_port: type: integer + controller_rpc_timeout_ms: + type: integer mqtt_broker_host: type: string mqtt_broker_port: diff --git a/src/controller/CMakeLists.txt b/src/controller/CMakeLists.txt index a68f6d4b..c6131113 100644 --- a/src/controller/CMakeLists.txt +++ b/src/controller/CMakeLists.txt @@ -45,7 +45,7 @@ if (NOT NO_FETCH_CONTENT) message(STATUS "Fetching everest-admin-panel") FetchContent_Declare(admin-panel DOWNLOAD_EXTRACT_TIMESTAMP TRUE - URL https://github.com/EVerest/everest-admin-panel/releases/download/manually_dispatched/everest-admin-panel.tar.gz + URL https://github.com/EVerest/everest-admin-panel/releases/download/v0.1.0/everest-admin-panel.tar.gz ) FetchContent_Populate(admin-panel) install( diff --git a/src/controller/command_api.cpp b/src/controller/command_api.cpp index abd17292..aae2511a 100644 --- a/src/controller/command_api.cpp +++ b/src/controller/command_api.cpp @@ -123,6 +123,8 @@ nlohmann::json CommandApi::handle(const std::string& cmd, const json& params) { this->rpc.ipc_request("restart_modules", nullptr, true); return nullptr; + } else if (cmd == "get_rpc_timeout") { + return this->config.controller_rpc_timeout_ms; } throw CommandApiMethodNotFound(fmt::format("Command '{}' unknown", cmd)); diff --git a/src/controller/command_api.hpp b/src/controller/command_api.hpp index 20115f18..9c6abace 100644 --- a/src/controller/command_api.hpp +++ b/src/controller/command_api.hpp @@ -24,6 +24,7 @@ class CommandApi { std::string module_dir; std::string interface_dir; std::string configs_dir; + int controller_rpc_timeout_ms; }; CommandApi(const Config& config, RPC& rpc); diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 1bf5f522..674e1710 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -42,6 +42,7 @@ int main(int argc, char* argv[]) { config_params.at("module_dir"), config_params.at("interface_dir"), config_params.at("configs_dir"), + config_params.at("controller_rpc_timeout_ms"), }; RPC rpc(socket_fd, config); diff --git a/src/controller/rpc.cpp b/src/controller/rpc.cpp index d02c1289..04b4db9d 100644 --- a/src/controller/rpc.cpp +++ b/src/controller/rpc.cpp @@ -89,7 +89,8 @@ class RPCRequest { nlohmann::json params; }; -RPC::RPC(int ipc_fd, const CommandApi::Config& config) : ipc_fd(ipc_fd) { +RPC::RPC(int ipc_fd, const CommandApi::Config& config) : + ipc_fd(ipc_fd), rpc_timeout(std::chrono::milliseconds(config.controller_rpc_timeout_ms)) { this->api = std::make_unique(config, *this); } @@ -192,8 +193,7 @@ nlohmann::json RPC::ipc_request(const std::string& method, const nlohmann::json& Everest::controller_ipc::send_message(this->ipc_fd, {{"method", method}, {"params", params}, {"id", id}}); - // FIXME (aw): timeout constant! - auto status = call_result_future.wait_for(std::chrono::milliseconds(2000)); + auto status = call_result_future.wait_for(this->rpc_timeout); lock.lock(); this->ipc_calls.erase(new_call.first); diff --git a/src/controller/rpc.hpp b/src/controller/rpc.hpp index de40dfe1..7d8461f5 100644 --- a/src/controller/rpc.hpp +++ b/src/controller/rpc.hpp @@ -29,6 +29,7 @@ class RPC { int ipc_fd; std::unique_ptr api; NotificationHandler notification_handler; + std::chrono::milliseconds rpc_timeout; // FIXME (aw): what type of cafe? std::mt19937 rng{0xcafe}; diff --git a/src/manager.cpp b/src/manager.cpp index 04f330c4..75350715 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -486,6 +486,7 @@ static ControllerHandle start_controller(const RuntimeSettings& rs) { {"configs_dir", rs.configs_dir.string()}, {"logging_config_file", rs.logging_config_file.string()}, {"controller_port", rs.controller_port}, + {"controller_rpc_timeout_ms", rs.controller_rpc_timeout_ms}, }}, });