Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func dialOptions(c Config, i InstanceConnConfig) []cloudsqlconn.DialOption {
if i.IAMAuthN != nil {
opts = append(opts, cloudsqlconn.WithDialIAMAuthN(*i.IAMAuthN))
}
if i.SQLDataEnabled != nil && *i.SQLDataEnabled || c.SQLDataEnabled {
if sqlDataEnabled(&c, i) {
opts = append(opts, cloudsqlconn.WithSQLData())
}

Expand Down Expand Up @@ -641,7 +641,7 @@ func NewClient(ctx context.Context, d cloudsql.Dialer, l cloudsql.Logger, conf *
// unless the proxy is in SqlDataEnabled mode, initiate a refresh operation to warm the cache
for _, inst := range conf.Instances {
// Skip instances with SqlDataEnabled
if conf.SQLDataEnabled || inst.SQLDataEnabled != nil && *inst.SQLDataEnabled {
if sqlDataEnabled(conf, inst) {
continue
}
go func(name string) { _, _ = d.EngineVersion(ctx, name) }(inst.Name)
Expand Down Expand Up @@ -904,6 +904,15 @@ type socketMount struct {
dialOpts []cloudsqlconn.DialOption
}

// sqlDataEnabled reports whether the instance connects through the SQL Data
// API. A value set on the instance takes precedence over the global setting.
func sqlDataEnabled(conf *Config, inst InstanceConnConfig) bool {
if inst.SQLDataEnabled != nil {
return *inst.SQLDataEnabled
}
return conf.SQLDataEnabled
}

func networkType(conf *Config, inst InstanceConnConfig) string {
if (conf.UnixSocket == "" && inst.UnixSocket == "" && inst.UnixSocketPath == "") ||
(inst.Addr != "" || inst.Port != 0) {
Expand Down Expand Up @@ -951,7 +960,7 @@ func (c *Client) newSocketMount(ctx context.Context, conf *Config, pc *portConfi
np = inst.Port
case conf.Port != 0:
np = pc.nextPort()
case conf.SQLDataEnabled || inst.SQLDataEnabled != nil && *inst.SQLDataEnabled:
case sqlDataEnabled(conf, inst):
// TODO: Only Postgres is supported by the SqlDataService
// when more engines are supported, this code will need to change.
np = pc.nextDBPort("POSTGRES")
Expand All @@ -971,7 +980,7 @@ func (c *Client) newSocketMount(ctx context.Context, conf *Config, pc *portConfi

var version string
switch {
case conf.SQLDataEnabled || inst.SQLDataEnabled != nil && *inst.SQLDataEnabled:
case sqlDataEnabled(conf, inst):
version = "POSTGRES"
default:
var err error
Expand Down
27 changes: 27 additions & 0 deletions internal/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ func TestClientInitialization(t *testing.T) {
"127.0.0.1:60000",
},
},
{
desc: "with SQL Data enabled globally but disabled per-instance",
in: &proxy.Config{
Addr: "127.0.0.1",
SQLDataEnabled: true,
Instances: []proxy.InstanceConnConfig{
{Name: sd},
{Name: mysql, SQLDataEnabled: pointer(false)},
},
},
wantTCPAddrs: []string{
"127.0.0.1:5432",
"127.0.0.1:3306",
},
},
{
desc: "with a Unix socket",
in: &proxy.Config{
Expand Down Expand Up @@ -735,6 +750,18 @@ func TestSQLDataWarmup(t *testing.T) {
},
want: 0,
},
{
desc: "warmup not skipped when disabled per-instance",
in: &proxy.Config{
SQLDataEnabled: true,
Instances: []proxy.InstanceConnConfig{{
Name: "proj:reg:inst",
Port: 30107,
SQLDataEnabled: pointer(false),
}},
},
want: 1,
},
}

for _, tc := range tcs {
Expand Down
Loading