Skip to content

Commit

Permalink
Add server_lifetime and server_idle_timeout pgbouncer variables (#746)
Browse files Browse the repository at this point in the history
Issue: CLD-4380
  • Loading branch information
stafot authored Oct 21, 2022
1 parent ddacd42 commit f3a9804
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
11 changes: 10 additions & 1 deletion cmd/cloud/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ func init() {
serverCmd.PersistentFlags().String("utilities-git-url", "", "The private git domain to use for utilities. For example https://gitlab.com")
serverCmd.PersistentFlags().Int("max-proxy-db-connections-per-pool", 20, "The maximum number of proxy database connections per pool (logical database).")
serverCmd.PersistentFlags().Int("default-proxy-db-pool-size", 5, "The db proxy default pool size per user.")
serverCmd.PersistentFlags().Int("reserve-proxy-db-pool-size", 20, "The db proxy reserve pool size per logical database.")
serverCmd.PersistentFlags().Int("reserve-proxy-db-pool-size", 10, "The db proxy reserve pool size per logical database.")
serverCmd.PersistentFlags().Int("min-proxy-db-pool-size", 1, "The db proxy min pool size.")
serverCmd.PersistentFlags().Int("max-client-connections", 20000, "The db proxy max client connections.")
serverCmd.PersistentFlags().Int("server-idle-timeout", 30, "The server idle timeout.")
serverCmd.PersistentFlags().Int("server-lifetime", 300, "The server lifetime.")

serverCmd.PersistentFlags().String("kubecost-token", "", "Set a kubecost token")
serverCmd.PersistentFlags().String("ndots-value", "5", "The default ndots value for installations.")
serverCmd.PersistentFlags().Bool("disable-db-init-check", false, "Whether to disable init container with database check.")
Expand Down Expand Up @@ -170,6 +173,12 @@ var serverCmd = &cobra.Command{
maxClientConnections, _ := command.Flags().GetInt("max-client-connections")
model.SetMaxClientConnections(maxClientConnections)

serverIdleTimeout, _ := command.Flags().GetInt("server-idle-timeout")
model.SetServerIdleTimeout(serverIdleTimeout)

serverLifetime, _ := command.Flags().GetInt("server-lifetime")
model.SetServerLifetime(serverLifetime)

gitlabOAuthToken, _ := command.Flags().GetString("gitlab-oauth")
if len(gitlabOAuthToken) == 0 {
gitlabOAuthToken = os.Getenv(model.GitlabOAuthTokenKey)
Expand Down
4 changes: 3 additions & 1 deletion internal/provisioner/pgbouncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ reserve_pool_size = %d
reserve_pool_timeout = 1
max_client_conn = %d
max_db_connections = %d
server_idle_timeout = %d
server_lifetime = %d
server_reset_query_always = 1
[databases]
Expand Down Expand Up @@ -246,7 +248,7 @@ func generatePGBouncerIni(vpcID string, store model.ClusterUtilityDatabaseStoreI
}

func generatePGBouncerBaseIni() string {
return fmt.Sprintf(baseIni, model.GetMinPoolSize(), model.GetDefaultPoolSize(), model.GetReservePoolSize(), model.GetMaxClientConnections(), model.GetMaxDatabaseConnectionsPerPool())
return fmt.Sprintf(baseIni, model.GetMinPoolSize(), model.GetDefaultPoolSize(), model.GetReservePoolSize(), model.GetMaxClientConnections(), model.GetMaxDatabaseConnectionsPerPool(), model.GetServerIdleTimeout(), model.GetServerLifetime())
}

func generatePGBouncerUserlist(vpcID string, awsClient aws.AWS) (string, error) {
Expand Down
28 changes: 27 additions & 1 deletion model/multitenant_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,20 @@ var maxDatabaseConnectionsPerPool int = 20
var defaultPoolSize int = 5

// reservePoolSize is the default pool size per user
var reservePoolSize int = 20
var reservePoolSize int = 10

// minPoolSize is the minimum pool size
var minPoolSize int = 3

// maxClientConnections is the maximum client connections
var maxClientConnections int = 20000

// serverIdleTimeout is the server idle timeout
var serverIdleTimeout int = 30

// serverLifetime is the server lifetime
var serverLifetime int = 300

// SetMaxDatabaseConnectionsPerPool is used to define how many database
// connections are created per logical database pool with proxy databases.
func SetMaxDatabaseConnectionsPerPool(val int) error {
Expand Down Expand Up @@ -85,6 +91,16 @@ func SetMaxClientConnections(val int) {
maxClientConnections = val
}

// SetServerIdleTimeout is used to define the server idle timeout of pgbouncer
func SetServerIdleTimeout(val int) {
serverIdleTimeout = val
}

// SetServerLifetime is used to define the server lifetime of pgbouncer
func SetServerLifetime(val int) {
serverLifetime = val
}

// GetMaxDatabaseConnectionsPerPool returns the value of
// maxDatabaseConnectionsPerPool.
func GetMaxDatabaseConnectionsPerPool() int {
Expand All @@ -111,6 +127,16 @@ func GetMaxClientConnections() int {
return maxClientConnections
}

// GetServerIdleTimeout returns the value of serverIdleTimeout.
func GetServerIdleTimeout() int {
return serverIdleTimeout
}

// GetServerLifetime returns the value of serverLifetime.
func GetServerLifetime() int {
return serverLifetime
}

// MultitenantDatabase represents database infrastructure that contains multiple
// installation databases.
type MultitenantDatabase struct {
Expand Down

0 comments on commit f3a9804

Please sign in to comment.