Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWrappedMySQL ¶ added in v0.16.0
func NewWrappedMySQL( ctx context.Context, config MySQLConfig, middleware middleware.Middleware, registry prometheus.Registerer, mustRegister bool, collectionFrequency time.Duration, ) (*sql.DB, func() error, error)
NewWrappedMySQLDrive builds a MySQL driver wrapped with the provided middleware and starts a periodic task that collects database connection metrics in the provided prometheus registerer. If the CACertPath is set in the passed in config, the database connection will be over SSL. The returned function should be called close the database connection instead of calling Close() directly as it stops the periodic metrics task.
Types ¶
type DBConnector ¶
type DBConnector interface {
Connect() error
}
DBConnector is the interface which various Database-specific configuration objects must satisfy to return a usable database connection to the caller
type MySQLConfig ¶ added in v0.18.3
type MySQLConfig struct {
mysql.Config
// Path to the server CA certificate for SSL connections
CACertPath string
}
MySQLConfig adds a path for a CA cert to mysql.Config. When CACertPath is set, NewWrappedMySQL will verify the database identity with the provided CA cert.
func (*MySQLConfig) RegisterFlags ¶ added in v0.18.3
func (c *MySQLConfig) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers MySQL flags with pflags
type PostgresConfig ¶
type PostgresConfig struct {
ApplicationName string // The name of the application connecting. Useful for attributing db load.
Host string // The host where the database is located
Port uint16 // The port on which the database is listening
Username string // The username for the database
Password string // The password for the database
Database string // The name of the database
ConnectTimeout time.Duration // Amount of time to wait before timing out
SSL bool // If true, connect to the database with SSL
SSLCert string // Path to the SSL Certificate, if any
SSLKey string // Path to the SSL Key, if any
SSLRootCert string // Path to the SSL Root Certificate, if any
MetricsFrequency time.Duration // How often to export core database metrics
Middleware middleware.Middleware // List of SQL Middlewares to apply, if any
}
PostgresConfig defines Postgres SQL connection information
func NewDefaultPostgresConfig ¶
func NewDefaultPostgresConfig(appName, dbName string) PostgresConfig
NewDefaultPostgresConfig creates and return a default postgres configuration.
func (PostgresConfig) Connect ¶
func (pc PostgresConfig) Connect(ctx context.Context, registry prometheus.Registerer, mustRegister bool) (*sqlx.DB, func(), error)
Connect uses the given Config struct to establish a connection with the database. Optionally, a prometheus registry may be provided. If no registry is provided, the global registry will be used. Additionally, users may specify that failed metrics registration should result in a panic via the `mustRegister` flag.
The database connection, deferable close function, and error are returned
func (*PostgresConfig) RegisterFlags ¶
func (pc *PostgresConfig) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers PostgreSQL flags with pflags