From: Dan Fuhry Date: Tue, 8 Apr 2025 22:03:28 +0000 (-0400) Subject: [sd] workaround for no FQDN in k8s when populating ShardRegion X-Git-Url: https://go.fuhry.dev/?a=commitdiff_plain;h=967247a688e657d9e203497271e910a8a2d303d2;p=runtime.git [sd] workaround for no FQDN in k8s when populating ShardRegion --- 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(),