Skip to content
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

feat: deprecate proxy drivers #1500

Merged
merged 2 commits into from
Oct 24, 2022
Merged
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
12 changes: 12 additions & 0 deletions proxy/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Cloud SQL proxy dialer for Go

## Note

This package is deprecated. Instead use the [Cloud SQL Go
Connector][go-connector] which has support for MySQL, Postgres, and SQL Server,
in addition to better configurability, support for metrics and tracing, and a
number of additional features. See the [migration guide][migration-guide] for
how to switch.

## Overview

You can also use the Cloud SQL proxy directly from a Go program.

These packages are primarily used as implementation for the Cloud SQL proxy
Expand Down Expand Up @@ -31,3 +41,5 @@ See [example usage](dialers/postgres/hook_test.go).
[Python]: https://github.com/GoogleCloudPlatform/cloud-sql-python-connector
[go-mysql]: https://github.com/go-sql-driver/mysql
[mysql-godoc]: https://pkg.go.dev/github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql
[go-connector]: https://pkg.go.dev/cloud.google.com/go/cloudsqlconn
[migration-guide]: https://github.com/GoogleCloudPlatform/cloud-sql-go-connector/blob/main/migration-guide.md
16 changes: 16 additions & 0 deletions proxy/dialers/mysql/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func init() {
//
// The returned *sql.DB may be valid even if there's also an error returned
// (e.g. if there was a transient connection error).
//
// Deprecated: Dial has been replaced by the Cloud SQL Go connector which has
// better support for configuring the dialer's behavior.
// See cloud.google.com/go/cloudsqlconn/mysql/mysql.RegisterDriver instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unlikely to be seen unless someone reads the code - should we consider adding a 1 time log warning or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to put this front and center, but since we don't know how people are setting up their logging system, the best we could do is log to stdout which would be an intrusive change. I think we'll have to advertise this change in the new release.

func Dial(instance, user string) (*sql.DB, error) {
cfg := mysql.NewConfig()
cfg.User = user
Expand All @@ -51,6 +55,10 @@ func Dial(instance, user string) (*sql.DB, error) {
// information, see:
//
// https://cloud.google.com/sql/docs/sql-proxy#user
//
// Deprecated: DialPassword has been replaced by the Cloud SQL Go connector
// which has better support for configuring the dialer's behavior. See
// cloud.google.com/go/cloudsqlconn/mysql/mysql.RegisterDriver instead.
func DialPassword(instance, user, password string) (*sql.DB, error) {
cfg := mysql.NewConfig()
cfg.User = user
Expand All @@ -63,6 +71,10 @@ func DialPassword(instance, user, password string) (*sql.DB, error) {
// provided instance via the given user and password. The config can be
// modified and passed to DialCfg to connect. If you don't modify the returned
// config before dialing, consider using Dial or DialPassword.
//
// Deprecated: Cfg has been replaced by the Cloud SQL Go connector which has
// better support for configuring the dialer's behavior.
// See cloud.google.com/go/cloudsqlconn/mysql/mysql.RegisterDriver instead.
func Cfg(instance, user, password string) *mysql.Config {
cfg := mysql.NewConfig()
cfg.User = user
Expand All @@ -78,6 +90,10 @@ func Cfg(instance, user, password string) *mysql.Config {
// The cfg.Addr should be the instance's connection string, in the format of:
//
// project-name:region:instance-name.
//
// Deprecated: DialCfg has been replaced by the Cloud SQL Go connector which has
// better support for configuring the dialer's behavior. See
// cloud.google.com/go/cloudsqlconn/mysql/mysql.RegisterDriver instead.
func DialCfg(cfg *mysql.Config) (*sql.DB, error) {
if cfg.TLSConfig != "" {
return nil, errors.New("do not specify TLS when using the Proxy")
Expand Down
14 changes: 14 additions & 0 deletions proxy/dialers/postgres/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ type dialer struct{}
// lib/pq returns the format '[project:region:instance]:port'
var instanceRegexp = regexp.MustCompile(`^\[(.+)\]:[0-9]+$`)

// Dial connects to the provider Cloud SQL instance.
//
// Deprecated: Dial has been replaced by the Cloud SQL Go connector which has
// better support for configuring the dialer's behavior. See
// cloud.google.com/go/cloudsqlconn/postgres/pgxv4.RegisterDriver instead.
func (d dialer) Dial(ntw, addr string) (net.Conn, error) {
matches := instanceRegexp.FindStringSubmatch(addr)
if len(matches) != 2 {
Expand All @@ -52,10 +57,19 @@ func (d dialer) Dial(ntw, addr string) (net.Conn, error) {
return proxy.Dial(instance)
}

// DialTimeout connects to the provider Cloud SQL instance using the provided
// timeout.
//
// Deprecated: DialTimeout has been replaced by the Cloud SQL Go connector which
// has better support for configuring the dialer's behavior. See
// cloud.google.com/go/cloudsqlconn/postgres/pgxv4.RegisterDriver instead.
func (d dialer) DialTimeout(ntw, addr string, timeout time.Duration) (net.Conn, error) {
return nil, fmt.Errorf("timeout is not currently supported for cloudsqlpostgres dialer")
}

// Deprecated: Open has been replaced by the Cloud SQL Go connector which has
// better support for configuring the dialer's behavior. See
// cloud.google.com/go/cloudsqlconn/postgres/pgxv4.RegisterDriver instead.
func (d *Driver) Open(name string) (driver.Conn, error) {
return pq.DialOpen(dialer{}, name)
}