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

Land PostgresClient that is backed by a ConnectionPool as SPI #430

Merged
merged 7 commits into from
Oct 30, 2023

Conversation

fabianfett
Copy link
Collaborator

No description provided.

@fabianfett fabianfett added the semver-patch No public API change. label Oct 28, 2023
@fabianfett fabianfett added this to the ConnectionPool milestone Oct 28, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2023

Codecov Report

❗ No coverage uploaded for pull request base (main@add68a0). Click here to learn what that means.
The diff coverage is 1.93%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #430   +/-   ##
=======================================
  Coverage        ?   58.83%           
=======================================
  Files           ?      124           
  Lines           ?     9792           
  Branches        ?        0           
=======================================
  Hits            ?     5761           
  Misses          ?     4031           
  Partials        ?        0           
Files Coverage Δ
...ources/ConnectionPoolModule/PoolStateMachine.swift 79.20% <100.00%> (ø)
...nection State Machine/ConnectionStateMachine.swift 62.45% <100.00%> (ø)
...es/PostgresNIO/Connection/PostgresConnection.swift 42.35% <0.00%> (ø)
Sources/PostgresNIO/Postgres+PSQLCompat.swift 0.00% <0.00%> (ø)
Sources/PostgresNIO/New/PSQLError.swift 79.22% <25.00%> (ø)
...nPoolModule/PoolStateMachine+ConnectionGroup.swift 87.11% <33.33%> (ø)
...urces/PostgresNIO/Pool/PostgresClientMetrics.swift 0.00% <0.00%> (ø)
Sources/PostgresNIO/Pool/PostgresClient.swift 0.00% <0.00%> (ø)
Sources/PostgresNIO/Pool/ConnectionFactory.swift 0.00% <0.00%> (ø)

Sources/PostgresNIO/Pool/PostgresClient.swift Outdated Show resolved Hide resolved
/// The server to connect to
///
/// - Default: localhost
public var host: String = "localhost"
Copy link
Member

Choose a reason for hiding this comment

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

No UDS support?

let pool: Pool

public init(configuration: Configuration, eventLoopGroup: EventLoopGroup, backgroundLogger: Logger) throws {
let connectionConfig = try PostgresConnection.Configuration(configuration)
Copy link
Member

Choose a reason for hiding this comment

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

Variant that uses the singleton ELG?

clientConfig.pool.keepAliveFrequency = .seconds(5)
clientConfig.pool.connectionIdleTimeout = .seconds(15)

clientConfig.server.host = env("POSTGRES_HOSTNAME") ?? "localhost"
Copy link
Member

Choose a reason for hiding this comment

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

Need to respect POSTGRES_PORT too.


init(keepAliveFrequency: Duration?, logger: Logger) {
self.keepAliveFrequency = keepAliveFrequency
self.query = "SELECT 1;"
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be configurable via the corresponding client config field?

@fabianfett fabianfett added the ConnectionPool Features and bugs that are related to the impl in ConnectionPoolModule label Oct 28, 2023
@fabianfett
Copy link
Collaborator Author

Crashing compiler toolchain in nightly. Ignore for now.

Sources/PostgresNIO/Pool/ConnectionFactory.swift Outdated Show resolved Hide resolved
Sources/PostgresNIO/Pool/PostgresClient.swift Outdated Show resolved Hide resolved

var connectionConfig: PostgresConnection.Configuration
switch config.endpointInfo {
case .bindUnixDomainSocket(let path):
Copy link
Member

Choose a reason for hiding this comment

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

Come to think of it, how about the "existing Channel" thing too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How do we want to use a single Channel for multiple connections. We will need to come up with a custom factory. That is a valuable goal. But not today.

}
}

public func withConnection<Result>(_ closure: (PostgresConnection) async throws -> Result) async throws -> Result {
Copy link
Member

Choose a reason for hiding this comment

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

Doc comments.

fabianfett and others added 2 commits October 30, 2023 10:46
Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
@fabianfett fabianfett merged commit 2905779 into vapor:main Oct 30, 2023
12 of 13 checks passed
@fabianfett fabianfett deleted the ff-PostgresClient branch October 30, 2023 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ConnectionPool Features and bugs that are related to the impl in ConnectionPoolModule semver-patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants