From a7a00db86c1b3fe5f132c6bf20a7fc2e06db0d03 Mon Sep 17 00:00:00 2001 From: Dan Fuhry Date: Thu, 3 Apr 2025 23:38:58 -0400 Subject: [PATCH] health-exporter: include node name in labels, publish under correct otel-tls service --- sd/etcd_factory.go | 15 +++++++++------ sd/health_exporter/main.go | 10 +++++++++- sd/monitor.go | 2 ++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/sd/etcd_factory.go b/sd/etcd_factory.go index f264ed4..5212ace 100644 --- a/sd/etcd_factory.go +++ b/sd/etcd_factory.go @@ -37,7 +37,7 @@ func NewDefaultEtcdClient() (*etcd_client.Client, error) { return nil, err } - clientSingleton, err = NewEtcdClient(id) + clientSingleton, err = NewEtcdClient(id, etcdDiscoveryDomain) if err == nil { break } @@ -52,14 +52,14 @@ func NewDefaultEtcdClient() (*etcd_client.Client, error) { return clientSingleton, nil } -func NewEtcdClient(id mtls.Identity) (*etcd_client.Client, error) { +func NewEtcdClient(id mtls.Identity, domain string) (*etcd_client.Client, error) { deadline := time.Now().Add(time.Millisecond * time.Duration(etcdStartupTimeoutMs)) return NewEtcdClientWithDeadline( - id, deadline) + id, domain, deadline) } -func NewEtcdClientWithDeadline(id mtls.Identity, deadline time.Time) (*etcd_client.Client, error) { +func NewEtcdClientWithDeadline(id mtls.Identity, domain string, deadline time.Time) (*etcd_client.Client, error) { var client *etcd_client.Client tlsConfig, err := id.TlsConfig(context.Background()) @@ -68,9 +68,12 @@ func NewEtcdClientWithDeadline(id mtls.Identity, deadline time.Time) (*etcd_clie } pnv := mtls.NewPeerNameVerifier() pnv.AllowFrom(mtls.Service, "etcd") - pnv.ConfigureClient(tlsConfig) + err = pnv.ConfigureClient(tlsConfig) + if err != nil { + return nil, err + } - clients, err := srv.GetClient("etcd-client", etcdDiscoveryDomain, "") + clients, err := srv.GetClient("etcd-client", domain, "") if err != nil { return nil, fmt.Errorf("failed to discover peers: %v", err) } diff --git a/sd/health_exporter/main.go b/sd/health_exporter/main.go index 6b7c87e..bd58ab1 100644 --- a/sd/health_exporter/main.go +++ b/sd/health_exporter/main.go @@ -9,6 +9,7 @@ import ( "net" "net/http" "os/signal" + "strings" "sync" "syscall" @@ -64,6 +65,12 @@ func main() { "protocol=%q,service=%q,monitor_host=%q,monitor_region=%q", s.Protocol, s.Service, s.MonitorHost, s.MonitorRegion) + if s.Node == "" { + nodeName := strings.Split(s.MonitorHost, ".")[0] + labels += fmt.Sprintf(",node_name=%q", nodeName) + } else { + labels += fmt.Sprintf(",node_name=%q", s.Shard) + } if s.Shard != "" { labels += fmt.Sprintf(",shard_name=%q", s.Shard) } @@ -88,7 +95,8 @@ func main() { publisher := &sd.SDPublisher{ AdvertisePort: tcpAddr.AddrPort().Port(), Protocol: sd.ProtocolTCP, - Service: "health-exporter", + Service: "otel-tls", + ShardName: "health-exporter", } publisher.Publish(ctx) diff --git a/sd/monitor.go b/sd/monitor.go index 579d6ab..656af85 100644 --- a/sd/monitor.go +++ b/sd/monitor.go @@ -25,6 +25,7 @@ type SDHealthReport struct { Up bool Domain string Shard string + Node string ShardRegion string Protocol string Service string @@ -114,6 +115,7 @@ func (sdp *healthCheckingPublisher) updateHealth(ctx context.Context, lease *etc SocketPort: sdp.publisher.AdvertisePort, Domain: sdp.publisher.Domain, Shard: sdp.publisher.ShardName, + Node: sdp.publisher.NodeName, ShardRegion: strings.Split(sdp.publisher.AdvertiseHost, ".")[1], Protocol: sdp.healthcheck.ServiceDefinition().Engine, MonitorHost: hostname.Fqdn(), -- 2.50.1