Skip to content

Commit

Permalink
feat(kuma-cp) add postgres max idle connections configuration (#2020)
Browse files Browse the repository at this point in the history
Signed-off-by: nikita15p <nikita15p@gmail.com>
  • Loading branch information
nikita15p authored May 27, 2021
1 parent 3559575 commit f502241
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ store:
# Maximum number of open connections to the database
# `0` value means number of open connections is unlimited
maxOpenConnections: 0 # ENV: KUMA_STORE_POSTGRES_MAX_OPEN_CONNECTIONS
# Maximum number of connections in the idle connection pool
# <0 value means no idle connections and 0 means default max idle connections
maxIdleConnections: 0 # ENV: KUMA_STORE_POSTGRES_MAX_IDLE_CONNECTIONS
# TLS settings
tls:
# Mode of TLS connection. Available values (disable, verifyNone, verifyCa, verifyFull)
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ var _ = Describe("Config loader", func() {
Expect(cfg.Store.Postgres.DbName).To(Equal("kuma"))
Expect(cfg.Store.Postgres.ConnectionTimeout).To(Equal(10))
Expect(cfg.Store.Postgres.MaxOpenConnections).To(Equal(300))
Expect(cfg.Store.Postgres.MaxIdleConnections).To(Equal(300))
Expect(cfg.Store.Postgres.MinReconnectInterval).To(Equal(44 * time.Second))
Expect(cfg.Store.Postgres.MaxReconnectInterval).To(Equal(55 * time.Second))

Expand Down Expand Up @@ -251,6 +252,7 @@ store:
dbName: kuma
connectionTimeout: 10
maxOpenConnections: 300
maxIdleConnections: 300
minReconnectInterval: 44s
maxReconnectInterval: 55s
tls:
Expand Down Expand Up @@ -446,6 +448,7 @@ sdsServer:
"KUMA_STORE_POSTGRES_DB_NAME": "kuma",
"KUMA_STORE_POSTGRES_CONNECTION_TIMEOUT": "10",
"KUMA_STORE_POSTGRES_MAX_OPEN_CONNECTIONS": "300",
"KUMA_STORE_POSTGRES_MAX_IDLE_CONNECTIONS" "300",
"KUMA_STORE_POSTGRES_TLS_MODE": "verifyFull",
"KUMA_STORE_POSTGRES_TLS_CERT_PATH": "/path/to/cert",
"KUMA_STORE_POSTGRES_TLS_KEY_PATH": "/path/to/key",
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/plugins/resources/postgres/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type PostgresStoreConfig struct {
// Maximum number of open connections to the database
// `0` value means number of open connections is unlimited
MaxOpenConnections int `yaml:"maxOpenConnections" envconfig:"kuma_store_postgres_max_open_connections"`
// Maximum number of connections in the idle connection pool
// <0 value means no idle connections and 0 means default max idle connections
MaxIdleConnections int `yaml:"maxIdleConnections" envconfig:"kuma_store_postgres_max_idle_connections"`
// TLS settings
TLS TLSPostgresStoreConfig `yaml:"tls"`
// MinReconnectInterval controls the duration to wait before trying to
Expand Down
1 change: 1 addition & 0 deletions pkg/plugins/common/postgres/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func ConnectToDb(cfg config.PostgresStoreConfig) (*sql.DB, error) {
}

db.SetMaxOpenConns(cfg.MaxOpenConnections)
db.SetMaxIdleConns(cfg.MaxIdleConnections)

// check connection to DB, Open() does not check it.
if err := db.Ping(); err != nil {
Expand Down

0 comments on commit f502241

Please sign in to comment.