Skip to content

Commit 05b0d60

Browse files
authored
feat: add --skip-failed-instance-config flag, to ignore unix socket connection errors on startup (#2452)
This ports the -skip_failed_instance_config flag from v1 to v2. If set, this will ignore connection errors that occur while creating unix sockets during startup. fixes #2451
1 parent 757f625 commit 05b0d60

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed

cmd/root.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ CPU may be throttled and a background refresh cannot run reliably
527527
against all specified instances. If an instance is unreachable, the Proxy exits with a failure
528528
status code.`)
529529

530+
localFlags.BoolVar(&c.conf.SkipFailedInstanceConfig, "skip-failed-instance-config", false,
531+
`If set, the Proxy will skip any instances that are invalid/unreachable (
532+
only applicable to Unix sockets)`)
533+
530534
// Global and per instance flags
531535
localFlags.StringVarP(&c.conf.Addr, "address", "a", "127.0.0.1",
532536
"(*) Address to bind Cloud SQL instance listeners.")

docs/cmd/cloud-sql-proxy.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ cloud-sql-proxy INSTANCE_CONNECTION_NAME... [flags]
277277
--run-connection-test Runs a connection test
278278
against all specified instances. If an instance is unreachable, the Proxy exits with a failure
279279
status code.
280+
--skip-failed-instance-config If set, the Proxy will skip any instances that are invalid/unreachable (
281+
only applicable to Unix sockets)
280282
--sqladmin-api-endpoint string API endpoint for all Cloud SQL Admin API requests. (default: https://sqladmin.googleapis.com)
281283
-l, --structured-logs Enable structured logging with LogEntry format
282284
--telemetry-prefix string Prefix for Cloud Monitoring metrics.

internal/proxy/proxy.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ type Config struct {
267267
// RunConnectionTest determines whether the Proxy should attempt a connection
268268
// to all specified instances to verify the network path is valid.
269269
RunConnectionTest bool
270+
271+
// SkipFailedInstanceConfig determines whether the Proxy should skip failed
272+
// connections to Cloud SQL instances instead of exiting on startup.
273+
// This only applies to Unix sockets.
274+
SkipFailedInstanceConfig bool
270275
}
271276

272277
// dialOptions interprets appropriate dial options for a particular instance
@@ -546,6 +551,11 @@ func NewClient(ctx context.Context, d cloudsql.Dialer, l cloudsql.Logger, conf *
546551
for _, inst := range conf.Instances {
547552
m, err := c.newSocketMount(ctx, conf, pc, inst)
548553
if err != nil {
554+
if conf.SkipFailedInstanceConfig {
555+
l.Errorf("[%v] Unable to mount socket: %v (skipped due to skip-failed-instance-config flag)", inst.Name, err)
556+
continue
557+
}
558+
549559
for _, m := range mnts {
550560
mErr := m.Close()
551561
if mErr != nil {

internal/proxy/proxy_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,20 @@ func TestClientInitialization(t *testing.T) {
309309
filepath.Join(testUnixSocketPathPg),
310310
},
311311
},
312+
{
313+
desc: "with Unix socket and two instances, one invalid but skipped",
314+
in: &proxy.Config{
315+
UnixSocket: testDir,
316+
Instances: []proxy.InstanceConnConfig{
317+
{Name: pg},
318+
{Name: "proj:region:fakeserver"},
319+
},
320+
SkipFailedInstanceConfig: true,
321+
},
322+
wantUnixAddrs: []string{
323+
filepath.Join(testDir, pg, ".s.PGSQL.5432"),
324+
},
325+
},
312326
{
313327
desc: "with TCP port for non functional instance",
314328
in: &proxy.Config{

migration-guide.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,29 @@ The following table lists in alphabetical order v1 flags and their v2 version.
144144
- ❌: Not supported in V2
145145
- 🤔: Unplanned, but has open feature request
146146

147-
| v1 | v2 | Notes |
148-
| --------------------------- | --------------------- | ------------------------------------------------------------------------------------ |
149-
| check_region || |
150-
| credential_file | credentials-file | |
151-
| dir | unix-socket | |
152-
| enable_iam_login | auto-iam-authn | |
153-
| fd_rlimit | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1258) |
154-
| fuse | fuse | |
155-
| fuse_tmp | fuse-temp-dir | |
156-
| health_check_port | http-port | Use --http-address=0.0.0.0 when using a health check in Kubernetes |
157-
| host | sqladmin-api-endpoint | |
158-
| instances_metadata | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1259) |
159-
| ip_address_types | private-ip | Defaults to public. To connect to a private IP, you must add the --private-ip flag |
160-
| log_debug_stdout || v2 logs to stdout, errors to stderr by default |
161-
| max_connections | max-connections | |
162-
| projects || v2 prefers explicit connection configuration to avoid user error |
163-
| quiet | quiet | quiet disables all logging except errors |
164-
| quota_project | quota-project | |
165-
| refresh_config_throttle || |
166-
| skip_failed_instance_config | | This flag was only necessary with Unix sockets. Use TCP sockets to avoid failed startup. |
167-
| structured_logs | structured-logs | |
168-
| term_timeout | max-sigterm-delay | |
169-
| token | token | |
170-
| use_http_health_check | health-check | |
171-
| verbose || |
172-
| version | version | |
147+
| v1 | v2 | Notes |
148+
| --------------------------- | --------------------------- | ------------------------------------------------------------------------------------ |
149+
| check_region | | |
150+
| credential_file | credentials-file | |
151+
| dir | unix-socket | |
152+
| enable_iam_login | auto-iam-authn | |
153+
| fd_rlimit | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1258) |
154+
| fuse | fuse | |
155+
| fuse_tmp | fuse-temp-dir | |
156+
| health_check_port | http-port | Use --http-address=0.0.0.0 when using a health check in Kubernetes |
157+
| host | sqladmin-api-endpoint | |
158+
| instances_metadata | 🤔 | [Feature Request](https://github.com/GoogleCloudPlatform/cloudsql-proxy/issues/1259) |
159+
| ip_address_types | private-ip | Defaults to public. To connect to a private IP, you must add the --private-ip flag |
160+
| log_debug_stdout | | v2 logs to stdout, errors to stderr by default |
161+
| max_connections | max-connections | |
162+
| projects | | v2 prefers explicit connection configuration to avoid user error |
163+
| quiet | quiet | quiet disables all logging except errors |
164+
| quota_project | quota-project | |
165+
| refresh_config_throttle | | |
166+
| skip_failed_instance_config | skip-failed-instance-config | |
167+
| structured_logs | structured-logs | |
168+
| term_timeout | max-sigterm-delay | |
169+
| token | token | |
170+
| use_http_health_check | health-check | |
171+
| verbose | | |
172+
| version | version | |

0 commit comments

Comments
 (0)