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: add support for a lazy refresh (#2184) #644

Merged
merged 1 commit into from
May 15, 2024
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
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@ only. Uses the port specified by the http-port flag.`)
localFlags.BoolVar(&c.conf.RunConnectionTest, "run-connection-test", false, `Runs a connection test
against all specified instances. If an instance is unreachable, the Proxy exits with a failure
status code.`)
localFlags.BoolVar(&c.conf.LazyRefresh, "lazy-refresh", false,
`Configure a lazy refresh where connection info is retrieved only if
the cached copy has expired. Use this setting in environments where the
CPU may be throttled and a background refresh cannot run reliably
(e.g., Cloud Run)`,
)

// Global and per instance flags
localFlags.StringVarP(&c.conf.Addr, "address", "a", "127.0.0.1",
Expand Down
8 changes: 8 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ func TestNewCommandArguments(t *testing.T) {
Debug: true,
}),
},
{
desc: "using the lazy refresh flag",
args: []string{"--lazy-refresh",
"projects/proj/locations/region/clusters/clust/instances/inst"},
want: withDefaults(&proxy.Config{
LazyRefresh: true,
}),
},
{
desc: "using the admin port flag",
args: []string{"--admin-port", "7777",
Expand Down
10 changes: 10 additions & 0 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ type Config struct {
// PSC enables connections via the PSC endpoint for all instances.
PSC bool

// LazyRefresh configures the Go Connector to retrieve connection info
// lazily and as-needed. Otherwise, no background refresh cycle runs. This
// setting is useful in environments where the CPU may be throttled outside
// of a request context, e.g., Cloud Run.
LazyRefresh bool

// Token is the Bearer token used for authorization.
Token string

Expand Down Expand Up @@ -326,6 +332,10 @@ func (c *Config) DialerOptions(l alloydb.Logger) ([]alloydbconn.Option, error) {
opts = append(opts, alloydbconn.WithDebugLogger(l))
}

if c.LazyRefresh {
opts = append(opts, alloydbconn.WithLazyRefresh())
}

return opts, nil
}

Expand Down
Loading