Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: one (*sql.DB) pool for all jobsdb #5170

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Sidddddarth
Copy link
Member

@Sidddddarth Sidddddarth commented Oct 4, 2024

Description

One connection pool for all jobsdb.
In future, use the same pool across other areas(reporting, backend-config cache, drain-config etc. with appropriate increase in pool configurations)

Using given config(all of these are hot-reloadable):
maxOpenConnections: 40
maxIdleConnections: 5
maxIdleConnIdleTime: 15 Minutes
maxConnLifetime: 0

Linear Ticket

Resolves PIPE-1602

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Copy link

codecov bot commented Oct 4, 2024

Codecov Report

Attention: Patch coverage is 62.79070% with 32 lines in your changes missing coverage. Please review.

Project coverage is 72.90%. Comparing base (7818610) to head (dfa116a).

Files with missing lines Patch % Lines
utils/misc/dbutils.go 63.63% 13 Missing and 3 partials ⚠️
app/apphandlers/processorAppHandler.go 0.00% 10 Missing ⚠️
app/apphandlers/embeddedAppHandler.go 80.00% 1 Missing and 1 partial ⚠️
app/apphandlers/gatewayAppHandler.go 66.66% 1 Missing and 1 partial ⚠️
jobsdb/jobsdb.go 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5170      +/-   ##
==========================================
- Coverage   72.91%   72.90%   -0.02%     
==========================================
  Files         439      439              
  Lines       51138    51194      +56     
==========================================
+ Hits        37287    37321      +34     
- Misses      11390    11409      +19     
- Partials     2461     2464       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Sidddddarth Sidddddarth marked this pull request as ready for review October 7, 2024 03:49
connStr := GetConnectionString(conf, componentName)
db, err := sql.Open("postgres", connStr)
if err != nil {
return nil, fmt.Errorf("Error opening connection to database: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("Error opening connection to database: %w", err)
return nil, fmt.Errorf("opening connection to database: %w", err)

@@ -35,6 +40,74 @@ func GetConnectionString(c *config.Config, componentName string) string {
)
}

func GetDatabaseConnectionPool(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func GetDatabaseConnectionPool(
func NewDatabaseConnectionPool(

}
if err := stat.RegisterCollector(
collectors.NewDatabaseSQLStats(
"jobsdb",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"jobsdb",
componentName,

Comment on lines +65 to +67
/*
TODO: find out a reasonably good value for below pool configurations
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/*
TODO: find out a reasonably good value for below pool configurations
*/

TODO: find out a reasonably good value for below pool configurations
*/

maxConnsVar := conf.GetReloadableIntVar(40, 1, "JobsDB.maxOpenConnections")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid using JobsDB, as it is an overloaded term.

Suggested change
maxConnsVar := conf.GetReloadableIntVar(40, 1, "JobsDB.maxOpenConnections")
maxConnsVar := conf.GetReloadableIntVar(40, 1, "db.pool.maxOpenConnections")

Or even

Suggested change
maxConnsVar := conf.GetReloadableIntVar(40, 1, "JobsDB.maxOpenConnections")
maxConnsVar := conf.GetReloadableIntVar(40, 1, "db.pool.maxOpenConnections", "db."+componentName+".pool.maxOpenConnections")

Comment on lines +146 to +147
// Not deferring close here
// defer dbPool.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the reason for not closing here? Shall we inject dbPool to embeddedAppHandler. So we always use on connection pool

@@ -139,13 +139,21 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, options *app.Options)
FeaturesRetryMaxAttempts: 10,
})

dbPool, err := misc.GetDatabaseConnectionPool(ctx, config, statsFactory, "jobsdb")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dbPool, err := misc.GetDatabaseConnectionPool(ctx, config, statsFactory, "jobsdb")
dbPool, err := misc.GetDatabaseConnectionPool(ctx, config, statsFactory, "embedded-app")

I would avoid using jobsdb for anything else other than jobsdb component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants