component

package
v0.0.0-...-8d377ce Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package component implements reusable bits for cloud service components. Each component is currently defined as being a standalone Go binary with its own internal gRPC listener. Subsequent listeners (eg. public gRPC or HTTP) can be defined by users of this library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CockroachConfig

type CockroachConfig struct {
	// Migrations is the go-migrate source of migrations for this database. Usually
	// this can be taken from a go-embedded set of migration files.
	Migrations source.Driver

	// EndpointHost is the host part of the endpoint address of the database server.
	EndpointHost string
	// TLSKeyPath is the filesystem path of the x509 key used to authenticate to the
	// database server.
	TLSKeyPath string
	// TLSKeyPath is the filesystem path of the x509 certificate used to
	// authenticate to the database server.
	TLSCertificatePath string
	// TLSCACertificatePath is the filesystem path of the x509 CA certificate used
	// to verify the database server's certificate.
	TLSCACertificatePath string
	// UserName is the username to be used on the database server.
	UserName string
	// UserName is the database name to be used on the database server.
	DatabaseName string

	// InMemory indicates that an in-memory CockroachDB instance should be used.
	// Data will be lost after the component shuts down.
	InMemory bool
	// contains filtered or unexported fields
}

CockroachConfig is the common configuration of a components' connection to CockroachDB. It's supposed to be instantiated within a Configuration struct of a component.

It can be configured by flags (via RegisterFlags) or manually (eg. in tests).

func (*CockroachConfig) Connect

func (d *CockroachConfig) Connect() (*sql.DB, error)

Connect returns a working *sql.DB handle to the database described by this CockroachConfig.

func (*CockroachConfig) MigrateDownDangerDanger

func (d *CockroachConfig) MigrateDownDangerDanger() error

MigrateDownDangerDanger removes all data from the database by performing a full migration down.

Let me reiterate: this function, by design, DESTROYS YOUR DATA.

Obviously, this is a dangerous method. Thus, to prevent accidental nuking of production data, we currently only allow this to be performed on InMemory databases.

func (*CockroachConfig) MigrateUp

func (d *CockroachConfig) MigrateUp() error

MigrateUp performs all possible migrations upwards for the database described by this CockroachConfig.

func (*CockroachConfig) MigrateUpToIncluding

func (d *CockroachConfig) MigrateUpToIncluding(ver uint) error

func (*CockroachConfig) RegisterFlags

func (c *CockroachConfig) RegisterFlags(prefix string)

RegisterFlags registers the connection configuration to be provided by flags. This must be called exactly once before then calling flags.Parse().

type ComponentConfig

type ComponentConfig struct {
	// GRPCKeyPath is the filesystem path of the x509 key used to serve internal
	// gRPC traffic.
	GRPCKeyPath string
	// GRPCCertificatePath is the filesystem path of the x509 certificate used to
	// serve internal gRPC traffic.
	GRPCCertificatePath string
	// GRPCCAPath is the filesystem path of of the x509 CA certificate used to
	// verify incoming connections on internal gRPC traffic.
	GRPCCAPath string
	// GRPCListenAddress is the address on which the component should server
	// internal gRPC traffic.
	GRPCListenAddress string

	// DevCerts, if enabled, automatically generates development CA and component
	// certificates/keys at DevCertsPath, uses these to serve traffic.
	DevCerts bool
	// DevCertsPath sets the prefix in which DevCerts are generated. All components
	// should have the same path set so that they reuse the CA certificate.
	DevCertsPath string

	// ComponentName is the name of this component, which should be [a-z0-9+]. It's
	// used to prefix all flags set by the Configuration.
	ComponentName string

	// PrometheusListenAddress is the address on which the component should serve
	// Prometheus metrics.
	PrometheusListenAddress string
	// PrometheusInsecure enables serving Prometheus metrics without any TLS, running
	// a plain HTTP listener. If disabled, Prometheus metrics are served using the
	// same PKI setup as the components' gRPC server.
	PrometheusInsecure bool
	// contains filtered or unexported fields
}

ComponentConfig is the common configuration of a component. It's supposed to be instantiated within a Configuration struct of a component.

It can be configured by flags (via RegisterFlags) or manually (eg. in tests).

func (*ComponentConfig) GRPCServerOptions

func (c *ComponentConfig) GRPCServerOptions() []grpc.ServerOption

GRPCServerOptions returns pre-built grpc.ServerOptions that this component should use to serve internal gRPC.

func (*ComponentConfig) GRPCServerOptionsPublic

func (c *ComponentConfig) GRPCServerOptionsPublic() []grpc.ServerOption

GRPCServerOptionsPublic returns pre-built grpc.ServerOptions that this component should use to serve public gRPC. Any client will be allowed to connect, and it's up to the server implementation to authenticate incoming requests.

func (*ComponentConfig) GetDevCerts

func (c *ComponentConfig) GetDevCerts() (certPath, keyPath, caPath string)

GetDevCerts returns paths to this component's development certificate, key and CA, or panics if unavailable.

func (*ComponentConfig) PrometheusRegistry

func (c *ComponentConfig) PrometheusRegistry() *prometheus.Registry

PrometheusRegistry returns this component's singleton Prometheus registry, creating it as needed. This method is not goroutine-safe, and should only be called during the setup process of the Component.

func (*ComponentConfig) RegisterFlags

func (c *ComponentConfig) RegisterFlags(componentName string)

RegisterFlags registers the component configuration to be provided by flags. This must be called exactly once before then calling flags.Parse().

func (*ComponentConfig) StartPrometheus

func (c *ComponentConfig) StartPrometheus(ctx context.Context)

StartPrometheus starts a Prometheus metrics server in a goroutine. It will serve any metrics that have been registered with the registry returned by PrometheusRegistry.

Jump to

Keyboard shortcuts

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