Documentation ¶
Index ¶
- Constants
- func WithDriverName(n string) func(*wrappedSQLOptions)
- func WithMetricsCollectionFrequency(f time.Duration) func(*wrappedSQLOptions)
- func WithMetricsRegisterer(r prometheus.Registerer) func(*wrappedSQLOptions)
- func WithMiddleware(m middleware.Middleware) func(*wrappedSQLOptions)
- func WithMustRegister(r bool) func(*wrappedSQLOptions)
- type DBConnector
- type MySQLConfig
- type PostgresConfig
- type WrappedSQLOption
Constants ¶
const ( // If no override option is provided, this is the name of the wrapped MySQL driver that will be // registered when calling MySQLConfig.Connect. DefaultWrappedMySQLDriverName = "wrappedMySQL" )
const ( // If no override option is provided, this is the name of the wrapped Postgres driver that will be // registered when calling PostgresConfig.Connect. DefaultWrappedPgDriverName = "instrumentedPostgres" )
Variables ¶
This section is empty.
Functions ¶
func WithDriverName ¶ added in v0.20.0
func WithDriverName(n string) func(*wrappedSQLOptions)
WithDriverName overrides the default wrapped driver name so that multiple wrapped drivers can be registered at once.
func WithMetricsCollectionFrequency ¶ added in v0.20.0
WithMetricsCollectionFrequency sets the frequency at which database metrics will be collected and made available in the Prometheus registry. Defaults to 5 seconds.
func WithMetricsRegisterer ¶ added in v0.20.0
func WithMetricsRegisterer(r prometheus.Registerer) func(*wrappedSQLOptions)
WithMiddleware sets the Prometheus registerer to the wrapped SQL options. Defaults to the prometheus default registerer.
func WithMiddleware ¶ added in v0.20.0
func WithMiddleware(m middleware.Middleware) func(*wrappedSQLOptions)
WithMiddleware adds the provided middleware to the wrapped SQL options. Defaults to log and tracing middleware.
func WithMustRegister ¶ added in v0.20.0
func WithMustRegister(r bool) func(*wrappedSQLOptions)
WithMustRegister sets whether or not metrics must register in Prometheus. Defaults to true.
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) Connect ¶ added in v0.20.0
func (c MySQLConfig) Connect(ctx context.Context, options ...WrappedSQLOption) (*sqlx.DB, func() error, error)
Connect uses the given Config struct to establish a connection with the database. See the documentation for WrappedSQLOption functions to configure how the driver gets wrapped. Note that calling Connect multiple times is not allowed with the same driver name option.
If no error occurs, the database connection, and a close function are returned
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 }
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, options ...WrappedSQLOption) (*sqlx.DB, func() error, error)
Connect uses the given Config struct to establish a connection with the database. See the documentation for WrappedSQLOption functions to configure how the driver gets wrapped. Note that calling Connect multiple times is not allowed with the same driver name option.
If no error occurs, the database connection, and a close function are returned
func (*PostgresConfig) RegisterFlags ¶
func (pc *PostgresConfig) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers PostgreSQL flags with pflags
type WrappedSQLOption ¶ added in v0.20.0
type WrappedSQLOption func(*wrappedSQLOptions)
WrappedSQLOption is a function that adds configuration for wrapping both PostgreSQL and MySQL drivers.