diff options
| author | Dan Engelbrecht <[email protected]> | 2026-03-27 09:51:29 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-27 09:51:29 +0100 |
| commit | e811745e5c37dd38a8fb9f4bc2892525401eabbd (patch) | |
| tree | 63896cabc0eb895887dc8247bb573f0dfd696afa /src/zenserver/hub/zenhubserver.cpp | |
| parent | hub async provision/deprovision/hibernate/wake (#891) (diff) | |
| download | zen-e811745e5c37dd38a8fb9f4bc2892525401eabbd.tar.xz zen-e811745e5c37dd38a8fb9f4bc2892525401eabbd.zip | |
hub instance state refactor (#892)
- Improvement: Provisioning a hibernated instance now automatically wakes it instead of requiring an explicit wake call first
- Improvement: Deprovisioning now accepts instances in Crashed or Hibernated states, not just Provisioned
- Improvement: Added `--consul-health-interval-seconds` and `--consul-deregister-after-seconds` options to control Consul health check behavior (defaults: 10s and 30s)
- Improvement: Consul registration now occurs when provisioning starts; health check intervals are applied once provisioning completes
Diffstat (limited to 'src/zenserver/hub/zenhubserver.cpp')
| -rw-r--r-- | src/zenserver/hub/zenhubserver.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/zenserver/hub/zenhubserver.cpp b/src/zenserver/hub/zenhubserver.cpp index 4d70fbddd..269de28c2 100644 --- a/src/zenserver/hub/zenhubserver.cpp +++ b/src/zenserver/hub/zenhubserver.cpp @@ -74,6 +74,20 @@ ZenHubServerConfigurator::AddCliOptions(cxxopts::Options& Options) Options.add_option("hub", "", + "consul-health-interval-seconds", + "Interval in seconds between Consul health checks", + cxxopts::value<uint32_t>(m_ServerOptions.ConsulHealthIntervalSeconds)->default_value("10"), + "<seconds>"); + + Options.add_option("hub", + "", + "consul-deregister-after-seconds", + "Seconds after which Consul deregisters an unhealthy service", + cxxopts::value<uint32_t>(m_ServerOptions.ConsulDeregisterAfterSeconds)->default_value("30"), + "<seconds>"); + + Options.add_option("hub", + "", "hub-base-port-number", "Base port number for provisioned instances", cxxopts::value<uint16_t>(m_ServerOptions.HubBasePortNumber)->default_value("21000"), @@ -181,7 +195,8 @@ ZenHubServer::OnModuleStateChanged(std::string_view HubInstanceId, { return; } - if (NewState == HubInstanceState::Provisioned) + + if (NewState == HubInstanceState::Provisioning || NewState == HubInstanceState::Provisioned) { consul::ServiceRegistrationInfo ServiceInfo{ .ServiceId = std::string(ModuleId), @@ -191,8 +206,12 @@ ZenHubServer::OnModuleStateChanged(std::string_view HubInstanceId, .Tags = std::vector<std::pair<std::string, std::string>>{std::make_pair("module", std::string(ModuleId)), std::make_pair("zen-hub", std::string(HubInstanceId)), std::make_pair("version", std::string(ZEN_CFG_VERSION))}, - .HealthIntervalSeconds = 10, - .DeregisterAfterSeconds = 30}; + .HealthIntervalSeconds = NewState == HubInstanceState::Provisioning + ? 0u + : m_ConsulHealthIntervalSeconds, // Disable health checks while not finished provisioning + .DeregisterAfterSeconds = NewState == HubInstanceState::Provisioning + ? 0u + : m_ConsulDeregisterAfterSeconds}; // Disable health checks while not finished provisioning if (!m_ConsulClient->RegisterService(ServiceInfo)) { @@ -219,7 +238,7 @@ ZenHubServer::OnModuleStateChanged(std::string_view HubInstanceId, ZEN_INFO("Deregistered storage server instance for module '{}' at port {} from Consul", ModuleId, Info.Port); } } - // Transitional states (Provisioning, Deprovisioning, Hibernating, Waking, Recovering, Crashed) + // Transitional states (Deprovisioning, Hibernating, Waking, Recovering, Crashed) // and Hibernated are intentionally ignored. } @@ -385,7 +404,9 @@ ZenHubServer::InitializeConsulRegistration(const ZenHubServerConfig& ServerConfi try { - m_ConsulClient = std::make_unique<consul::ConsulClient>(ServerConfig.ConsulEndpoint, ConsulAccessToken); + m_ConsulClient = std::make_unique<consul::ConsulClient>(ServerConfig.ConsulEndpoint, ConsulAccessToken); + m_ConsulHealthIntervalSeconds = ServerConfig.ConsulHealthIntervalSeconds; + m_ConsulDeregisterAfterSeconds = ServerConfig.ConsulDeregisterAfterSeconds; consul::ServiceRegistrationInfo Info; Info.ServiceId = fmt::format("zen-hub-{}", ServerConfig.InstanceId); @@ -399,6 +420,8 @@ ZenHubServer::InitializeConsulRegistration(const ZenHubServerConfig& ServerConfi std::make_pair("base-port-number", fmt::format("{}", ServerConfig.HubBasePortNumber)), std::make_pair("instance-limit", fmt::format("{}", ServerConfig.HubInstanceLimit)), std::make_pair("use-job-object", fmt::format("{}", ServerConfig.HubUseJobObject))}; + Info.HealthIntervalSeconds = ServerConfig.ConsulHealthIntervalSeconds; + Info.DeregisterAfterSeconds = ServerConfig.ConsulDeregisterAfterSeconds; m_ConsulRegistration = std::make_unique<consul::ServiceRegistration>(m_ConsulClient.get(), Info); |