Skip to content

Support DNS configuration and automatic failover. #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hessjcg opened this issue Feb 25, 2025 · 0 comments · Fixed by #427 or #429
Closed

Support DNS configuration and automatic failover. #421

hessjcg opened this issue Feb 25, 2025 · 0 comments · Fixed by #427 or #429
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@hessjcg
Copy link
Collaborator

hessjcg commented Feb 25, 2025

The connector may be configured to connect to a Cloud SQL instance using a DNS name.

When a connection is configured with a DNS name (instead of an instance name), the connector will query the local DNS for a TXT record. The TXT should contain an instance name matching that DNS name. The connector will use the instance name from the TXT record to connect to the Cloud SQL instance.

The connector will periodically query that DNS. If the instance name in the DNS record changes, the connector will terminate all open connections to the old instance. Then, it will reconfigure itself to open connections to the new instance.

Users can configure their database clients using the domain name instead of the instance name.
Users can fail-over database clients when they change the DNS entry for the database instance.

This feature is implemented in all of the connectors:

@hessjcg hessjcg added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Feb 25, 2025
hessjcg added a commit that referenced this issue Mar 11, 2025
. (#424)

Add CloudSqlInstance.close() to stop the refresh cycle permanently.

Change CloudSqlInstance.forceRefresh() so that it schedules a refresh and returns immediately.
This should not return a promise. Update test cases to account for changes.

Part of #421
hessjcg added a commit that referenced this issue Mar 17, 2025
Update InstanceConnectionName and parseInstanceConnectionName() to allow DNS names
as well as instance connection names. Add test cases to cover DNS Names. Add new dns-lookup.ts
that looks up the instance connection name from a DNS name using the TXT record.

Part of #421
hessjcg added a commit that referenced this issue Mar 17, 2025
The connector may be configured to use a DNS name to look up the instance
name instead of configuring the connector with the instance name directly.

Add a DNS TXT record for the Cloud SQL instance to a private DNS server
or a private Google Cloud DNS Zone used by your application. For example:

- Record type: TXT
- Name: prod-db.mycompany.example.com – This is the domain name used by the application
- Value: my-project:region:my-instance – This is the instance connection name

Configure the dialer with the cloudsqlconn.WithDNSResolver() option.

Open a database connection using the DNS name:

```
const clientOpts = await connector.getOptions({
  domainName: "db.example.com",
});
```

Part of #421

See also: GoogleCloudPlatform/cloud-sql-go-connector#843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
2 participants