Skip to content
Draft
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
24 changes: 24 additions & 0 deletions cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ func WithAutoIP() Option {
}
}

// WithProxyV1Compatibility enables legacy behavior of v1 and will print
// out "Ready for new connections" when the proxy starts.
func WithProxyV1Compatibility() Option {
return func(c *Command) {
c.conf.ProxyV1Compatibility = true
}
}

// WithProxyV1LogDebugStdout enables legacy behavior of v1 and will print
// debug/info logs to stdout instead of stderr.
func WithProxyV1LogDebugStdout() Option {
return func(c *Command) {
c.conf.LogDebugStdout = true
}
}

// WithProxyV1Verbose enables legacy behavior of v1 and will set
// the debug-logs flag on the v2 proxy.
func WithProxyV1Verbose(v bool) Option {
return func(c *Command) {
c.conf.DebugLogs = v
}
}

// WithQuietLogging configures the Proxy to log error messages only.
func WithQuietLogging() Option {
return func(c *Command) {
Expand Down
30 changes: 30 additions & 0 deletions cmd/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,36 @@ func TestCommandOptions(t *testing.T) {
},
option: WithLazyRefresh(),
},
{
desc: "with proxy v1 compatibility",
isValid: func(c *Command) error {
if !c.conf.ProxyV1Compatibility {
return errors.New("compatibility was false, but should be true")
}
return nil
},
option: WithProxyV1Compatibility(),
},
{
desc: "with proxy v1 verbose true",
isValid: func(c *Command) error {
if !c.conf.DebugLogs {
return errors.New("DebugLogs was false, but should be true")
}
return nil
},
option: WithProxyV1Verbose(true),
},
{
desc: "with proxy v1 verbose false",
isValid: func(c *Command) error {
if c.conf.DebugLogs {
return errors.New("DebugLogs was true, but should be false")
}
return nil
},
option: WithProxyV1Verbose(false),
},
}

for _, tc := range tcs {
Expand Down
12 changes: 11 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ func semanticVersion() string {
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := NewCommand().Execute(); err != nil {
ExecuteCommand(NewCommand())
}

// ExecuteCommand runs a preconfigured command, and exits the appropriate error code.
func ExecuteCommand(c *Command) {
if err := c.Execute(); err != nil {
exit := 1
var terr *exitError
if errors.As(err, &terr) {
Expand Down Expand Up @@ -646,6 +651,8 @@ func loadConfig(c *Command, args []string, opts []Option) error {

if c.conf.Quiet {
c.logger = log.NewStdLogger(io.Discard, os.Stderr)
} else if c.conf.LogDebugStdout {
c.logger = log.NewStdLogger(os.Stdout, os.Stderr)
}

err = parseConfig(c, c.conf, args)
Expand Down Expand Up @@ -1105,6 +1112,9 @@ func runSignalWrapper(cmd *Command) (err error) {
return err
case p = <-startCh:
cmd.logger.Infof("The proxy has started successfully and is ready for new connections!")
if cmd.conf.ProxyV1Compatibility {
cmd.logger.Infof("Ready for new connections")
}
// If running under systemd with Type=notify, it will send a message to the
// service manager that it is ready to handle connections now.
go func() {
Expand Down
8 changes: 8 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ type Config struct {
// endpoint for all instances
PSC bool

// ProxyV1Compatibility supports a legacy behavior where the Proxy will
// print out "Ready for new connections" when the proxy starts.
ProxyV1Compatibility bool

// LogDebugStdout supports a legacy behavior where the Proxy will
// print debug/info logs to stdout instead of stderr.
LogDebugStdout bool

// AutoIP supports a legacy behavior where the Proxy will connect to
// the first IP address returned from the SQL ADmin API response. This
// setting should be avoided and used only to support legacy Proxy
Expand Down
Loading