NetworkedApplications: separate administrative listener

This commit is contained in:
faumaray committed 2026-12-03 20:35:19 +03:00
1 parent 6b9ccc5e9a
commit c6d4a44394
3 files changed
+105

No files matched your search

@@ -137,6 +137,7 @@ namespace NetworkedKv
, m_store(std::move(other.m_store))
, m_api(std::move(other.m_api))
, m_server(std::move(other.m_server))
, m_admin_server(std::move(other.m_admin_server))
, m_state(other.m_state)
{
other.m_host = nullptr;
@@ -155,6 +156,7 @@ namespace NetworkedKv
m_store = std::move(other.m_store);
m_api = std::move(other.m_api);
m_server = std::move(other.m_server);
m_admin_server = std::move(other.m_admin_server);
m_state = other.m_state;
other.m_host = nullptr;
other.m_state = ApplicationState::Stopped;
@@ -168,6 +170,10 @@ namespace NetworkedKv
m_server->shutdown(m_config.shutdown_grace);
m_server.reset();
}
if (m_admin_server) {
m_admin_server->shutdown(m_config.shutdown_grace);
m_admin_server.reset();
}
stop_owned_host();
}
@@ -277,6 +283,52 @@ namespace NetworkedKv
}
m_server = std::move(server);
}
// The administrative listener is separate from the data plane and
// only exposes bounded lifecycle and telemetry views.
if (!m_admin_server && !m_config.admin_address.empty()) {
std::string host;
std::uint16_t port = 0;
if (!parse_address(m_config.admin_address, host, port)) {
m_state = ApplicationState::Failed;
return std::unexpected{config_error(
"NetworkedApplication: admin_address must be host:port")};
}
Void::Net::HttpServerOptions options;
options.bind_host = std::move(host);
options.port = port;
options.max_concurrent_connections = 8;
auto admin = std::make_unique<Void::Net::HttpServer>(options);
auto add_admin = [&](const char* pattern) {
return admin->add_route(
Void::Net::Method::Get, pattern,
[this](const Void::Net::ServerRequest& request)
-> Void::Net::RouteResult {
return to_server_response(
m_api->admin(to_http_request(request)));
});
};
Void::Result::Error admin_error{};
bool admin_ok = true;
for (const char* pattern : {"/live", "/ready", "/metrics"}) {
if (!admin_ok) {
break;
}
if (auto added = add_admin(pattern); !added) {
admin_ok = false;
admin_error = std::move(added).error();
}
}
if (!admin_ok) {
m_state = ApplicationState::Failed;
return std::unexpected{std::move(admin_error)};
}
if (auto started = admin->start(); !started) {
m_state = ApplicationState::Failed;
return started;
}
m_admin_server = std::move(admin);
}
m_state = ApplicationState::Running;
return {};
}
@@ -296,6 +348,10 @@ namespace NetworkedKv
m_server->shutdown(m_config.shutdown_grace);
m_server.reset();
}
if (m_admin_server) {
m_admin_server->shutdown(m_config.shutdown_grace);
m_admin_server.reset();
}
if (m_resources.ownership == ResourceOwnership::Managed && m_host) {
auto report =
m_host->shutdown_blocking(deadline_after(m_config.shutdown_grace));
@@ -330,6 +386,11 @@ namespace NetworkedKv
return m_server ? m_server->bound_port() : 0;
}
std::uint16_t NetworkedApplication::admin_bound_port() const noexcept
{
return m_admin_server ? m_admin_server->bound_port() : 0;
}
void NetworkedApplication::stop_owned_host() noexcept
{
if (m_resources.ownership != ResourceOwnership::Managed ||