forked from vapor/postgres-nio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPostgresClientMetrics.swift
85 lines (66 loc) · 2.58 KB
/
PostgresClientMetrics.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import _ConnectionPoolModule
import Logging
final class PostgresClientMetrics: ConnectionPoolObservabilityDelegate {
typealias ConnectionID = PostgresConnection.ID
let logger: Logger
init(logger: Logger) {
self.logger = logger
}
func startedConnecting(id: ConnectionID) {
self.logger.debug("Creating new connection", metadata: [
.connectionID: "\(id)",
])
}
/// A connection attempt failed with the given error. After some period of
/// time ``startedConnecting(id:)`` may be called again.
func connectFailed(id: ConnectionID, error: Error) {
self.logger.debug("Connection creation failed", metadata: [
.connectionID: "\(id)",
.error: "\(String(reflecting: error))"
])
}
func connectSucceeded(id: ConnectionID) {
self.logger.debug("Connection established", metadata: [
.connectionID: "\(id)"
])
}
/// The utlization of the connection changed; a stream may have been used, returned or the
/// maximum number of concurrent streams available on the connection changed.
func connectionLeased(id: ConnectionID) {
self.logger.debug("Connection leased", metadata: [
.connectionID: "\(id)"
])
}
func connectionReleased(id: ConnectionID) {
self.logger.debug("Connection released", metadata: [
.connectionID: "\(id)"
])
}
func keepAliveTriggered(id: ConnectionID) {
self.logger.debug("run ping pong", metadata: [
.connectionID: "\(id)",
])
}
func keepAliveSucceeded(id: ConnectionID) {}
func keepAliveFailed(id: PostgresConnection.ID, error: Error) {}
/// The remote peer is quiescing the connection: no new streams will be created on it. The
/// connection will eventually be closed and removed from the pool.
func connectionClosing(id: ConnectionID) {
self.logger.debug("Close connection", metadata: [
.connectionID: "\(id)"
])
}
/// The connection was closed. The connection may be established again in the future (notified
/// via ``startedConnecting(id:)``).
func connectionClosed(id: ConnectionID, error: Error?) {
self.logger.debug("Connection closed", metadata: [
.connectionID: "\(id)"
])
}
func requestQueueDepthChanged(_ newDepth: Int) {
}
func connectSucceeded(id: PostgresConnection.ID, streamCapacity: UInt16) {
}
func connectionUtilizationChanged(id: PostgresConnection.ID, streamsUsed: UInt16, streamCapacity: UInt16) {
}
}