From 967247a688e657d9e203497271e910a8a2d303d2 Mon Sep 17 00:00:00 2001 From: Dan Fuhry Date: Tue, 8 Apr 2025 18:03:28 -0400 Subject: [PATCH] [sd] workaround for no FQDN in k8s when populating ShardRegion --- sd/monitor.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sd/monitor.go b/sd/monitor.go index 656af85..58a45c0 100644 --- a/sd/monitor.go +++ b/sd/monitor.go @@ -108,6 +108,16 @@ func (sdp *healthCheckingPublisher) MonitorAndPublish(ctx context.Context, wg *s func (sdp *healthCheckingPublisher) updateHealth(ctx context.Context, lease *etcd_client.LeaseGrantResponse, evt HealthChangeEvent) { key := fmt.Sprintf("/sd/_health/%016x", lease.ID) + shardRegion := "" + advHostParts := strings.Split(sdp.publisher.AdvertiseHost, ".") + if len(advHostParts) >= 2 { + shardRegion = advHostParts[1] + } else if hostname.Containerization() == hostname.ContainerKubernetes { + shardRegion = "k8s" + } else { + shardRegion = "unknown" + } + hr := SDHealthReport{ Up: evt.Status == ServiceUp, Service: sdp.publisher.Service, @@ -116,7 +126,7 @@ func (sdp *healthCheckingPublisher) updateHealth(ctx context.Context, lease *etc Domain: sdp.publisher.Domain, Shard: sdp.publisher.ShardName, Node: sdp.publisher.NodeName, - ShardRegion: strings.Split(sdp.publisher.AdvertiseHost, ".")[1], + ShardRegion: shardRegion, Protocol: sdp.healthcheck.ServiceDefinition().Engine, MonitorHost: hostname.Fqdn(), MonitorRegion: hostname.RegionName(), -- 2.50.1