Skip to content

Commit

Permalink
string method for mysql config and warning on low OpenConns
Browse files Browse the repository at this point in the history
  • Loading branch information
Stumble committed Apr 26, 2020
1 parent 614d8e8 commit bbcf514
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/clients/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
_ "github.com/go-sql-driver/mysql"
"github.com/kelseyhightower/envconfig"
"github.com/prometheus/client_golang/prometheus"
"github.com/rs/zerolog/log"
)

const (
HighQPSMaxOpenConns = 100
)

type Config struct {
Expand All @@ -21,6 +26,15 @@ type Config struct {
MaxLifetime time.Duration `default:"60s"`
}

func (c *Config) String() string {
if c == nil {
return "nil"
}
copy := *c
copy.Password = "*hidden*"
return fmt.Sprintf("%+v", copy)
}

func ConfigFromEnv() *Config {
config := &Config{}
envconfig.MustProcess("mysql", config)
Expand All @@ -47,6 +61,11 @@ func NewMysqlManagerWithMetrics(config *Config, gauge *prometheus.GaugeVec, exec
if config == nil {
config = ConfigFromEnv()
}
if config.MaxOpenConns < HighQPSMaxOpenConns {
log.Warn().Msgf(
"MysqlManager Config has MaxOpenConns = %d,"+
"which may be too low to handle high QPS.", config.MaxOpenConns)
}
manager, err := newManagerWithMetrics(config, gauge, execCounter, execHistogram)
if err != nil {
return nil, err
Expand Down

0 comments on commit bbcf514

Please sign in to comment.