Skip to content

Commit

Permalink
kbaig2 - don't impose any default DB connection pooling
Browse files Browse the repository at this point in the history
rh-pre-commit.version: 2.2.0
rh-pre-commit.check-secrets: ENABLED
  • Loading branch information
gabemontero committed Apr 10, 2024
1 parent 77f432a commit aba9aa9
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"crypto/tls"
"database/sql"
"fmt"
"net/http"
"path"
Expand Down Expand Up @@ -67,9 +68,6 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
)

// The default number of connections to use
const defaultDatabaseConnections = 10

func main() {
serverConfig := config.Get()

Expand Down Expand Up @@ -122,19 +120,25 @@ func main() {
log.Fatalf("Failed to connect to database: %v", err)
}

sqlDB, err := db.DB()
var sqlDB *sql.DB

// Set DB connection limits
maxIdle := serverConfig.DB_MAX_IDLE_CONNECTIONS
maxOpen := serverConfig.DB_MAX_OPEN_CONNECTIONS
if maxOpen < 1 {
maxOpen = defaultDatabaseConnections
if maxOpen > 0 {
sqlDB, err = db.DB()
if err != nil {
log.Fatalf("Error getting database configuration for updating max open connections: %s", err.Error())
}
sqlDB.SetMaxOpenConns(maxOpen)
}
if maxIdle < 1 {
maxIdle = defaultDatabaseConnections
if maxIdle > 0 {
sqlDB, err = db.DB()
if err != nil {
log.Fatalf("Error getting database configuration for updating max open connections: %s", err.Error())
}
sqlDB.SetMaxIdleConns(maxIdle)
}
sqlDB.SetMaxIdleConns(maxIdle)
sqlDB.SetMaxOpenConns(maxOpen)

// Set grpc worker pool
grpcWorkers := serverConfig.GRPC_WORKER_POOL
Expand Down

0 comments on commit aba9aa9

Please sign in to comment.