proxy

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseInstanceURI added in v1.1.0

func ParseInstanceURI(inst string) (string, string, string, string, error)

ParseInstanceURI validates the instance uri is in the proper format and returns the project, region, cluster, and instance name.

func ShortInstURI added in v1.1.0

func ShortInstURI(inst string) (string, error)

ShortInstURI shortens the instance URI into project.region.cluster.instance.

func SupportsFUSE added in v0.6.0

func SupportsFUSE() error

SupportsFUSE checks if the fusermount binary is present in the PATH or a well known location.

func UnixAddress added in v0.6.0

func UnixAddress(dir, inst string) string

UnixAddress is defined as a function to distinguish between Unix-based implementations where the dir and inst are simply joined, and Windows-based implementations where the inst must be further altered.

func UnixSocketDir added in v0.3.0

func UnixSocketDir(dir, inst string) (string, error)

UnixSocketDir returns a shorted instance connection name to prevent exceeding the Unix socket length, e.g., project.region.cluster.instance

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client proxies connections from a local client to the remote server side proxy for multiple AlloyDB instances.

func NewClient

func NewClient(ctx context.Context, d alloydb.Dialer, l alloydb.Logger, conf *Config) (*Client, error)

NewClient completes the initial setup required to get the proxy to a "steady" state.

func (*Client) CheckConnections added in v0.5.0

func (c *Client) CheckConnections(ctx context.Context) (int, error)

CheckConnections dials each registered instance and reports the number of connections checked and any errors that may have occurred.

func (*Client) Close

func (c *Client) Close() error

Close stops the dialer, closes any open FUSE mounts and any open listeners, and optionally waits for all connections to close before exiting.

func (*Client) ConnCount added in v0.5.0

func (c *Client) ConnCount() (uint64, uint64)

ConnCount returns the number of open connections and the maximum allowed connections. Returns 0 when the maximum allowed connections have not been set.

func (*Client) Lookup added in v0.6.0

func (c *Client) Lookup(ctx context.Context, instance string, _ *fuse.EntryOut) (*fs.Inode, syscall.Errno)

Lookup implements the fs.NodeLookuper interface and returns an index node (inode) for a symlink that points to a Unix domain socket. The Unix domain socket is connected to the requested Cloud SQL instance. Lookup returns a symlink (instead of the socket itself) so that multiple callers all use the same Unix socket.

func (*Client) Readdir added in v0.6.0

func (c *Client) Readdir(_ context.Context) (fs.DirStream, syscall.Errno)

Readdir returns a list of all active Unix sockets in addition to the README.

func (*Client) Serve

func (c *Client) Serve(ctx context.Context, notify func()) error

Serve starts proxying connections for all configured instances using the associated socket.

type Config

type Config struct {
	// UserAgent is the user agent to use when sending requests to the Admin
	// API.
	UserAgent string

	// AutoIAMAuthN enabled automatic IAM authentication which results in the
	// Proxy sending the IAM principal's OAuth2 token to the backend to enable
	// a passwordless login for callers.
	AutoIAMAuthN bool

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

	// CredentialsFile is the path to a service account key.
	CredentialsFile string

	// CredentialsJSON is a JSON representation of the service account key.
	CredentialsJSON string

	// GcloudAuth set whether to use Gcloud's config helper to retrieve a
	// token for authentication.
	GcloudAuth bool

	// Addr is the address on which to bind all instances.
	Addr string

	// Port is the initial port to bind to. Subsequent instances bind to
	// increments from this value.
	Port int

	// UnixSocket is the directory where Unix sockets will be created,
	// connected to any Instances. If set, takes precedence over Addr and Port.
	UnixSocket string

	// FUSEDir enables a file system in user space at the provided path that
	// connects to the requested instance only when a client requests it.
	FUSEDir string

	// FUSETempDir sets the temporary directory where the FUSE mount will place
	// Unix domain sockets connected to Cloud SQL instances. The temp directory
	// is not accessed directly.
	FUSETempDir string

	// APIEndpointURL is the URL of the AlloyDB Admin API.
	APIEndpointURL string

	// Instances are configuration for individual instances. Instance
	// configuration takes precedence over global configuration.
	Instances []InstanceConnConfig

	// MaxConnections are the maximum number of connections the Client may
	// establish to the AlloyDB server side proxy before refusing additional
	// connections. A zero-value indicates no limit.
	MaxConnections uint64

	// WaitOnClose sets the duration to wait for connections to close before
	// shutting down. Not setting this field means to close immediately
	// regardless of any open connections.
	WaitOnClose time.Duration

	// ImpersonationChain is a comma separated list of one or more service
	// accounts. The first entry in the chain is the impersonation target. Any
	// additional service accounts after the target are delegates. The
	// roles/iam.serviceAccountTokenCreator must be configured for each account
	// that will be impersonated.
	ImpersonationChain string

	// StructuredLogs sets all output to use JSON in the LogEntry format.
	// See https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry
	StructuredLogs bool

	// Quiet controls whether only error messages are logged.
	Quiet bool

	// TelemetryProject enables sending metrics and traces to the specified project.
	TelemetryProject string
	// TelemetryPrefix sets a prefix for all emitted metrics.
	TelemetryPrefix string
	// TelemetryTracingSampleRate sets the rate at which traces are
	// samples. A higher value means fewer traces.
	TelemetryTracingSampleRate int
	// DisableTraces disables tracing when TelemetryProject is set.
	DisableTraces bool
	// DisableMetrics disables metrics when TelemetryProject is set.
	DisableMetrics bool

	// Prometheus enables a Prometheus endpoint served at the address and
	// port specified by HTTPAddress and HTTPPort.
	Prometheus bool
	// PrometheusNamespace configures the namespace underwhich metrics are written.
	PrometheusNamespace string

	// HealthCheck enables a health check server. It's address and port are
	// specified by HTTPAddress and HTTPPort.
	HealthCheck bool

	// HTTPAddress sets the address for the health check and prometheus server.
	HTTPAddress string
	// HTTPPort sets the port for the health check and prometheus server.
	HTTPPort string
	// AdminPort configures the port for the localhost-only admin server.
	AdminPort string

	// Debug enables a debug handler on localhost.
	Debug bool
	// QuitQuitQuit enables a handler that will shut the Proxy down upon
	// receiving a POST request.
	QuitQuitQuit bool

	// OtherUserAgents is a list of space separate user agents that will be
	// appended to the default user agent.
	OtherUserAgents string

	// RunConnectionTest determines whether the Proxy should attempt a connection
	// to all specified instances to verify the network path is valid.
	RunConnectionTest bool
}

Config contains all the configuration provided by the caller.

func (*Config) DialerOptions added in v0.4.0

func (c *Config) DialerOptions(l alloydb.Logger) ([]alloydbconn.Option, error)

DialerOptions builds appropriate list of options from the Config values for use by alloydbconn.NewClient()

type InstanceConnConfig

type InstanceConnConfig struct {
	// Name is the instance URI.
	Name string
	// Addr is the address on which to bind a listener for the instance.
	Addr string
	// Port is the port on which to bind a listener for the instance.
	Port int
	// UnixSocket is the directory where a Unix socket will be created,
	// connected to the AlloyDB instance. If set, takes precedence over Addr
	// and Port.
	UnixSocket string
	// UnixSocketPath is the path where a Unix socket will be created,
	// connected to the Cloud SQL instance. The full path to the socket will be
	// UnixSocketPath. Because this is a Postgres database, the proxy will ensure
	// the last path element is `.s.PGSQL.5432`, appending this path element if
	// necessary. If set, UnixSocketPath takes precedence over UnixSocket, Addr
	// and Port.
	UnixSocketPath string

	// AutoIAMAuthN enables automatic IAM authentication on the instance only.
	// See Config.AutoIAMAuthN for more details.
	AutoIAMAuthN bool
}

InstanceConnConfig holds the configuration for an individual instance connection.

type MultiErr added in v0.4.0

type MultiErr []error

MultiErr is a group of errors wrapped into one.

func (MultiErr) Error added in v0.4.0

func (m MultiErr) Error() string

Error returns a single string representing one or more errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL