Skip to content

Commit

Permalink
Adding max-db-conns and max-idle-conns through environment variables (#…
Browse files Browse the repository at this point in the history
…645)

* Adding max-db-conns and max-idle-conns through environment variables

* Improving default values
  • Loading branch information
jespino authored Jun 29, 2021
1 parent f3be1d2 commit b59b714
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/services/store/mattermostauthlayer/mattermostauthlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/json"
"errors"
"log"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -38,6 +40,26 @@ func New(dbType, connectionString string, store store.Store) (*MattermostAuthLay

return nil, err
}
maxDBIdleConns, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_IDLE_CONNS"))
if err != nil {
maxDBIdleConns = 20
}
maxDBOpenConns, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_OPEN_CONNS"))
if err != nil {
maxDBOpenConns = 300
}
maxDBIdleTime, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_IDLE_TIME"))
if err != nil {
maxDBIdleTime = 300
}
maxDBLifetime, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_LIFETIME"))
if err != nil {
maxDBLifetime = 3600
}
db.SetMaxIdleConns(maxDBIdleConns)
db.SetMaxOpenConns(maxDBOpenConns)
db.SetConnMaxIdleTime(time.Duration(maxDBIdleTime) * time.Second)
db.SetConnMaxLifetime(time.Duration(maxDBLifetime) * time.Second)

err = db.Ping()
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions server/services/store/sqlstore/sqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package sqlstore

import (
"database/sql"
"os"
"strconv"
"time"

sq "github.com/Masterminds/squirrel"
"github.com/mattermost/focalboard/server/services/mlog"
Expand Down Expand Up @@ -33,6 +36,26 @@ func New(dbType, connectionString string, tablePrefix string, logger *mlog.Logge

return nil, err
}
maxDBIdleConns, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_IDLE_CONNS"))
if err != nil {
maxDBIdleConns = 20
}
maxDBOpenConns, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_OPEN_CONNS"))
if err != nil {
maxDBOpenConns = 300
}
maxDBIdleTime, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_IDLE_TIME"))
if err != nil {
maxDBIdleTime = 300
}
maxDBLifetime, err := strconv.Atoi(os.Getenv("FOCALBOARD_DB_MAX_LIFETIME"))
if err != nil {
maxDBLifetime = 3600
}
db.SetMaxIdleConns(maxDBIdleConns)
db.SetMaxOpenConns(maxDBOpenConns)
db.SetConnMaxIdleTime(time.Duration(maxDBIdleTime) * time.Second)
db.SetConnMaxLifetime(time.Duration(maxDBLifetime) * time.Second)

err = db.Ping()
if err != nil {
Expand Down

0 comments on commit b59b714

Please sign in to comment.