Skip to content

Commit 8127738

Browse files
committed
feat: log pool maximum size
It's important for observability to have an historic trace of the pool size. Currently we expose it on the metrics endpoint, but not all deployments use it. This logs the pool size after the successful connection log to make it more visible: <timestamp>: Connection Pool initialized with a maximum size of 4 connections
1 parent 291eed0 commit 8127738

File tree

5 files changed

+9
-3
lines changed

5 files changed

+9
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1212
- #3607, Log to stderr when the JWT secret is less than 32 characters long - @laurenceisla
1313
- #2858, Performance improvements when calling RPCs via GET using indexes in more cases - @wolfgangwalther
1414
- #3560, Log resolved host in "Listening on ..." messages - @develop7
15+
- #Pending, Log maximum pool size - @steve-chavez
1516

1617
### Fixed
1718

docs/references/observability.rst

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ For diagnostic information about the server itself, PostgREST logs to ``stderr``
3333
06/May/2024:08:16:11 -0500: Starting PostgREST 12.1...
3434
06/May/2024:08:16:11 -0500: Attempting to connect to the database...
3535
06/May/2024:08:16:11 -0500: Successfully connected to PostgreSQL 14.10 (Ubuntu 14.10-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
36+
06/May/2024:08:16:11 -0500: Connection Pool initialized with a maximum size of 10 connections
3637
06/May/2024:08:16:11 -0500: API server listening on port 3000
3738
06/May/2024:08:16:11 -0500: Listening for database notifications on the "pgrst" channel
3839
06/May/2024:08:16:11 -0500: Config reloaded

src/PostgREST/App.hs

-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ run appState = do
6767
let observer = AppState.getObserver appState
6868
conf@AppConfig{..} <- AppState.getConfig appState
6969

70-
observer $ AppStartObs prettyVersion
71-
7270
AppState.schemaCacheLoader appState -- Loads the initial SchemaCache
7371
Unix.installSignalHandlers (AppState.getMainThreadId appState) (AppState.schemaCacheLoader appState) (AppState.readInDbConfig False appState)
7472

src/PostgREST/AppState.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ init conf@AppConfig{configLogLevel, configDbPoolSize} = do
132132
metricsState <- Metrics.init configDbPoolSize
133133
let observer = liftA2 (>>) (Logger.observationLogger loggerState configLogLevel) (Metrics.observationMetrics metricsState)
134134

135+
observer $ AppStartObs prettyVersion
136+
135137
pool <- initPool conf observer
136138
(sock, adminSock) <- initSockets conf
137139
state' <- initWithPool (sock, adminSock) pool conf loggerState metricsState observer
@@ -206,7 +208,7 @@ initSockets AppConfig{..} = do
206208
pure (sock, adminSock)
207209

208210
initPool :: AppConfig -> ObservationHandler -> IO SQL.Pool
209-
initPool AppConfig{..} observer =
211+
initPool AppConfig{..} observer = do
210212
SQL.acquire $ SQL.settings
211213
[ SQL.size configDbPoolSize
212214
, SQL.acquisitionTimeout $ fromIntegral configDbPoolAcquisitionTimeout
@@ -391,6 +393,7 @@ retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThrea
391393
observer $ ExitUnsupportedPgVersion actualPgVersion minimumPgVersion
392394
killThread mainThreadId
393395
observer $ DBConnectedObs $ pgvFullName actualPgVersion
396+
observer $ PoolInit configDbPoolSize
394397
putPgVersion appState actualPgVersion
395398
return $ Just actualPgVersion
396399

src/PostgREST/Observation.hs

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ data Observation
4949
| QueryRoleSettingsErrorObs SQL.UsageError
5050
| QueryErrorCodeHighObs SQL.UsageError
5151
| QueryPgVersionError SQL.UsageError
52+
| PoolInit Int
5253
| PoolAcqTimeoutObs SQL.UsageError
5354
| HasqlPoolObs SQL.Observation
5455
| PoolRequest
@@ -118,6 +119,8 @@ observationMessage = \case
118119
"Failed reloading config: " <> err
119120
ConfigSucceededObs ->
120121
"Config reloaded"
122+
PoolInit poolSize ->
123+
"Connection Pool initialized with a maximum size of " <> show poolSize <> " connections"
121124
PoolAcqTimeoutObs usageErr ->
122125
jsonMessage usageErr
123126
HasqlPoolObs (SQL.ConnectionObservation uuid status) ->

0 commit comments

Comments
 (0)