Skip to content

Commit

Permalink
chore: Add ability to configure maximum DB connection lifetime (#3032)
Browse files Browse the repository at this point in the history
  • Loading branch information
markterm committed May 15, 2020
1 parent 38a995b commit b7ff9f0
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ func (c PersistConfig) GetClusterName() string {
}

type ConnectionPool struct {
MaxIdleConns int `json:"maxIdleConns,omitempty"`
MaxOpenConns int `json:"maxOpenConns,omitempty"`
MaxIdleConns int `json:"maxIdleConns,omitempty"`
MaxOpenConns int `json:"maxOpenConns,omitempty"`
ConnMaxLifetime TTL `json:"connMaxLifetime,omitempty"`
}
type PostgreSQLConfig struct {
Host string `json:"host"`
Expand Down
1 change: 1 addition & 0 deletions docs/workflow-controller-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ data:
connectionPool:
maxIdleConns: 100
maxOpenConns: 0
connMaxLifetime: 0s # 0 means connections don't have a max lifetime
# if true node status is only saved to the persistence DB to avoid the 1MB limit in etcd
nodeStatusOffLoad: false
# save completed workloads to the workflow archive
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ data:
connectionPool:
maxIdleConns: 100
maxOpenConns: 0
connMaxLifetime: 0s
nodeStatusOffLoad: true
archive: true
archiveTTL: 7d
Expand Down
1 change: 1 addition & 0 deletions manifests/quick-start-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ data:
connectionPool:
maxIdleConns: 100
maxOpenConns: 0
connMaxLifetime: 0s
nodeStatusOffLoad: true
archive: true
archiveTTL: 7d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ data:
connectionPool:
maxIdleConns: 100
maxOpenConns: 0
connMaxLifetime: 0s
nodeStatusOffLoad: true
archive: true
archiveTTL: 7d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ data:
connectionPool:
maxIdleConns: 100
maxOpenConns: 0
connMaxLifetime: 0s
nodeStatusOffLoad: true
archive: true
archiveTTL: 7d
Expand Down
3 changes: 3 additions & 0 deletions persist/sqldb/sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sqldb

import (
"fmt"
"time"

log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -70,6 +71,7 @@ func CreatePostGresDBSession(kubectlConfig kubernetes.Interface, namespace strin
if persistPool != nil {
session.SetMaxOpenConns(persistPool.MaxOpenConns)
session.SetMaxIdleConns(persistPool.MaxIdleConns)
session.SetConnMaxLifetime(time.Duration(persistPool.ConnMaxLifetime))
}
return session, cfg.TableName, nil
}
Expand Down Expand Up @@ -103,6 +105,7 @@ func CreateMySQLDBSession(kubectlConfig kubernetes.Interface, namespace string,
if persistPool != nil {
session.SetMaxOpenConns(persistPool.MaxOpenConns)
session.SetMaxIdleConns(persistPool.MaxIdleConns)
session.SetConnMaxLifetime(time.Duration(persistPool.ConnMaxLifetime))
}
// this is needed to make MySQL run in a Golang-compatible UTF-8 character set.
_, err = session.Exec("SET NAMES 'utf8mb4'")
Expand Down

0 comments on commit b7ff9f0

Please sign in to comment.