From 19098ff37318dc411a06d0771ce16787f4aaa044 Mon Sep 17 00:00:00 2001 From: Vivek Singh Chauhan Date: Mon, 11 Nov 2024 17:59:01 +0000 Subject: [PATCH] INT - override resolver for gRPC --- pkg/watchmanager/manager.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pkg/watchmanager/manager.go b/pkg/watchmanager/manager.go index cd741555f..608bb93f4 100644 --- a/pkg/watchmanager/manager.go +++ b/pkg/watchmanager/manager.go @@ -13,6 +13,7 @@ import ( "github.com/Axway/agent-sdk/pkg/watchmanager/proto" "github.com/google/uuid" "google.golang.org/grpc" + gr "google.golang.org/grpc/resolver" ) // NewManagerFunc func signature to create a Manager @@ -87,6 +88,7 @@ func (m *watchManager) createConnection() (*grpc.ClientConn, error) { logrusStreamClientInterceptor(m.options.loggerEntry), ), grpc.WithUserAgent(m.cfg.UserAgent), + grpc.WithResolvers(&builder{m.cfg.Host, m.cfg.Port}), } m.logger. @@ -97,6 +99,36 @@ func (m *watchManager) createConnection() (*grpc.ClientConn, error) { return grpc.NewClient(address, grpcDialOptions...) } +type builder struct { + host string + port uint32 +} + +func (b *builder) Build(target gr.Target, cc gr.ClientConn, _ gr.BuildOptions) (gr.Resolver, error) { + cc.UpdateState(gr.State{Endpoints: []gr.Endpoint{ + { + Addresses: []gr.Address{ + { + Addr: fmt.Sprintf("%s:%d", b.host, b.port), + ServerName: b.host, + }, + }, + }, + }}) + return &nopResolver{}, nil +} + +func (b *builder) Scheme() string { + return b.host +} + +type nopResolver struct { +} + +func (*nopResolver) ResolveNow(gr.ResolveNowOptions) {} + +func (*nopResolver) Close() {} + func (m *watchManager) getDialer(targetAddr string) (util.Dialer, error) { if m.options.singleEntryAddr == "" && m.options.proxyURL == "" { return nil, nil