From caa6e47c64a3f78d1ab9fe2aeb657ee525b9e3f2 Mon Sep 17 00:00:00 2001 From: Jin Hou Date: Wed, 20 Aug 2025 11:26:00 -0700 Subject: [PATCH 1/3] fix: fix logmessage for usage with domain names --- dialer.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dialer.go b/dialer.go index d43d79ad..c79aec38 100644 --- a/dialer.go +++ b/dialer.go @@ -323,8 +323,9 @@ func NewDialer(ctx context.Context, opts ...Option) (*Dialer, error) { } // Dial returns a net.Conn connected to the specified Cloud SQL instance. The -// icn argument must be the instance's connection name, which is in the format -// "project-name:region:instance-name". +// icn argument may be the instance's connection name in the format +// "project-name:region:instance-name" or a DNS name that resolves to an +// instance connection name. func (d *Dialer) Dial(ctx context.Context, icn string, opts ...DialOption) (conn net.Conn, err error) { select { case <-d.closed: @@ -346,8 +347,9 @@ func (d *Dialer) Dial(ctx context.Context, icn string, opts ...DialOption) (conn return nil, err } // Log if resolver changed the instance name input string. - if cn.String() != icn { - d.logger.Debugf(ctx, "resolved instance %s to %s", icn, cn) + resolvedICN := fmt.Sprintf("%s:%s:%s", cn.Project(), cn.Region(), cn.Name()) + if resolvedICN != icn { + d.logger.Debugf(ctx, "resolved instance %s to %s", icn, resolvedICN) } cfg := d.defaultDialConfig From e62f95acacb98b09b5cf80cd83d9622ed97bffea Mon Sep 17 00:00:00 2001 From: Jin Hou Date: Mon, 25 Aug 2025 15:40:10 -0700 Subject: [PATCH 2/3] fix based on comment --- dialer.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dialer.go b/dialer.go index c79aec38..53ceaef4 100644 --- a/dialer.go +++ b/dialer.go @@ -346,10 +346,14 @@ func (d *Dialer) Dial(ctx context.Context, icn string, opts ...DialOption) (conn if err != nil { return nil, err } + // Log if resolver changed the instance name input string. - resolvedICN := fmt.Sprintf("%s:%s:%s", cn.Project(), cn.Region(), cn.Name()) - if resolvedICN != icn { - d.logger.Debugf(ctx, "resolved instance %s to %s", icn, resolvedICN) + if cn.DomainName() != "" { + // icn is a domain name, which resolves to a actual icn + d.logger.Debugf(ctx, "resolved dns: %s", icn, cn.String()) + } else if cn.String() != icn { + // icn was not a domain name, but the resolver changed it and cn != icn + d.logger.Debugf(ctx, "resolved instance connection string %s to %s", icn, cn.String()) } cfg := d.defaultDialConfig From 289db374adac923a2ed99cf4e60e806e608a2d3e Mon Sep 17 00:00:00 2001 From: Jin Hou Date: Thu, 28 Aug 2025 10:44:54 -0700 Subject: [PATCH 3/3] fix comment format --- dialer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dialer.go b/dialer.go index 53ceaef4..f6b81188 100644 --- a/dialer.go +++ b/dialer.go @@ -350,7 +350,7 @@ func (d *Dialer) Dial(ctx context.Context, icn string, opts ...DialOption) (conn // Log if resolver changed the instance name input string. if cn.DomainName() != "" { // icn is a domain name, which resolves to a actual icn - d.logger.Debugf(ctx, "resolved dns: %s", icn, cn.String()) + d.logger.Debugf(ctx, "resolved domain name %s to %s", icn, cn.String()) } else if cn.String() != icn { // icn was not a domain name, but the resolver changed it and cn != icn d.logger.Debugf(ctx, "resolved instance connection string %s to %s", icn, cn.String())