Skip to content

Commit e2881ec

Browse files
committed
postgres: support connect_timeout_ms
1 parent 81c88bf commit e2881ec

File tree

6 files changed

+43
-21
lines changed

6 files changed

+43
-21
lines changed

internal/versions/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"api_version": 148,
2+
"api_version": 149,
33
"minimum_api_version": 40,
44
"cache_version": 1
55
}

universe/db/postgres/exports.fn.cue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ package postgres
1212
nanos?: int
1313
}
1414
idleInTransactionSessionTimeoutMs?: int
15+
connectTimeoutMs?: int
1516

1617
#Definition: {
1718
packageName: "namespacelabs.dev/foundation/universe/db/postgres"

universe/db/postgres/provider.pb.go

Lines changed: 25 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

universe/db/postgres/provider.proto

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import "google/protobuf/duration.proto";
1212

1313
message DatabaseArgs {
1414
reserved 1, 2;
15-
string client = 7;
16-
string resource_ref = 3;
17-
int32 max_conns = 4; // Set if > 0.
18-
string max_conns_from_env = 6;
19-
google.protobuf.Duration max_conns_idle_time = 5;
20-
int32 idle_in_transaction_session_timeout_ms = 8;
15+
string client = 7;
16+
string resource_ref = 3;
17+
int32 max_conns = 4; // Set if > 0.
18+
string max_conns_from_env = 6;
19+
google.protobuf.Duration max_conns_idle_time = 5;
20+
int32 idle_in_transaction_session_timeout_ms = 8;
21+
int32 connect_timeout_ms = 9;
2122
}
2223

2324
message DatabaseReferenceArgs {

universe/db/postgres/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type ConfigOverrides struct {
3131
MaxConns int32
3232
MaxConnIdleTime time.Duration
3333
IdleInTransactionSessionTimeout time.Duration
34+
ConnectTimeout time.Duration
3435
}
3536

3637
func NewDatabaseFromConnectionUri(ctx context.Context, db *postgrespb.DatabaseInstance, connuri string, tp trace.TracerProvider, client string) (*DB, error) {
@@ -62,6 +63,10 @@ func NewDatabaseFromConnectionUriWithOverrides(ctx context.Context, db *postgres
6263
if overrides.IdleInTransactionSessionTimeout > 0 {
6364
config.ConnConfig.RuntimeParams["idle_in_transaction_session_timeout"] = fmt.Sprintf("%d", overrides.IdleInTransactionSessionTimeout.Milliseconds())
6465
}
66+
67+
if overrides.ConnectTimeout > 0 {
68+
config.ConnConfig.ConnectTimeout = overrides.ConnectTimeout
69+
}
6570
}
6671

6772
conn, err := pgxpool.NewWithConfig(ctx, config)

universe/db/postgres/wire.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func ProvideDatabase(ctx context.Context, db *DatabaseArgs, deps ExtensionDeps)
5656
overrides.IdleInTransactionSessionTimeout = time.Millisecond * time.Duration(db.GetIdleInTransactionSessionTimeoutMs())
5757
}
5858

59+
if db.GetConnectTimeoutMs() > 0 {
60+
overrides.ConnectTimeout = time.Millisecond * time.Duration(db.GetConnectTimeoutMs())
61+
}
62+
5963
return ConnectToResource(ctx, res, db.ResourceRef, tp, db.GetClient(), overrides)
6064
}
6165

0 commit comments

Comments
 (0)