aboutsummaryrefslogtreecommitdiff
path: root/internal/sqlutil/trace.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/sqlutil/trace.go')
-rw-r--r--internal/sqlutil/trace.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/internal/sqlutil/trace.go b/internal/sqlutil/trace.go
index 3d5fa7dc..42ac4e58 100644
--- a/internal/sqlutil/trace.go
+++ b/internal/sqlutil/trace.go
@@ -21,9 +21,11 @@ import (
"fmt"
"io"
"os"
+ "regexp"
"strings"
"time"
+ "github.com/matrix-org/dendrite/common"
"github.com/ngrok/sqlmw"
"github.com/sirupsen/logrus"
)
@@ -76,12 +78,27 @@ func (in *traceInterceptor) RowsNext(c context.Context, rows driver.Rows, dest [
// Open opens a database specified by its database driver name and a driver-specific data source name,
// usually consisting of at least a database name and connection information. Includes tracing driver
// if DENDRITE_TRACE_SQL=1
-func Open(driverName, dsn string) (*sql.DB, error) {
+func Open(driverName, dsn string, dbProperties common.DbProperties) (*sql.DB, error) {
if tracingEnabled {
// install the wrapped driver
driverName += "-trace"
}
- return sql.Open(driverName, dsn)
+ db, err := sql.Open(driverName, dsn)
+ if err != nil {
+ return nil, err
+ }
+ if driverName != common.SQLiteDriverName() && dbProperties != nil {
+ logrus.WithFields(logrus.Fields{
+ "MaxOpenConns": dbProperties.MaxOpenConns(),
+ "MaxIdleConns": dbProperties.MaxIdleConns(),
+ "ConnMaxLifetime": dbProperties.ConnMaxLifetime(),
+ "dataSourceName": regexp.MustCompile(`://[^@]*@`).ReplaceAllLiteralString(dsn, "://"),
+ }).Debug("Setting DB connection limits")
+ db.SetMaxOpenConns(dbProperties.MaxOpenConns())
+ db.SetMaxIdleConns(dbProperties.MaxIdleConns())
+ db.SetConnMaxLifetime(dbProperties.ConnMaxLifetime())
+ }
+ return db, nil
}
func init() {