Skip to content

Commit

Permalink
Make controller RPC timeout configurable
Browse files Browse the repository at this point in the history
Also make it available to the admin panel

Signed-off-by: Kai-Uwe Hermann <kai-uwe.hermann@pionix.de>
  • Loading branch information
hikinggrass committed Sep 27, 2023
1 parent 0a3d60e commit 1184b6d
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/framework/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -103,6 +104,7 @@ struct RuntimeSettings {
fs::path config_file;
fs::path www_dir;
int controller_port;
int controller_rpc_timeout_ms;

Check notice on line 107 in include/framework/runtime.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

include/framework/runtime.hpp#L107

struct member 'RuntimeSettings::controller_rpc_timeout_ms' is never used.
std::string mqtt_broker_host;
int mqtt_broker_port;
std::string mqtt_everest_prefix;
Expand Down
7 changes: 7 additions & 0 deletions lib/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>();
} 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<std::string>();
Expand Down
2 changes: 2 additions & 0 deletions schemas/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/controller/command_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/controller/command_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CommandApi {
std::string module_dir;
std::string interface_dir;
std::string configs_dir;
int controller_rpc_timeout_ms;

Check notice on line 27 in src/controller/command_api.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/controller/command_api.hpp#L27

struct member 'Config::controller_rpc_timeout_ms' is never used.
};

CommandApi(const Config& config, RPC& rpc);
Expand Down
1 change: 1 addition & 0 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/controller/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class RPCRequest {

RPC::RPC(int ipc_fd, const CommandApi::Config& config) : ipc_fd(ipc_fd) {
this->api = std::make_unique<CommandApi>(config, *this);
this->rpc_timeout = std::chrono::milliseconds(config.controller_rpc_timeout_ms);
}

void RPC::run(const NotificationHandler& notification_handler) {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/controller/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RPC {
int ipc_fd;
std::unique_ptr<CommandApi> api;
NotificationHandler notification_handler;
std::chrono::milliseconds rpc_timeout;

// FIXME (aw): what type of cafe?
std::mt19937 rng{0xcafe};
Expand Down
1 change: 1 addition & 0 deletions src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}},
});

Expand Down

0 comments on commit 1184b6d

Please sign in to comment.