From caf3e5ab5cb5879e79aa4d9ad97dd80f037c245c Mon Sep 17 00:00:00 2001 From: Dan Fuhry Date: Fri, 4 Apr 2025 08:25:50 -0400 Subject: [PATCH] [metricbus] publish server in SD --- metrics/metricbus/internal/server.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/metrics/metricbus/internal/server.go b/metrics/metricbus/internal/server.go index a93927b..30b1407 100644 --- a/metrics/metricbus/internal/server.go +++ b/metrics/metricbus/internal/server.go @@ -18,6 +18,7 @@ import ( "go.fuhry.dev/runtime/constants" "go.fuhry.dev/runtime/metrics/metricbus" "go.fuhry.dev/runtime/mtls" + "go.fuhry.dev/runtime/sd" "go.fuhry.dev/runtime/utils/hashset" "go.fuhry.dev/runtime/utils/hostname" "go.fuhry.dev/runtime/utils/log" @@ -82,6 +83,7 @@ type mbServer struct { httpServer *http.Server httpMux *http.ServeMux listenOn *net.TCPAddr + publisher *sd.SDPublisher startStopMu sync.Mutex } @@ -145,6 +147,12 @@ func NewMetricBusServerWithPort(port uint) (*mbServer, error) { }, listenOn: tcpAddr, servicer: servicer, + publisher: &sd.SDPublisher{ + Protocol: sd.ProtocolTCP, + AdvertisePort: uint16(port), + Service: "otel-tls", + ShardName: fmt.Sprintf("%s-metric-collector", constants.OrgSlug), + }, } server.log.V(1).Infof("Server configured to listen on %s", tcpAddr.String()) @@ -190,6 +198,7 @@ func (s *mbServer) Start(ctx context.Context) error { shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer s.startStopMu.Unlock() + defer s.publisher.Unpublish() defer cancel() defer dbusConn.Close() defer s.httpServer.Shutdown(shutdownCtx) @@ -205,6 +214,10 @@ func (s *mbServer) Start(ctx context.Context) error { } } })() + err = s.publisher.Publish(s.ctx) + if err != nil { + s.log.Warnf("failed to publish service in sd: %v", err) + } s.log.Notice("Server started") -- 2.50.1