@@ -22,6 +22,7 @@ import (
2222 "log"
2323 "math"
2424 "math/rand"
25+ "net"
2526 "net/url"
2627 "slices"
2728 "sort"
@@ -47,6 +48,30 @@ var maxDrainingTimeout = 30 * time.Minute
4748
4849const requestParamsHeader = "x-goog-request-params"
4950
51+ // ipProtocol represents the type of IP protocol used.
52+ type ipProtocol int32
53+
54+ const (
55+ // unknown represents an unknown or undetermined IP protocol.
56+ unknown ipProtocol = iota - 1
57+ // ipv6 represents the IPv4 protocol.
58+ ipv4
59+ // ipv6 represents the IPv6 protocol.
60+ ipv6
61+ )
62+
63+ // AddressType returns the string representation of the IPProtocol.
64+ func (ip ipProtocol ) addressType () string {
65+ switch ip {
66+ case ipv4 :
67+ return "ipv4"
68+ case ipv6 :
69+ return "ipv6"
70+ default :
71+ return "unknown"
72+ }
73+ }
74+
5075// BigtableChannelPoolOption options for configurable
5176type BigtableChannelPoolOption func (* BigtableChannelPool )
5277
@@ -111,6 +136,13 @@ type BigtableConn struct {
111136 * grpc.ClientConn
112137 isALTSConn atomic.Bool
113138 createdAt atomic.Int64
139+ // remoteAddrType stores the type: -1 (unknown/nil), 0 (ipv4), 1 (ipv6)
140+ remoteAddrType atomic.Int32
141+ }
142+
143+ // ipProtocol returns the IP protocol as a string: "ipv4", "ipv6", or "unknown".
144+ func (bc * BigtableConn ) ipProtocol () string {
145+ return ipProtocol (bc .remoteAddrType .Load ()).addressType ()
114146}
115147
116148// Prime sends a PingAndWarm request to warm up the connection.
@@ -137,6 +169,19 @@ func (bc *BigtableConn) Prime(ctx context.Context, fullInstanceName, appProfileI
137169 return err
138170 }
139171
172+ // ip protocol will be -1 if it addr is nil/default, 0 is ipv4 and 1 if ipv6.
173+ if p .Addr != nil {
174+ if tcpAddr , ok := p .Addr .(* net.TCPAddr ); ok {
175+ if tcpAddr .IP != nil {
176+ if tcpAddr .IP .To4 () != nil {
177+ bc .remoteAddrType .Store (int32 (ipv4 ))
178+ } else {
179+ bc .remoteAddrType .Store (int32 (ipv6 ))
180+ }
181+ }
182+ }
183+ }
184+
140185 if p .AuthInfo != nil {
141186 if _ , ok := p .AuthInfo .(alts.AuthInfo ); ok {
142187 bc .isALTSConn .Store (true )
@@ -173,8 +218,8 @@ func NewBigtableConn(conn *grpc.ClientConn) *BigtableConn {
173218 ClientConn : conn ,
174219 }
175220 bc .createdAt .Store (time .Now ().UnixMilli ())
221+ bc .remoteAddrType .Store (int32 (unknown ))
176222 return bc
177-
178223}
179224
180225// createdAt returns the creation time of the connection in int64. milliseconds since epoch
0 commit comments