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/zenutil/consul/consul.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/zenutil/consul/consul.cpp')
| -rw-r--r-- | src/zenutil/consul/consul.cpp | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/zenutil/consul/consul.cpp b/src/zenutil/consul/consul.cpp index d463c0938..c9144e589 100644 --- a/src/zenutil/consul/consul.cpp +++ b/src/zenutil/consul/consul.cpp @@ -167,6 +167,8 @@ ConsulClient::RegisterService(const ServiceRegistrationInfo& Info) ApplyCommonHeaders(AdditionalHeaders); AdditionalHeaders.Entries.emplace(HttpClient::Accept(HttpContentType::kJSON)); + HttpClient::KeyValueMap AdditionalParameters(std::make_pair<std::string, std::string>("replace-existing-checks", "true")); + CbObjectWriter Writer; { Writer.AddString("ID"sv, Info.ServiceId); @@ -185,13 +187,21 @@ ConsulClient::RegisterService(const ServiceRegistrationInfo& Info) } Writer.EndArray(); // Tags } - Writer.BeginObject("Check"sv); + if (Info.HealthIntervalSeconds != 0) { - Writer.AddString("HTTP"sv, fmt::format("http://{}:{}/{}", Info.Address, Info.Port, Info.HealthEndpoint)); - Writer.AddString("Interval"sv, fmt::format("{}s", Info.HealthIntervalSeconds)); - Writer.AddString("DeregisterCriticalServiceAfter"sv, fmt::format("{}s", Info.DeregisterAfterSeconds)); + // Consul requires Interval whenever HTTP is specified; omit the Check block entirely + // when no interval is configured (e.g. during Provisioning). + Writer.BeginObject("Check"sv); + { + Writer.AddString("HTTP"sv, fmt::format("http://{}:{}/{}", Info.Address, Info.Port, Info.HealthEndpoint)); + Writer.AddString("Interval"sv, fmt::format("{}s", Info.HealthIntervalSeconds)); + if (Info.DeregisterAfterSeconds != 0) + { + Writer.AddString("DeregisterCriticalServiceAfter"sv, fmt::format("{}s", Info.DeregisterAfterSeconds)); + } + } + Writer.EndObject(); // Check } - Writer.EndObject(); // Check } ExtendableStringBuilder<512> SB; @@ -199,7 +209,7 @@ ConsulClient::RegisterService(const ServiceRegistrationInfo& Info) IoBuffer PayloadBuffer(IoBuffer::Wrap, SB.Data(), SB.Size()); PayloadBuffer.SetContentType(HttpContentType::kJSON); - HttpClient::Response Result = m_HttpClient.Put("v1/agent/service/register", PayloadBuffer, AdditionalHeaders); + HttpClient::Response Result = m_HttpClient.Put("v1/agent/service/register", PayloadBuffer, AdditionalHeaders, AdditionalParameters); if (!Result) { @@ -321,6 +331,20 @@ ConsulClient::GetAgentServicesJson() return Result.ToText(); } +std::string +ConsulClient::GetAgentChecksJson() +{ + HttpClient::KeyValueMap AdditionalHeaders; + ApplyCommonHeaders(AdditionalHeaders); + + HttpClient::Response Result = m_HttpClient.Get("v1/agent/checks", AdditionalHeaders); + if (!Result) + { + return "{}"; + } + return Result.ToText(); +} + ////////////////////////////////////////////////////////////////////////// ServiceRegistration::ServiceRegistration(ConsulClient* Client, const ServiceRegistrationInfo& Info) : m_Client(Client), m_Info(Info) |