]> go.fuhry.dev Git - runtime.git/commitdiff
[sd] workaround for no FQDN in k8s when populating ShardRegion
authorDan Fuhry <dan@fuhry.com>
Tue, 8 Apr 2025 22:03:28 +0000 (18:03 -0400)
committerDan Fuhry <dan@fuhry.com>
Tue, 8 Apr 2025 22:03:28 +0000 (18:03 -0400)
sd/monitor.go

index 656af853ea44ee27fdccfac265a2559a7706bf06..58a45c0018490f585b703b7713807169b8240fd3 100644 (file)
@@ -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(),