Skip to content
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

Make controller RPC timeout configurable #101

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
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;
}

Comment on lines +243 to +249
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about
controller_rpc_timeout_ms = settings.value("controller_rpc_timeout_ms", defaults::CONTROLLER_RPC_TIMEOUT_MS);?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, right now it just follows the style of the surrounding code, we should probably refactor this in a different PR though

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: 1 addition & 1 deletion src/controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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 @@
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
6 changes: 3 additions & 3 deletions src/controller/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandApi>(config, *this);
}

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