mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
* Add apm for testing apm * Testing opentracing * testing * Testing * go fmt * Add config switch for tracing. * fixup * Update cmd/fleet/serve.go Co-authored-by: Tomas Touceda <chiiph@gmail.com> * Add support for both elasticapm and opentelemetry * Fix driver stuff and config options * Fixup * fixup * Add changes file * Add config for sql driver * fixup * Add doc to exported field * testing * fixup * fixup * Testing again * fixup * testing * Undo Co-authored-by: Tomas Touceda <chiiph@gmail.com>
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package mysql
|
|
|
|
import (
|
|
"github.com/fleetdm/fleet/v4/server/config"
|
|
"github.com/go-kit/kit/log"
|
|
"github.com/ngrok/sqlmw"
|
|
)
|
|
|
|
const defaultMaxAttempts int = 15
|
|
|
|
// DBOption is used to pass optional arguments to a database connection
|
|
type DBOption func(o *dbOptions) error
|
|
|
|
type dbOptions struct {
|
|
// maxAttempts configures the number of retries to connect to the DB
|
|
maxAttempts int
|
|
logger log.Logger
|
|
replicaConfig *config.MysqlConfig
|
|
interceptor sqlmw.Interceptor
|
|
tracingConfig *config.LoggingConfig
|
|
}
|
|
|
|
// Logger adds a logger to the datastore.
|
|
func Logger(l log.Logger) DBOption {
|
|
return func(o *dbOptions) error {
|
|
o.logger = l
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// WithInterceptor adds the sql interceptor to the datastore.
|
|
func WithInterceptor(i sqlmw.Interceptor) DBOption {
|
|
return func(o *dbOptions) error {
|
|
o.interceptor = i
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// Replica sets the configuration of the read replica for the datastore.
|
|
func Replica(conf *config.MysqlConfig) DBOption {
|
|
return func(o *dbOptions) error {
|
|
o.replicaConfig = conf
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// LimitAttempts sets a the number of attempts
|
|
// to try establishing a connection to the database backend
|
|
// the default value is 15 attempts
|
|
func LimitAttempts(attempts int) DBOption {
|
|
return func(o *dbOptions) error {
|
|
o.maxAttempts = attempts
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func TracingEnabled(lconfig *config.LoggingConfig) DBOption {
|
|
return func(o *dbOptions) error {
|
|
o.tracingConfig = lconfig
|
|
return nil
|
|
}
|
|
}
|